From c2b7ba0835bc4b65c8da27b6012e18a0c8f15ec5 Mon Sep 17 00:00:00 2001 From: qi_liang Date: Wed, 11 Sep 2019 14:24:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=B8=80=E4=B8=AA=E7=99=BB?= =?UTF-8?q?=E9=99=86=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9=E8=87=AA=E5=B7=B1?= =?UTF-8?q?=E8=B5=84=E6=96=99=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/lq/cms/web/sys/UserController.java | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/lq/cms/web/sys/UserController.java b/src/main/java/com/lq/cms/web/sys/UserController.java index ac133ed..08436e2 100755 --- a/src/main/java/com/lq/cms/web/sys/UserController.java +++ b/src/main/java/com/lq/cms/web/sys/UserController.java @@ -8,11 +8,17 @@ import com.lq.cms.service.SysUserService; import com.lq.cms.vo.SysUserRoleVo; import com.lq.cms.vo.SysUserVo; import com.lq.code.entity.AjaxResult; +import com.lq.code.interceptor.shiro.ShiroRealm; import com.lq.code.util.*; import com.lq.entity.SysUser; import org.apache.log4j.Logger; import org.apache.shiro.SecurityUtils; +import org.apache.shiro.authc.UsernamePasswordToken; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.apache.shiro.cache.Cache; +import org.apache.shiro.mgt.RealmSecurityManager; +import org.apache.shiro.subject.PrincipalCollection; +import org.apache.shiro.subject.SimplePrincipalCollection; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -182,15 +188,28 @@ public class UserController { return ajaxResult; } - - public AjaxResult updateUser(SysUser sysUser){ + @RequestMapping("/updateUser") + @ResponseBody + public AjaxResult updateUser(SysUser sysUser,@RequestParam(value = "uploadFile",required = false) MultipartFile uploadFile){ Subject subject = SecurityUtils.getSubject(); SysUser loginUser =(SysUser)subject.getPrincipal(); if (loginUser!=null){ BeanUtil.copyNotNull(loginUser,sysUser); + String uploadFileName =upLoadFile(uploadFile); + loginUser.setUpdateTime(new Date()); + if (StringUtil.isNotNull(uploadFileName)) { + loginUser.setImgUrl(uploadFileName); + } sysUserService.update(loginUser); + RealmSecurityManager securityManager = (RealmSecurityManager) SecurityUtils.getSecurityManager(); + PrincipalCollection principalCollection = subject.getPrincipals(); + String realName = principalCollection.getRealmNames().iterator().next(); + PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(loginUser,realName); + subject.runAs(newPrincipalCollection); } - return new AjaxResult(); + AjaxResult ajaxResult = new AjaxResult(); + ajaxResult.setData(loginUser); + return ajaxResult; }