package com.jfinal.club.my.safe;

import com.jfinal.club.common.model.Users;
import com.jfinal.core.Controller;
import com.jfinal.kit.Ret;
import com.jfinal.validate.Validator;

/**
 * @ProjectName: jfinal-club
 * @Package: com.jfinal.club.my.safe
 * @ClassName: UserUpdateValidator
 * @Author: Jzdsh
 * @Description:
 * @Date: 2020/3/30 18:12
 * @Version: 1.0
 */
public class UserUpdateValidator extends Validator {
    @Override
    protected void validate(Controller c) {
        setShortCircuit(true);
        setRet(Ret.fail());
        c.getFile("users.tximg","/temp");
        validateRequired("users.nickname","msg","请输入个昵称吧");

        String nickName = c.get("users.nickname");
        String name = c.get("users.name");
        if(nickName.length() > 50){
            addError("msg","昵称不能超过50个字符！");
        }
        if(name != null && name.length() > 10){
            addError("msg","真实姓名不能超过10个字符！");
        }
    }

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