| | |
| | | package com.lf.server.service.sys; |
| | | |
| | | import com.lf.server.entity.all.RedisCacheKey; |
| | | import com.lf.server.entity.all.SettingData; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.Md5Helper; |
| | | import com.lf.server.helper.RsaHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.sys.UserMapper; |
| | | import com.lf.server.service.all.RedisService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.cache.RedisCache; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.List; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 用户表 |
| | |
| | | public class UserService implements UserMapper { |
| | | @Autowired |
| | | UserMapper userMapper; |
| | | |
| | | @Autowired |
| | | RedisService redisService; |
| | | |
| | | @Override |
| | | public Integer selectCount(String uname) { |
| | |
| | | return userMapper.selectByPageForRole(uname, roleid, depid, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updateUsersPwd(Integer updateUser, String pwd, List<Integer> ids) { |
| | | return userMapper.updateUsersPwd(updateUser, pwd, ids); |
| | | } |
| | | |
| | | /** |
| | | * 验证新用户密码 |
| | | */ |
| | | public String ValidateNewPwd(UserEntity entity) { |
| | | public String validateNewPwd(UserEntity entity) { |
| | | if (entity == null) { |
| | | return "没有找到用户"; |
| | | } |
| | |
| | | /** |
| | | * 验证老用户密码 |
| | | */ |
| | | public String ValidateOldPwd(UserEntity entity) { |
| | | public String validateOldPwd(UserEntity entity) { |
| | | if (entity == null) { |
| | | return "没有找到用户"; |
| | | } |
| | |
| | | return "没有找到用户"; |
| | | } |
| | | if (!Md5Helper.validatePassword(pwd, ue.getPwd())) { |
| | | // |
| | | return "旧密码输入错误"; |
| | | } |
| | | if (!StringHelper.checkPwdValid(salt)) { |
| | |
| | | return "密码解密失败"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 验证管理员密码 |
| | | */ |
| | | public String validateAdminPwd(UserEntity ue, String adminPwd) { |
| | | if (ue == null) { |
| | | return "没有登录或超时"; |
| | | } |
| | | if (StringHelper.isEmpty(adminPwd)) { |
| | | return "管理员密码不能为空"; |
| | | } |
| | | |
| | | try { |
| | | String pwd = RsaHelper.decrypt(adminPwd); |
| | | if (!Md5Helper.validatePassword(pwd, ue.getPwd())) { |
| | | return "管理员密码不正确"; |
| | | } |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | | return "密码解密失败"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 验证新密码 |
| | | */ |
| | | public String validateNewPwd(UserEntity ue, String newPwd) { |
| | | if (StringHelper.isEmpty(newPwd)) { |
| | | return "新密码不能为空"; |
| | | } |
| | | |
| | | try { |
| | | String pwd = RsaHelper.decrypt(newPwd); |
| | | if (!StringHelper.checkPwdValid(pwd)) { |
| | | return "密码不符合要求"; |
| | | } |
| | | |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(pwd)); |
| | | ue.setSalt(dbPwd); |
| | | |
| | | return null; |
| | | } catch (Exception ex) { |
| | | return "密码解密失败"; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 设置密码错误缓存 |
| | | * |
| | | * @param ue |
| | | */ |
| | | public void setPwdErrCache(UserEntity ue) { |
| | | String key = RedisCacheKey.signPwdError(ue.getUid()); |
| | | Object objCount = redisService.get(key); |
| | | |
| | | int count = objCount == null ? 1 : (int) objCount + 1; |
| | | redisService.put(key, count, SettingData.PWD_ERR_TIME, TimeUnit.MINUTES); |
| | | } |
| | | } |