use of com.fanxb.bookmark.common.entity.po.User in project bookmark by FleyX.
the class UserServiceImpl method login.
/**
* Description: 登录
*
* @param body 登录表单
* @return string
* @author fanxb
* @date 2019/7/6 16:37
*/
public String login(LoginBody body) {
String key = RedisConstant.getUserFailCountKey(body.getStr());
String count = redisTemplate.opsForValue().get(key);
if (count != null && Integer.parseInt(count) >= LOGIN_COUNT) {
redisTemplate.expire(key, 30, TimeUnit.MINUTES);
throw new FormDataException("您已连续输错密码5次,请30分钟后再试,或联系管理员处理");
}
User userInfo = userDao.selectByUsernameOrEmail(body.getStr(), body.getStr());
if (userInfo == null || StrUtil.isEmpty(userInfo.getPassword()) || !HashUtil.sha1(HashUtil.md5(body.getPassword())).equals(userInfo.getPassword())) {
redisTemplate.opsForValue().set(key, count == null ? "1" : String.valueOf(Integer.parseInt(count) + 1), 30, TimeUnit.MINUTES);
throw new FormDataException("账号密码错误");
}
redisTemplate.delete(key);
userDao.updateLastLoginTime(System.currentTimeMillis(), userInfo.getUserId());
return JwtUtil.encode(Collections.singletonMap("userId", String.valueOf(userInfo.getUserId())), CommonConstant.jwtSecret, body.isRememberMe() ? LONG_EXPIRE_TIME : SHORT_EXPIRE_TIME);
}
Aggregations