管理员服务
| 43 | * 管理员服务 |
| 44 | */ |
| 45 | @Service |
| 46 | public class AdminServiceImpl implements AdminService { |
| 47 | @Resource StaffRepository staffRepository; |
| 48 | @Resource FileComponent fileComponent; |
| 49 | @Resource StaffCacheManager staffCacheManager; |
| 50 | @Resource TopicRepository topicRepository; |
| 51 | @Resource CommentRepository commentRepository; |
| 52 | @Resource QuestionRepository questionRepository; |
| 53 | @Resource AnswerRepository answerRepository; |
| 54 | @Resource FeedbackRepository feedbackRepository; |
| 55 | @Resource ReportRepository reportRepository; |
| 56 | @Resource AdminCacheManager adminCacheManager; |
| 57 | @Resource Environment environment; |
| 58 | @Resource SettingCacheManager settingCacheManager; |
| 59 | @Resource CaptchaCacheManager captchaCacheManager; |
| 60 | @Resource StaffLoginLogShardingConfig staffLoginLogShardingConfig; |
| 61 | @Resource AuthenticationManager authenticationManager; |
| 62 | @Resource StaffLoginLogComponent staffLoginLogComponent; |
| 63 | |
| 64 | |
| 65 | /** |
| 66 | * 登录界面信息 |
| 67 | * @param username 员工账号 |
| 68 | * @return |
| 69 | */ |
| 70 | public Map<String, Object> getLoginViewModel(String username) { |
| 71 | Map<String, Object> returnValue = new HashMap<>(); |
| 72 | |
| 73 | //是否需要验证码 true:要 false:不要 |
| 74 | boolean isCaptcha = false; |
| 75 | |
| 76 | //登录失败超过N次,出现验证码 0为每次都出现验证码 |
| 77 | int failedLoginCount = environment.getProperty("bbs.admin.failedLoginCount", Integer.class, 0); |
| 78 | if(failedLoginCount <=0){//每分钟连续登录密码错误N次时出现验证码 |
| 79 | isCaptcha = true; |
| 80 | }else{ |
| 81 | if(username != null && !username.trim().isEmpty()){ |
| 82 | Integer errorCount = staffCacheManager.getLoginFailureCount(username);//查询错误次数 |
| 83 | if(errorCount != null && errorCount >= failedLoginCount){ |
| 84 | isCaptcha = true; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | } |
| 89 | if(isCaptcha){ |
| 90 | returnValue.put("isCaptcha", true); |
| 91 | returnValue.put("captchaKey", UUIDUtil.getUUID32()); |
| 92 | }else{ |
| 93 | returnValue.put("isCaptcha", false); |
| 94 | } |
| 95 | return returnValue; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * 登录 |
| 100 | * @param username 员工账号 |
| 101 | * @param password 密码 |
| 102 | * @param captchaKey 验证码key |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…