use of cn.exrick.manager.annotation.SystemControllerLog in project xmall by Exrick.
the class UserController method login.
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
@ApiOperation(value = "用户登录")
@SystemControllerLog(description = "登录系统")
public Result<Object> login(String username, String password, String challenge, String validate, String seccode, HttpServletRequest request) {
// 极验验证
GeetestLib gtSdk = new GeetestLib(GeetestLib.id, GeetestLib.key, GeetestLib.newfailback);
// 从session中获取gt-server状态
int gt_server_status_code = (Integer) request.getSession().getAttribute(gtSdk.gtServerStatusSessionKey);
// 自定义参数,可选择添加
HashMap<String, String> param = new HashMap<String, String>();
int gtResult = 0;
if (gt_server_status_code == 1) {
// gt-server正常,向gt-server进行二次验证
gtResult = gtSdk.enhencedValidateRequest(challenge, validate, seccode, param);
System.out.println(gtResult);
} else {
// gt-server非正常情况下,进行failback模式验证
System.out.println("failback:use your own server captcha validate");
gtResult = gtSdk.failbackValidateRequest(challenge, validate, seccode);
System.out.println(gtResult);
}
if (gtResult == 1) {
// 验证成功
Subject subject = SecurityUtils.getSubject();
// MD5加密
String md5Pass = DigestUtils.md5DigestAsHex(password.getBytes());
UsernamePasswordToken token = new UsernamePasswordToken(username, md5Pass);
try {
subject.login(token);
return new ResultUtil<Object>().setData(null);
} catch (Exception e) {
return new ResultUtil<Object>().setErrorMsg("用户名或密码错误");
}
} else {
// 验证失败
return new ResultUtil<Object>().setErrorMsg("验证失败");
}
}
Aggregations