Pārlūkot izejas kodu

教研密码

tags/正式3.2.0
王宁 pirms 2 gadiem
vecāks
revīzija
f568bd1662

+ 182
- 149
suser/src/main/java/com/xhkjedu/suser/service/system/UserService.java Parādīt failu

@@ -13,15 +13,12 @@ import com.xhkjedu.suser.model.system.TUserLog;
13 13
 import com.xhkjedu.suser.utils.JedisUtil;
14 14
 import com.xhkjedu.suser.utils.PoiUtils;
15 15
 import com.xhkjedu.suser.utils.SMSSender;
16
+import com.xhkjedu.suser.utils.UserUtil;
16 17
 import com.xhkjedu.suser.vo.assess.AssessParams;
17 18
 import com.xhkjedu.suser.vo.system.TeacherVo;
18 19
 import com.xhkjedu.suser.vo.system.UserVo;
19 20
 import com.xhkjedu.suser.vo.system.ZtMsgVo;
20
-import com.xhkjedu.utils.DESUtils;
21
-import com.xhkjedu.utils.DatesUtil;
22
-import com.xhkjedu.utils.MD5;
23
-import com.xhkjedu.utils.N_Utils;
24
-import com.xhkjedu.utils.PageUtil;
21
+import com.xhkjedu.utils.*;
25 22
 import com.xhkjedu.vo.PageResult;
26 23
 import com.xhkjedu.vo.ResultVo;
27 24
 import lombok.extern.slf4j.Slf4j;
@@ -32,11 +29,7 @@ import org.springframework.web.multipart.MultipartFile;
32 29
 
33 30
 import javax.annotation.Resource;
34 31
 import javax.servlet.http.HttpServletRequest;
35
-import java.util.ArrayList;
36
-import java.util.HashMap;
37
-import java.util.List;
38
-import java.util.Map;
39
-import java.util.UUID;
32
+import java.util.*;
40 33
 
41 34
 /**
42 35
  * @ClassName UserService
@@ -58,19 +51,20 @@ public class UserService extends JedisUtil {
58 51
     private SchoolMapper schoolMapper;
59 52
 
60 53
     /**
61
-     *功能描述  根据登录名和密码获取用户信息
54
+     * 功能描述  根据登录名和密码获取用户信息
55
+     *
56
+     * @param * @param user
57
+     * @return com.xhkjedu.vo.ResultVo
62 58
      * @author WN
63 59
      * @date 2020/6/1
64
-     * @param  * @param user
65
-     * @return com.xhkjedu.vo.ResultVo
66 60
      */
67
-    public ResultVo getUserByLoginnameAndPwd(TUser user,HttpServletRequest request){
61
+    public ResultVo getUserByLoginnameAndPwd(TUser user, HttpServletRequest request) {
68 62
         ResultVo resultVo = null;
69 63
         String loginpwd = user.getLoginpwd();
70 64
         setLoginPwd(user);
71 65
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
72 66
 
73
-        if(userVo!=null && userVo.getUserid()>0){
67
+        if (userVo != null && userVo.getUserid() > 0) {
74 68
             user.setUserid(userVo.getUserid());
75 69
             user.setUsername(userVo.getUsername());
76 70
             user.setSchoolid(userVo.getSchoolid());
@@ -81,31 +75,31 @@ public class UserService extends JedisUtil {
81 75
                     resultVo = new ResultVo(0, "登录成功", userVo);
82 76
                 } else if (userVo.getUsertype() == 2) {
83 77
                     resultVo = new ResultVo(1, "禁止学生登录");
84
-                } else if(userVo.getSchoolstate()!=1){
85
-                    resultVo = new ResultVo(1,"用户所在学校暂无权限");
86
-                }else{
87
-                    if(userVo.getUserstate()!=1){
88
-                        resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
89
-                    }else{
90
-                        resultVo = new ResultVo(0,"登录成功",userVo);
78
+                } else if (userVo.getSchoolstate() != 1) {
79
+                    resultVo = new ResultVo(1, "用户所在学校暂无权限");
80
+                } else {
81
+                    if (userVo.getUserstate() != 1) {
82
+                        resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
83
+                    } else {
84
+                        resultVo = new ResultVo(0, "登录成功", userVo);
91 85
                     }
92 86
                 }
93 87
             }
94
-        }else{
95
-            resultVo = new ResultVo(1,"该账号不存在");
88
+        } else {
89
+            resultVo = new ResultVo(1, "该账号不存在");
96 90
         }
97 91
 
98 92
         return getLogResultVo(user, resultVo, loginpwd, request);
99 93
     }
100 94
 
101 95
     //教师登录
102
-    public ResultVo loginTeacher(TUser user,HttpServletRequest request){
96
+    public ResultVo loginTeacher(TUser user, HttpServletRequest request) {
103 97
         ResultVo resultVo = null;
104 98
         String loginpwd = user.getLoginpwd();
105 99
         setLoginPwd(user);
106 100
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
107 101
 
108
-        if(userVo!=null && userVo.getUserid()>0) {
102
+        if (userVo != null && userVo.getUserid() > 0) {
109 103
             user.setUserid(userVo.getUserid());
110 104
             user.setUsername(userVo.getUsername());
111 105
             user.setSchoolid(userVo.getSchoolid());
@@ -116,16 +110,16 @@ public class UserService extends JedisUtil {
116 110
                     resultVo = new ResultVo(1, "禁止非教师账号登录");
117 111
                 } else if (userVo.getSchoolstate() != 1) {
118 112
                     resultVo = new ResultVo(1, "用户所在学校暂无权限");
119
-                }else{
120
-                    if(userVo.getUserstate()!=1){
121
-                        resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
122
-                    }else{
123
-                        resultVo = new ResultVo(0,"登录成功",userVo);
113
+                } else {
114
+                    if (userVo.getUserstate() != 1) {
115
+                        resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
116
+                    } else {
117
+                        resultVo = new ResultVo(0, "登录成功", userVo);
124 118
                     }
125 119
                 }
126 120
             }
127
-        }else{
128
-            resultVo = new ResultVo(1,"该账号不存在");
121
+        } else {
122
+            resultVo = new ResultVo(1, "该账号不存在");
129 123
         }
130 124
 
131 125
         return getLogResultVo(user, resultVo, loginpwd, request);
@@ -133,19 +127,20 @@ public class UserService extends JedisUtil {
133 127
 
134 128
     /**
135 129
      * 学生登录
130
+     *
131
+     * @return com.xhkjedu.vo.ResultVo
136 132
      * @Param [user]
137 133
      * @Author ywx
138 134
      * @Date 2020/6/2 11:14
139
-     * @return com.xhkjedu.vo.ResultVo
140 135
      **/
141
-    public ResultVo loginStudent(TUser user, HttpServletRequest request){
136
+    public ResultVo loginStudent(TUser user, HttpServletRequest request) {
142 137
         ResultVo resultVo = null;
143 138
         String loginpwd = user.getLoginpwd();
144 139
         setLoginPwd(user);
145 140
         String mac = user.getMac();
146
-        UserVo userVo = userMapper.getUserByLoginnameMac(user.getLoginname(),mac);
141
+        UserVo userVo = userMapper.getUserByLoginnameMac(user.getLoginname(), mac);
147 142
 
148
-        if(userVo!=null && userVo.getUserid()>0) {
143
+        if (userVo != null && userVo.getUserid() > 0) {
149 144
             Integer sbindmac = userVo.getSbindmac();
150 145
             user.setUserid(userVo.getUserid());
151 146
             user.setUsername(userVo.getUsername());
@@ -156,7 +151,7 @@ public class UserService extends JedisUtil {
156 151
                 if (userVo.getUsertype() != 2) {
157 152
                     resultVo = new ResultVo(1, "登录失败,仅允许学生登录");
158 153
                 } else if (userVo.getXznum() == 0) {
159
-                    resultVo = new ResultVo(1,"该账号未分配班级");
154
+                    resultVo = new ResultVo(1, "该账号未分配班级");
160 155
                 } else if (sbindmac == 1 && N_Utils.isNotEmpty(mac)) {
161 156
                     if (N_Utils.isNotEmpty(userVo.getMac()) && !mac.equals(userVo.getMac())) {
162 157
                         resultVo = new ResultVo(1, "登录失败,该账号已与其他设备关联");
@@ -176,8 +171,8 @@ public class UserService extends JedisUtil {
176 171
                 userVo.setBindmac(sbindmac);
177 172
                 userMapper.updateBindMac(userVo);
178 173
             }
179
-        }else{
180
-            resultVo = new ResultVo(1,"该账号不存在");
174
+        } else {
175
+            resultVo = new ResultVo(1, "该账号不存在");
181 176
         }
182 177
 
183 178
         return getLogResultVo(user, resultVo, loginpwd, request);
@@ -185,10 +180,11 @@ public class UserService extends JedisUtil {
185 180
 
186 181
     /**
187 182
      * 登录日志
183
+     *
184
+     * @return com.xhkjedu.vo.ResultVo
188 185
      * @Param [loginname, device, user, result]
189 186
      * @Author ywx
190 187
      * @Date 2020/6/2 11:08
191
-     * @return com.xhkjedu.vo.ResultVo
192 188
      **/
193 189
     private ResultVo getLogResultVo(TUser user, ResultVo result, String loginpwd, HttpServletRequest request) {
194 190
         String loginname = user.getLoginname();
@@ -209,9 +205,9 @@ public class UserService extends JedisUtil {
209 205
             //redis
210 206
             String ticketKey = UUID.randomUUID().toString().replace("-", "");
211 207
             String token = DESUtils.encrypt(ticketKey, ConfigKey.secretKey);//加密
212
-            String key = userVo.getCloudcode()+"_"+userVo.getUserid()+"_"+user.getUltype();
208
+            String key = userVo.getCloudcode() + "_" + userVo.getUserid() + "_" + user.getUltype();
213 209
             Boolean redis_rtn = set(key, token, ConfigKey.redisdatatime);
214
-            if(!redis_rtn){
210
+            if (!redis_rtn) {
215 211
                 result.setCode(1);
216 212
                 result.setMsg("加入缓存出错!");
217 213
                 return result;
@@ -224,7 +220,7 @@ public class UserService extends JedisUtil {
224 220
             }
225 221
         } else {
226 222
             userLog.setLoginstate(2);
227
-            userLog.setLogtxt(result.getMsg()+",密码:"+loginpwd);
223
+            userLog.setLogtxt(result.getMsg() + ",密码:" + loginpwd);
228 224
         }
229 225
         try {
230 226
             userLog.setUserid(user.getUserid());
@@ -245,10 +241,11 @@ public class UserService extends JedisUtil {
245 241
 
246 242
     /**
247 243
      * 添加用户信息
244
+     *
245
+     * @return com.xhkjedu.vo.ResultVo
248 246
      * @Param [user]
249 247
      * @Author ywx
250 248
      * @Date 2020/6/2 9:45
251
-     * @return com.xhkjedu.vo.ResultVo
252 249
      **/
253 250
     public ResultVo save(TUser user) {
254 251
         Integer schoolid = user.getSchoolid();
@@ -257,22 +254,23 @@ public class UserService extends JedisUtil {
257 254
             Integer usernum2 = userMapper.getUserNumBySchoolId(schoolid);
258 255
             usernum2 = usernum2 + 1;//学校账号数量+本次添加的人
259 256
             if (usernum.compareTo(usernum2) == -1) {
260
-                return new ResultVo(1,"账号数量已超限,请联系管理员");
257
+                return new ResultVo(1, "账号数量已超限,请联系管理员");
261 258
             }
262 259
         }
263 260
         user.setUserstate(1);
264 261
         user.setCreatetime(N_Utils.getSecondTimestamp());
265 262
         setLoginPwd(user);
266 263
         userMapper.insertUseGeneratedKeys(user);
267
-        return new ResultVo(0, "保存成功",user.getId());
264
+        return new ResultVo(0, "保存成功", user.getId());
268 265
     }
269 266
 
270 267
     /**
271 268
      * 修改用户信息
269
+     *
270
+     * @return com.xhkjedu.vo.ResultVo
272 271
      * @Param [user]
273 272
      * @Author ywx
274 273
      * @Date 2020/6/2 9:51
275
-     * @return com.xhkjedu.vo.ResultVo
276 274
      **/
277 275
     public ResultVo update(TUser user) {
278 276
         if (N_Utils.isNotEmpty(user.getLoginpwd())) {
@@ -282,13 +280,13 @@ public class UserService extends JedisUtil {
282 280
         if (N_Utils.isNotEmpty(loginname)) {
283 281
             TUser user1 = getObjByLoginName(loginname);
284 282
             //登录账号改变并且和别的账号冲突
285
-            if (user1!=null && !user1.getUserid().equals(user.getUserid())) {
286
-                return new ResultVo(1,"此用户已存在,请更换!");
283
+            if (user1 != null && !user1.getUserid().equals(user.getUserid())) {
284
+                return new ResultVo(1, "此用户已存在,请更换!");
287 285
             }
288 286
         }
289 287
         user.setCreatetime(N_Utils.getSecondTimestamp());
290 288
         userMapper.updateByPrimaryKeySelective(user);
291
-        return new ResultVo(0,"修改成功");
289
+        return new ResultVo(0, "修改成功");
292 290
     }
293 291
 
294 292
     private void setLoginPwd(TUser user) {
@@ -299,87 +297,96 @@ public class UserService extends JedisUtil {
299 297
 
300 298
     /**
301 299
      * 删除用户
300
+     *
301
+     * @return com.xhkjedu.vo.ResultVo
302 302
      * @Param [user]
303 303
      * @Author ywx
304 304
      * @Date 2020/6/2 9:59
305
-     * @return com.xhkjedu.vo.ResultVo
306 305
      **/
307 306
     public ResultVo deleteById(TUser user) {
308 307
         user.setDeletetime(N_Utils.getSecondTimestamp());
309 308
         userMapper.deleteById(user);
310
-        return new ResultVo(0,"删除成功");
309
+        return new ResultVo(0, "删除成功");
311 310
     }
312 311
 
313 312
     /**
314 313
      * 获取用户列表
314
+     *
315
+     * @return com.xhkjedu.vo.ResultVo
315 316
      * @Param [user]
316 317
      * @Author ywx
317 318
      * @Date 2020/6/2 10:06
318
-     * @return com.xhkjedu.vo.ResultVo
319 319
      **/
320 320
     public ResultVo findAll(TUser user) {
321 321
         PageHelper.startPage(user.getPage(), user.getPageSize());
322 322
         List<UserVo> list = userMapper.findAll(user);
323 323
         PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
324
-        return new ResultVo(0,"获取列表成功", pageResult);
324
+        return new ResultVo(0, "获取列表成功", pageResult);
325 325
     }
326 326
 
327 327
     /**
328 328
      * 获取用户详情
329
+     *
330
+     * @return com.xhkjedu.vo.ResultVo
329 331
      * @Param [userid]
330 332
      * @Author ywx
331 333
      * @Date 2020/6/2 10:23
332
-     * @return com.xhkjedu.vo.ResultVo
333 334
      **/
334 335
     public ResultVo findById(Integer userid) {
335 336
         UserVo userVo = userMapper.findById(userid);
336
-        return new ResultVo(0,"获取详情成功", userVo);
337
+        return new ResultVo(0, "获取详情成功", userVo);
337 338
     }
338 339
 
339 340
     /**
340 341
      * 修改用户密码
342
+     *
343
+     * @return com.xhkjedu.vo.ResultVo
341 344
      * @Param [user]
342 345
      * @Author ywx
343 346
      * @Date 2020/6/2 10:30
344
-     * @return com.xhkjedu.vo.ResultVo
345 347
      **/
346 348
     public ResultVo updatePwd(TUser user) {
347
-        UserVo userVo = userMapper.findById(user.getUserid());
348
-
349
-        String oldpwd = this.md5pwd(user.getOldpwd());
350
-        if(userVo.getLoginpwd().equals(oldpwd)){
351
-            setLoginPwd(user);
352
-            userMapper.updatePwd(user);
353
-            return new ResultVo(0,"修改成功");
354
-        }else{
355
-            return new ResultVo(1,"原密码错误");
349
+        ResultVo pwdResultVo = UserUtil.checkhLoginPwd(user.getLoginpwd());
350
+        if (pwdResultVo.getCode() == 0) {
351
+            UserVo userVo = userMapper.findById(user.getUserid());
352
+            String oldpwd = this.md5pwd(user.getOldpwd());
353
+            if (userVo.getLoginpwd().equals(oldpwd)) {
354
+                setLoginPwd(user);
355
+                userMapper.updatePwd(user);
356
+                return new ResultVo(0, "修改成功");
357
+            } else {
358
+                return new ResultVo(1, "原密码错误");
359
+            }
360
+        } else {
361
+            return pwdResultVo;
356 362
         }
357
-
358 363
     }
359 364
 
360 365
     /**
361 366
      * 修改用户头像
367
+     *
368
+     * @return com.xhkjedu.vo.ResultVo
362 369
      * @Param [user]
363 370
      * @Author ywx
364 371
      * @Date 2020/6/2 10:37
365
-     * @return com.xhkjedu.vo.ResultVo
366 372
      **/
367 373
     public ResultVo updateHeadPic(TUser user) {
368 374
         userMapper.updateHeadPic(user);
369
-        return new ResultVo(0,"修改成功");
375
+        return new ResultVo(0, "修改成功");
370 376
     }
371 377
 
372 378
     /**
373 379
      * 检查登录账号是否存在
380
+     *
381
+     * @return com.xhkjedu.vo.ResultVo
374 382
      * @Param [loginname]
375 383
      * @Author ywx
376 384
      * @Date 2020/6/2 10:44
377
-     * @return com.xhkjedu.vo.ResultVo
378 385
      **/
379 386
     public ResultVo checkLoginName(String loginname) {
380 387
         Integer num = userMapper.checkLoginName(loginname);
381
-        if (num != 0){
382
-            return new ResultVo(1,"此用户已存在,请更换!");
388
+        if (num != 0) {
389
+            return new ResultVo(1, "此用户已存在,请更换!");
383 390
         } else {
384 391
             return new ResultVo(0, "检查登录账号是否存在成功");
385 392
         }
@@ -387,10 +394,11 @@ public class UserService extends JedisUtil {
387 394
 
388 395
     /**
389 396
      * 根据登录账号获取用户详情
397
+     *
398
+     * @return com.xhkjedu.model.system.TUser
390 399
      * @Param [loginname]
391 400
      * @Author ywx
392 401
      * @Date 2020/6/3 9:33
393
-     * @return com.xhkjedu.model.system.TUser
394 402
      **/
395 403
     public TUser getObjByLoginName(String loginname) {
396 404
         return userMapper.getObjByLoginName(loginname);
@@ -398,10 +406,11 @@ public class UserService extends JedisUtil {
398 406
 
399 407
     /**
400 408
      * 批量添加
409
+     *
410
+     * @return void
401 411
      * @Param [users]
402 412
      * @Author ywx
403 413
      * @Date 2020/6/3 18:27
404
-     * @return void
405 414
      **/
406 415
     public void batchSave(List<TUser> users) throws Exception {
407 416
         Integer schoolid = users.get(0).getSchoolid();
@@ -418,10 +427,11 @@ public class UserService extends JedisUtil {
418 427
 
419 428
     /**
420 429
      * 修改用户状态
430
+     *
431
+     * @return void
421 432
      * @Param [userid, userstate]
422 433
      * @Author ywx
423 434
      * @Date 2020/6/4 9:08
424
-     * @return void
425 435
      **/
426 436
     public void updateState(Integer userid, int userstate) {
427 437
         userMapper.updateState(userid, userstate);
@@ -429,18 +439,19 @@ public class UserService extends JedisUtil {
429 439
 
430 440
     /**
431 441
      * 导入教师
442
+     *
443
+     * @return com.xhkjedu.vo.ResultVo
432 444
      * @Param [file, tUser]
433 445
      * @Author ywx
434 446
      * @Date 2020/6/5 8:47
435
-     * @return com.xhkjedu.vo.ResultVo
436 447
      **/
437 448
     public ResultVo importTeacher(MultipartFile file, TUser tUser) {
438 449
         Integer schoolid = tUser.getSchoolid();
439 450
         Integer createid = tUser.getCreateid();
440
-        N_Utils.validation(new Object[]{schoolid,"学校id",1,createid,"创建人id",1});
451
+        N_Utils.validation(new Object[]{schoolid, "学校id", 1, createid, "创建人id", 1});
441 452
         try {
442
-            Map<String,Object> map = PoiUtils.readExcelUser(file, 1);
443
-            List<TUser> teachers = (List<TUser>)map.get("users");
453
+            Map<String, Object> map = PoiUtils.readExcelUser(file, 1);
454
+            List<TUser> teachers = (List<TUser>) map.get("users");
444 455
             map.remove("users");//导入成功的教师信息不返回给前端
445 456
 
446 457
             List<TUser> users = new ArrayList<>();
@@ -448,14 +459,14 @@ public class UserService extends JedisUtil {
448 459
             List<TUser> usersExisted = new ArrayList<>();
449 460
             for (TUser user : teachers) {
450 461
                 TUser u = getObjByLoginName(user.getLoginname());
451
-                if (null == u){
462
+                if (null == u) {
452 463
                     user.setSchoolid(schoolid);
453 464
                     user.setCreateid(createid);
454 465
                     user.setCreatetime(N_Utils.getSecondTimestamp());
455 466
                     user.setUserstate(1);
456 467
                     users.add(user);
457 468
                 } else {
458
-                    if (1 != u.getUsertype() || schoolid != u.getSchoolid()){
469
+                    if (1 != u.getUsertype() || schoolid != u.getSchoolid()) {
459 470
                         usersExisted.add(u);
460 471
                     } else {
461 472
                         usersExisted.add(u);
@@ -467,11 +478,11 @@ public class UserService extends JedisUtil {
467 478
             if (!CollectionUtils.isEmpty(users)) {
468 479
                 batchSave(users);
469 480
             }
470
-            map.put("usersExisted",usersExisted);
471
-            if (N_Utils.isListNotEmpty(usersExisted)){
472
-                map.put("code",1);
481
+            map.put("usersExisted", usersExisted);
482
+            if (N_Utils.isListNotEmpty(usersExisted)) {
483
+                map.put("code", 1);
473 484
             } else {
474
-                map.put("code",0);
485
+                map.put("code", 0);
475 486
             }
476 487
             return new ResultVo(0, "导入成功", map);
477 488
         } catch (Exception e) {
@@ -480,42 +491,45 @@ public class UserService extends JedisUtil {
480 491
         }
481 492
     }
482 493
 
483
-    private String md5pwd(String pwd){
494
+    private String md5pwd(String pwd) {
484 495
         MD5 m = new MD5();
485 496
         String loginpwd = m.getMD5ofStr(m.getMD5ofStr(m.getMD5ofStr(pwd)));
486 497
         return loginpwd;
487 498
     }
488 499
 
489 500
     /**
490
-     *功能描述 修改操作密码
501
+     * 功能描述 修改操作密码
502
+     *
503
+     * @param * @param user
504
+     * @return void
491 505
      * @author WN
492 506
      * @date 2020/6/17
493
-     * @param  * @param user
494
-     * @return void
495 507
      */
496
-    public void updateOpepasswordByUserId(TUser user){
508
+    public void updateOpepasswordByUserId(TUser user) {
497 509
         String pwd = md5pwd(user.getOpepassword());
498
-        userMapper.updateOpepasswordByUserId(user.getUserid(),pwd);
510
+        userMapper.updateOpepasswordByUserId(user.getUserid(), pwd);
499 511
     }
500 512
 
501 513
     /**
502
-     *功能描述 验证用户操作密码
514
+     * 功能描述 验证用户操作密码
515
+     *
516
+     * @param * @param user
517
+     * @return java.lang.Integer
503 518
      * @author WN
504 519
      * @date 2020/6/17
505
-     * @param  * @param user
506
-     * @return java.lang.Integer
507 520
      */
508
-    public Integer getUserIdByOpepassword(TUser user){
521
+    public Integer getUserIdByOpepassword(TUser user) {
509 522
         String pwd = md5pwd(user.getOpepassword());
510
-        return userMapper.getUserIdByOpepassword(user.getUserid(),pwd);
523
+        return userMapper.getUserIdByOpepassword(user.getUserid(), pwd);
511 524
     }
512 525
 
513 526
     /**
514 527
      * 教师基本信息
528
+     *
529
+     * @return com.xhkjedu.suser.vo.system.TeacherVo
515 530
      * @Param [userid]
516 531
      * @Author ywx
517 532
      * @Date 2020/6/29 16:23
518
-     * @return com.xhkjedu.suser.vo.system.TeacherVo
519 533
      **/
520 534
     public TeacherVo getTeacherInfo(Integer userid, Integer classtype) {
521 535
         return userMapper.getTeacherInfo(userid, classtype);
@@ -523,23 +537,30 @@ public class UserService extends JedisUtil {
523 537
 
524 538
     /**
525 539
      * 重置密码
540
+     *
541
+     * @return com.xhkjedu.vo.ResultVo
526 542
      * @Param [user]
527 543
      * @Author ywx
528 544
      * @Date 2020/7/30 14:25
529
-     * @return com.xhkjedu.vo.ResultVo
530 545
      **/
531 546
     public ResultVo resetPwd(TUser user) {
532
-        setLoginPwd(user);
533
-        userMapper.updatePwd(user);
534
-        return new ResultVo(0,"重置密码成功");
547
+        ResultVo pwdResultVo = UserUtil.checkhLoginPwd(user.getLoginpwd());
548
+        if (pwdResultVo.getCode() == 0) {//密码验证通过
549
+            setLoginPwd(user);
550
+            userMapper.updatePwd(user);
551
+            return new ResultVo(0, "重置密码成功");
552
+        } else {
553
+            return pwdResultVo;
554
+        }
535 555
     }
536 556
 
537 557
     /**
538 558
      * 解除mac绑定
559
+     *
560
+     * @return void
539 561
      * @Param [studentid]
540 562
      * @Author ywx
541 563
      * @Date 2020/9/18 11:56
542
-     * @return void
543 564
      **/
544 565
     public void removeBind(Integer studentid) {
545 566
         UserVo user = new UserVo();
@@ -551,23 +572,25 @@ public class UserService extends JedisUtil {
551 572
 
552 573
     /**
553 574
      * 生成修改码
575
+     *
576
+     * @return com.xhkjedu.vo.ResultVo
554 577
      * @Param [userphone]
555 578
      * @Author ywx
556 579
      * @Date 2020/10/13 15:08
557
-     * @return com.xhkjedu.vo.ResultVo
558 580
      **/
559 581
     public ResultVo updateCode(String userphone) {
560 582
         String templateCode = "xgmm";
561 583
         if (generateCode(userphone, templateCode)) return new ResultVo(1, "请输入验证码或者在5分钟之后重新点击");
562
-        return new ResultVo(0,"生成修改码成功");
584
+        return new ResultVo(0, "生成修改码成功");
563 585
     }
564 586
 
565 587
     /**
566 588
      * 生成验证码
589
+     *
590
+     * @return boolean
567 591
      * @Param [userphone, templateCode]
568 592
      * @Author ywx
569 593
      * @Date 2020/5/8 10:04
570
-     * @return boolean
571 594
      **/
572 595
     private boolean generateCode(String userphone, String templateCode) {
573 596
         Integer msgNum = msgMapper.getMsgNumByUserPhone(userphone);//5分钟内发送短信次数
@@ -599,25 +622,32 @@ public class UserService extends JedisUtil {
599 622
 
600 623
     /**
601 624
      * 通过短信修改密码
625
+     *
626
+     * @return com.xhkjedu.vo.ResultVo
602 627
      * @Param [user]
603 628
      * @Author ywx
604 629
      * @Date 2020/10/13 15:17
605
-     * @return com.xhkjedu.vo.ResultVo
606 630
      **/
607 631
     public ResultVo updatePwdByCode(TUser user) {
608
-        setLoginPwd(user);
609
-        ResultVo x = getCodeResultVo(user.getUserphone(), user.getMsgcode());
610
-        if (x != null) return x;
611
-        userMapper.updatePwdByCode(user);
612
-        return new ResultVo(0,"修改成功");
632
+        ResultVo pwdResultVo = UserUtil.checkhLoginPwd(user.getLoginpwd());
633
+        if (pwdResultVo.getCode() == 0) {
634
+            setLoginPwd(user);
635
+            ResultVo x = getCodeResultVo(user.getUserphone(), user.getMsgcode());
636
+            if (x != null) return x;
637
+            userMapper.updatePwdByCode(user);
638
+            return new ResultVo(0, "修改成功");
639
+        } else {
640
+            return pwdResultVo;
641
+        }
613 642
     }
614 643
 
615 644
     /**
616 645
      * 判断验证码是否有效
646
+     *
647
+     * @return com.xhkjedu.model.baseinfo.ResultVo
617 648
      * @Param [userphone, messageCode]
618 649
      * @Author ywx
619 650
      * @Date 2020/5/8 10:21
620
-     * @return com.xhkjedu.model.baseinfo.ResultVo
621 651
      **/
622 652
     private ResultVo getCodeResultVo(String userphone, Integer messageCode) {
623 653
         TMsg msg = msgMapper.findByUserPhoneAndCode(userphone, messageCode);//根据手机号和验证码获取短信信息
@@ -629,58 +659,60 @@ public class UserService extends JedisUtil {
629 659
 
630 660
     /**
631 661
      * 生成登录确认码
662
+     *
663
+     * @return com.xhkjedu.vo.ResultVo
632 664
      * @Param [userphone]
633 665
      * @Author ywx
634 666
      * @Date 2020/10/13 15:19
635
-     * @return com.xhkjedu.vo.ResultVo
636 667
      **/
637 668
     public ResultVo loginCode(String userphone) {
638
-        N_Utils.validation(new Object[]{userphone,"手机号",2});
669
+        N_Utils.validation(new Object[]{userphone, "手机号", 2});
639 670
         String templateCode = "dlqr";
640 671
         if (generateCode(userphone, templateCode)) return new ResultVo(1, "请输入验证码或者在5分钟之后重新点击");
641
-        return new ResultVo(0,"生成登录确认码成功");
672
+        return new ResultVo(0, "生成登录确认码成功");
642 673
     }
643 674
 
644 675
     /**
645 676
      * 验证码登录
677
+     *
678
+     * @return com.xhkjedu.vo.ResultVo
646 679
      * @Param [user]
647 680
      * @Author ywx
648 681
      * @Date 2020/10/13 15:36
649
-     * @return com.xhkjedu.vo.ResultVo
650 682
      **/
651
-    public ResultVo loginByCode(TUser user,HttpServletRequest request) {
683
+    public ResultVo loginByCode(TUser user, HttpServletRequest request) {
652 684
         ResultVo resultVo = getCodeResultVo(user.getUserphone(), user.getMsgcode());
653 685
         if (resultVo != null) return resultVo;
654 686
         UserVo userVo = userMapper.getUserByLoginname(user.getUserphone());
655 687
 
656
-        if(userVo!=null && userVo.getUserid()>0){
688
+        if (userVo != null && userVo.getUserid() > 0) {
657 689
             user.setUserid(userVo.getUserid());
658 690
             user.setUsername(userVo.getUsername());
659 691
             user.setSchoolid(userVo.getSchoolid());
660
-            if(userVo.getUsertype()==999){
661
-                resultVo = new ResultVo(0,"登录成功",userVo);
662
-            } else if(userVo.getUsertype()==2){
663
-                resultVo = new ResultVo(1,"禁止学生登录");
664
-            } else if(userVo.getSchoolstate()!=1){
665
-                resultVo = new ResultVo(1,"用户所在学校暂无权限");
666
-            }else{
667
-                if(userVo.getUserstate()!=1){
668
-                    resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
669
-                }else{
670
-                    resultVo = new ResultVo(0,"登录成功",userVo);
692
+            if (userVo.getUsertype() == 999) {
693
+                resultVo = new ResultVo(0, "登录成功", userVo);
694
+            } else if (userVo.getUsertype() == 2) {
695
+                resultVo = new ResultVo(1, "禁止学生登录");
696
+            } else if (userVo.getSchoolstate() != 1) {
697
+                resultVo = new ResultVo(1, "用户所在学校暂无权限");
698
+            } else {
699
+                if (userVo.getUserstate() != 1) {
700
+                    resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
701
+                } else {
702
+                    resultVo = new ResultVo(0, "登录成功", userVo);
671 703
                 }
672 704
             }
673
-        }else{
674
-            resultVo = new ResultVo(1,"该账号不存在");
705
+        } else {
706
+            resultVo = new ResultVo(1, "该账号不存在");
675 707
         }
676 708
 
677
-        return getLogResultVo(user, resultVo, user.getMsgcode()+"", request);
709
+        return getLogResultVo(user, resultVo, user.getMsgcode() + "", request);
678 710
     }
679 711
 
680 712
     public ResultVo batchUpdatePwd(TUser user) {
681 713
         setLoginPwd(user);
682 714
         userMapper.batchUpdatePwd(user);
683
-        return new ResultVo(0,"修改成功");
715
+        return new ResultVo(0, "修改成功");
684 716
     }
685 717
 
686 718
     public ResultVo checkLogin(Integer userid, String loginpwd) {
@@ -719,26 +751,26 @@ public class UserService extends JedisUtil {
719 751
         ResultVo resultVo = null;
720 752
         UserVo userVo = userMapper.getUserByLoginname(user.getLoginname());
721 753
 
722
-        if(userVo!=null && userVo.getUserid()>0){
754
+        if (userVo != null && userVo.getUserid() > 0) {
723 755
             user.setUserid(userVo.getUserid());
724 756
             user.setUsername(userVo.getUsername());
725 757
             user.setSchoolid(userVo.getSchoolid());
726 758
             user.setUltype("p_web_t");
727
-            if(userVo.getUsertype()==999){
728
-                resultVo = new ResultVo(0,"登录成功",userVo);
729
-            } else if(userVo.getUsertype()==2){
730
-                resultVo = new ResultVo(1,"禁止学生登录");
731
-            } else if(userVo.getSchoolstate()!=1){
732
-                resultVo = new ResultVo(1,"用户所在学校暂无权限");
733
-            }else{
734
-                if(userVo.getUserstate()!=1){
735
-                    resultVo = new ResultVo(1,"该账户无权访问,请联系老师");
736
-                }else{
737
-                    resultVo = new ResultVo(0,"登录成功",userVo);
759
+            if (userVo.getUsertype() == 999) {
760
+                resultVo = new ResultVo(0, "登录成功", userVo);
761
+            } else if (userVo.getUsertype() == 2) {
762
+                resultVo = new ResultVo(1, "禁止学生登录");
763
+            } else if (userVo.getSchoolstate() != 1) {
764
+                resultVo = new ResultVo(1, "用户所在学校暂无权限");
765
+            } else {
766
+                if (userVo.getUserstate() != 1) {
767
+                    resultVo = new ResultVo(1, "该账户无权访问,请联系老师");
768
+                } else {
769
+                    resultVo = new ResultVo(0, "登录成功", userVo);
738 770
                 }
739 771
             }
740
-        }else{
741
-            resultVo = new ResultVo(1,"该账号不存在");
772
+        } else {
773
+            resultVo = new ResultVo(1, "该账号不存在");
742 774
         }
743 775
 
744 776
         return getLogResultVo(user, resultVo, "", request);
@@ -746,10 +778,11 @@ public class UserService extends JedisUtil {
746 778
 
747 779
     /**
748 780
      * 获取头像是否可以修改
781
+     *
782
+     * @return java.lang.Integer
749 783
      * @Param [userid]
750 784
      * @Author ywx
751 785
      * @Date 2022/3/14 9:58
752
-     * @return java.lang.Integer
753 786
      **/
754 787
     public Integer getHeadTime(Integer userid) {
755 788
         return userMapper.getHeadTime(userid);

+ 21
- 2
suser/src/main/java/com/xhkjedu/suser/utils/UserUtil.java Parādīt failu

@@ -1,5 +1,6 @@
1 1
 package com.xhkjedu.suser.utils;
2 2
 
3
+import com.xhkjedu.vo.ResultVo;
3 4
 import lombok.extern.slf4j.Slf4j;
4 5
 import org.springframework.http.HttpEntity;
5 6
 import org.springframework.http.HttpHeaders;
@@ -22,10 +23,11 @@ import java.util.List;
22 23
 public class UserUtil {
23 24
     /**
24 25
      * 发送form-data请求返回json结果
26
+     *
27
+     * @return java.lang.String
25 28
      * @Param [apiUrl, param]
26 29
      * @Author ywx
27 30
      * @Date 2021/5/14 17:41
28
-     * @return java.lang.String
29 31
      **/
30 32
     public static String sendFormData(String apiUrl, MultiValueMap<String, String> param) {
31 33
         try {
@@ -39,8 +41,25 @@ public class UserUtil {
39 41
             String result = response.getBody();
40 42
             return result;
41 43
         } catch (RestClientException e) {
42
-            log.error("发送form-data请求失败",e.getMessage());
44
+            log.error("发送form-data请求失败", e.getMessage());
43 45
             return null;
44 46
         }
45 47
     }
48
+
49
+    /**
50
+     * 功能描述  校验密码,包含字母和数字,长度6-16
51
+     *
52
+     * @param * @param loginpwd
53
+     * @return ResultVo
54
+     * @author WN
55
+     * @date 2022/3/15
56
+     */
57
+    public static ResultVo checkhLoginPwd(String loginpwd) {
58
+        ResultVo resultVo = new ResultVo(1, "密码必须是6-16位的英文字母、数字组合");
59
+        String passRegex = "^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,16}$";
60
+        if (loginpwd.matches(passRegex)) {
61
+            resultVo = new ResultVo(0, "密码符合规范");
62
+        }
63
+        return resultVo;
64
+    }
46 65
 }

Notiek ielāde…
Atcelt
Saglabāt