本文整理汇总了Java中com.jfinal.aop.ClearInterceptor类的典型用法代码示例。如果您正苦于以下问题:Java ClearInterceptor类的具体用法?Java ClearInterceptor怎么用?Java ClearInterceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ClearInterceptor类属于com.jfinal.aop包,在下文中一共展示了ClearInterceptor类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkUser
import com.jfinal.aop.ClearInterceptor; //导入依赖的package包/类
/**
* 检查用户账号是否被注册*
*/
@ClearInterceptor
public void checkUser() {
String loginName = getPara("loginName");
if (StringUtils.isEmpty(loginName)) {
renderArgumentError("loginName can not be null");
return;
}
//检查手机号码是否被注册
boolean exists = Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null;
renderJson(new BaseResponse(exists ? Code.SUCCESS:Code.FAIL, exists ? "registered" : "unregistered"));
}
示例2: login
import com.jfinal.aop.ClearInterceptor; //导入依赖的package包/类
/**
* 登录接口
*/
@ClearInterceptor()
public void login() {
String loginName = getPara("loginName");
String password = getPara("password");
//校验参数, 确保不能为空
if (!notNull(Require.me()
.put(loginName, "loginName can not be null")
.put(password, "password can not be null")
)) {
return;
}
String sql = "SELECT * FROM t_user WHERE loginName=? AND password=?";
User nowUser = User.user.findFirst(sql, loginName, StringUtils.encodePassword(password, "md5"));
LoginResponse response = new LoginResponse();
if (nowUser == null) {
response.setCode(Code.FAIL).setMessage("userName or password is error");
renderJson(response);
return;
}
Map<String, Object> userInfo = new HashMap<String, Object>(nowUser.getAttrs());
userInfo.remove(PASSWORD);
response.setInfo(userInfo);
response.setMessage("login success");
response.setToken(TokenManager.getMe().generateToken(nowUser));
response.setConstant(Constant.me());
renderJson(response);
}
示例3: sendCode
import com.jfinal.aop.ClearInterceptor; //导入依赖的package包/类
/**
* 1. 检查是否被注册*
* 2. 发送短信验证码*
*/
@ClearInterceptor
public void sendCode() {
String loginName = getPara("loginName");
if (StringUtils.isEmpty(loginName)) {
renderArgumentError("loginName can not be null");
return;
}
//检查手机号码有效性
if (!SMSUtils.isMobileNo(loginName)) {
renderArgumentError("mobile number is invalid");
return;
}
//检查手机号码是否被注册
if (Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null) {
renderJson(new BaseResponse(Code.ACCOUNT_EXISTS,"mobile already registered"));
return;
}
String smsCode = SMSUtils.randomSMSCode(4);
//发送短信验证码
if (!SMSUtils.sendCode(loginName, smsCode)) {
renderFailed("sms send failed");
return;
}
//保存验证码数据
RegisterCode registerCode = new RegisterCode()
.set(RegisterCode.MOBILE, loginName)
.set(RegisterCode.CODE, smsCode);
//保存数据
if (Db.findFirst("SELECT * FROM t_register_code WHERE mobile=?", loginName) == null) {
registerCode.save();
} else {
registerCode.update();
}
renderJson(new BaseResponse("sms sended"));
}
示例4: register
import com.jfinal.aop.ClearInterceptor; //导入依赖的package包/类
/**
* 用户注册
*/
@ClearInterceptor()
public void register(){
//必填信息
String loginName = getPara("loginName");//登录帐号
int code = getParaToInt("code", 0);//手机验证码
int sex = getParaToInt("sex", 0);//性别
String password = getPara("password");//密码
String nickName = getPara("nickName");//昵称
//头像信息,为空则使用默认头像地址
String avatar = getPara("avatar", AppProperty.me().defaultUserAvatar());
//校验必填项参数
if(!notNull(Require.me()
.put(loginName, "loginName can not be null")
.put(code, "code can not be null")//根据业务需求决定是否使用此字段
.put(password, "password can not be null")
.put(nickName, "nickName can not be null"))){
return;
}
//检查账户是否已被注册
if (Db.findFirst("SELECT * FROM t_user WHERE loginName=?", loginName) != null) {
renderJson(new BaseResponse(Code.ACCOUNT_EXISTS, "mobile already registered"));
return;
}
//检查验证码是否有效, 如果业务不需要,则无需保存此段代码
if (Db.findFirst("SELECT * FROM t_register_code WHERE mobile=? AND code = ?", loginName, code) == null) {
renderJson(new BaseResponse(Code.CODE_ERROR,"code is invalid"));
return;
}
//保存用户数据
String userId = RandomUtils.randomCustomUUID();
new User()
.set("userId", userId)
.set(User.LOGIN_NAME, loginName)
.set(User.PASSWORD, StringUtils.encodePassword(password, "md5"))
.set(User.NICK_NAME, nickName)
.set(User.CREATION_DATE, DateUtils.getNowTimeStamp())
.set(User.SEX, sex)
.set(User.AVATAR, avatar)
.save();
//删除验证码记录
Db.update("DELETE FROM t_register_code WHERE mobile=? AND code = ?", loginName, code);
//返回数据
renderJson(new BaseResponse("success"));
}