|
@@ -13,6 +13,8 @@ import com.huiju.welcome.utils.StatusUtils;
|
13
|
13
|
import io.swagger.annotations.ApiImplicitParam;
|
14
|
14
|
import io.swagger.annotations.ApiImplicitParams;
|
15
|
15
|
import io.swagger.annotations.ApiOperation;
|
|
16
|
+import lombok.extern.slf4j.Slf4j;
|
|
17
|
+import org.apache.commons.lang3.StringUtils;
|
16
|
18
|
import org.apache.http.HttpStatus;
|
17
|
19
|
import org.slf4j.Logger;
|
18
|
20
|
import org.slf4j.LoggerFactory;
|
|
@@ -37,6 +39,7 @@ import java.util.Map;
|
37
|
39
|
*/
|
38
|
40
|
@RestController
|
39
|
41
|
@RequestMapping("/")
|
|
42
|
+@Slf4j
|
40
|
43
|
public class SysUserController extends BaseController {
|
41
|
44
|
|
42
|
45
|
private final Logger logger = LoggerFactory.getLogger(TdSpecController.class);
|
|
@@ -200,13 +203,59 @@ public class SysUserController extends BaseController {
|
200
|
203
|
ResponseBean responseBean = new ResponseBean();
|
201
|
204
|
|
202
|
205
|
sysUser.setCreateDate(LocalDateTime.now());
|
203
|
|
-
|
204
|
206
|
boolean success = sysUserService.save(sysUser);
|
|
207
|
+
|
|
208
|
+ String defaultPwd = "123456";
|
|
209
|
+ String passwd = Encrypt.md5(Encrypt.md5(defaultPwd), sysUser.getUserId().toString());
|
|
210
|
+ log.info("创建新人员:{}, 默认密码:{},加密盐:{}, 加密后: {}", sysUser.getUsername(), defaultPwd, sysUser.getUserId().toString(), passwd);
|
|
211
|
+ sysUser.setPassword(passwd);
|
|
212
|
+ success = sysUserService.updateById(sysUser);
|
|
213
|
+
|
|
214
|
+
|
205
|
215
|
if (!success) {
|
206
|
216
|
responseBean.addError(HttpStatus.SC_INTERNAL_SERVER_ERROR, "新增用户失败");
|
207
|
217
|
return responseBean;
|
208
|
218
|
}
|
209
|
219
|
|
|
220
|
+ responseBean.addSuccess(sysUser);
|
|
221
|
+ return responseBean;
|
|
222
|
+ }
|
|
223
|
+
|
|
224
|
+ @ApiOperation(value = "修改密码", notes = "修改密码")
|
|
225
|
+ @ApiImplicitParams({
|
|
226
|
+ @ApiImplicitParam(paramType = "form", dataType = "String", name = "oldPwd", value = "旧密码"),
|
|
227
|
+ @ApiImplicitParam(paramType = "form", dataType = "String", name = "newPwd", value = "新密码")
|
|
228
|
+ })
|
|
229
|
+ @RequestMapping(value = "/updatePwd", method = RequestMethod.POST)
|
|
230
|
+ public ResponseBean updatePwd(@RequestParam String oldPwd, @RequestParam String newPwd, HttpSession session) {
|
|
231
|
+ ResponseBean responseBean = new ResponseBean();
|
|
232
|
+ if (StringUtils.isBlank(oldPwd)) {
|
|
233
|
+ responseBean.addError(HttpStatus.SC_BAD_REQUEST, "旧密码不能为空");
|
|
234
|
+ }
|
|
235
|
+ if (StringUtils.isBlank(newPwd)) {
|
|
236
|
+ responseBean.addError(HttpStatus.SC_BAD_REQUEST, "新密码不能为空");
|
|
237
|
+ }
|
|
238
|
+
|
|
239
|
+ Integer userId = (Integer) session.getAttribute("token-id");
|
|
240
|
+ SysUser currentUser = sysUserService.getById(userId);
|
|
241
|
+ oldPwd = Encrypt.md5(oldPwd);
|
|
242
|
+ // 密码校验
|
|
243
|
+ if (!checkPassword(oldPwd, currentUser)) {
|
|
244
|
+ responseBean.addError(HttpStatus.SC_BAD_REQUEST, "旧密码不正确");
|
|
245
|
+ return responseBean;
|
|
246
|
+ }
|
|
247
|
+
|
|
248
|
+ String passwd = Encrypt.md5(Encrypt.md5(newPwd), currentUser.getUserId().toString());
|
|
249
|
+ log.info("修改人员信息:{}, 新密码:{},加密盐:{}, 加密后: {}", currentUser.getUsername(), newPwd, currentUser.getUserId().toString(), passwd);
|
|
250
|
+ currentUser.setPassword(passwd);
|
|
251
|
+ boolean success = sysUserService.updateById(currentUser);
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+ if (!success) {
|
|
255
|
+ responseBean.addError(HttpStatus.SC_INTERNAL_SERVER_ERROR, "修改密码失败");
|
|
256
|
+ return responseBean;
|
|
257
|
+ }
|
|
258
|
+
|
210
|
259
|
return responseBean;
|
211
|
260
|
}
|
212
|
261
|
|
|
@@ -217,6 +266,7 @@ public class SysUserController extends BaseController {
|
217
|
266
|
@RequestMapping(value = "/sysuser", method = RequestMethod.PUT)
|
218
|
267
|
public ResponseBean update(@RequestBody SysUser sysUser, HttpServletRequest request) {
|
219
|
268
|
ResponseBean responseBean = new ResponseBean();
|
|
269
|
+ sysUser.setPassword(null);
|
220
|
270
|
boolean success = sysUserService.updateById(sysUser);
|
221
|
271
|
if (!success) {
|
222
|
272
|
responseBean.addError(HttpStatus.SC_INTERNAL_SERVER_ERROR, "更新用户失败");
|