package com.jfinal.club._admin.login;

import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;

/**
 * @descriptions: 登录验证器
 * @author: lc
 * @date: 2020-05-09 17:51:24
 * @Version: 1.0
 **/
public class LoginValidator extends Validator {
    @Override
    protected void validate(Controller c) {
        //设置短路验证
        setShortCircuit(true);
        setRet(Ret.fail());

        validateRequiredString("username","msg","请填写用户名!");
        validateRequiredString("password","msg","请输入密码!");

        String username = c.get("username");
        String password = c.get("password");
        if(username != null && username.length() > 30){
            addError("msg","用户名太长啦!");
        }
        if(password !=null && password.length() > 40){
            addError("msg","密码太长啦!");
        }


    }

    @Override
    protected void handleError(Controller c) {
        c.renderJson(getRet( ));
    }
}
