Skip to content

Commit

Permalink
增加用户profile/settings页面
Browse files Browse the repository at this point in the history
  • Loading branch information
penggle committed May 26, 2017
1 parent f3eb4d2 commit ff3421a
Show file tree
Hide file tree
Showing 20 changed files with 1,193 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Object submitLogin(HttpServletRequest request, HttpServletResponse respon
loginToken.setLoginTime(DateTimeUtils.formatNow());
loginToken.setLoginTimes(user.getLoginTimes());
loginToken.setLastLoginTime(StringUtils.defaultIfEmpty(user.getLastLoginTime(), nowTime));
loginToken.setLoginUserIcon(user.getUserIcon());
loginToken.setLoginUserIcon(user.getUserIconUrl());
loginToken.setLoginRoleNames(loginRoleNames.toString());
user.setLastLoginTime(nowTime);

Expand Down Expand Up @@ -187,11 +187,11 @@ public Object getLoginUserInfo(HttpServletRequest request, HttpServletResponse r
Map<String,Object> user = new HashMap<String,Object>();
user.put("userId", loginToken.getLoginId());
user.put("userName", loginToken.getLoginName());
user.put("userIconUrl", request.getContextPath() + loginToken.getLoginUserIcon());
user.put("userIconUrl", loginToken.getLoginUserIcon());
user.put("userRoleNames", loginToken.getLoginRoleNames());
user.put("lastLoginTime", loginToken.getLastLoginTime());
user.put("messages", new ArrayList<Object>()); //TODO
user.put("notifications", new ArrayList<Object>()); //TODO
user.put("notices", new ArrayList<Object>()); //TODO
return genSuccessResult(user);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.springframework.web.bind.annotation.RequestMethod.POST;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

Expand All @@ -24,7 +25,9 @@
import com.certusnet.xproject.admin.consts.em.AdminUserTypeEnum;
import com.certusnet.xproject.admin.model.AdminRole;
import com.certusnet.xproject.admin.model.AdminUser;
import com.certusnet.xproject.admin.model.AdminUserAccessLog;
import com.certusnet.xproject.admin.service.AdminResourceService;
import com.certusnet.xproject.admin.service.AdminUserAccessLogService;
import com.certusnet.xproject.admin.service.AdminUserService;
import com.certusnet.xproject.admin.web.LoginToken;
import com.certusnet.xproject.common.consts.GlobalConstants;
Expand Down Expand Up @@ -57,6 +60,9 @@ public class AdminUserMgtController extends BaseController {
@Resource(name="adminResourceFacadeService")
private AdminResourceService adminResourceService;

@Resource(name="adminUserAccessLogService")
private AdminUserAccessLogService adminUserAccessLogService;

/**
* 查询用户列表
* @param request
Expand Down Expand Up @@ -133,7 +139,44 @@ public Object editUser(HttpServletRequest request, HttpServletResponse response,
userEditForm.setUserIcon(userIcon);
}
}
adminUserService.updateUser(userEditForm);
adminUserService.updateUser(userEditForm, true);
return genSuccessResult("保存成功!", null);
}

/**
* 当前用户修改信息
* @param request
* @param response
* @param userAddForm
* @param modelMap
* @return
*/
@RequestMapping(value="/admin/user/edit/current", method=POST, consumes=APPLICATION_JSON, produces=APPLICATION_JSON)
@HttpAccessLogging(title="用户修改个人信息")
public Object editCurrentUser(HttpServletRequest request, HttpServletResponse response, @RequestBody AdminUser userEditForm) throws Exception {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
userEditForm.setUserId(loginToken.getLoginId());
userEditForm.setUpdateBy(loginToken.getLoginId());
userEditForm.setUpdateTime(DateTimeUtils.formatNow());

if(StringUtils.isEmpty(userEditForm.getUserIcon())){
userEditForm.setUserIcon(AdminConstants.DEFAULT_USER_AVATAR);
}else{
String userIcon = userEditForm.getUserIcon();
if(userIcon.toLowerCase().startsWith(GlobalConstants.DEFAULT_UPLOAD_SAVE_PATH)){
String srcFullFileName = FileUtils.formatFilePath(request.getSession().getServletContext().getRealPath("/") + userIcon);
userIcon = userIcon.replace(GlobalConstants.DEFAULT_UPLOAD_SAVE_PATH, AdminConstants.USER_ICON_IMAGE_SAVE_PATH);
String destFullFileName = FileUtils.formatFilePath(GlobalConstants.IMAGE_SERVER_ROOT_PATH + userIcon);
FileUtils.copyFile(srcFullFileName, destFullFileName);
userEditForm.setUserIcon(userIcon);
}
}
adminUserService.updateUser(userEditForm, false);
AdminUser loginUser = adminUserService.getUserById(loginToken.getLoginId());
loginToken.setLoginUser(loginUser);
loginToken.setLoginName(loginUser.getUserName());
loginToken.setLoginUserIcon(loginUser.getUserIconUrl());
ShiroUtils.getSession().setAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY, loginToken); //刷新session中的当前登录用户信息
return genSuccessResult("保存成功!", null);
}

Expand Down Expand Up @@ -166,7 +209,23 @@ public Object changeUserPasswd(HttpServletRequest request, HttpServletResponse r
if(forceUpdate == null){
forceUpdate = false;
}
adminUserService.updatePassword(passwdEditForm, forceUpdate);
adminUserService.updatePassword(passwdEditForm, forceUpdate, true);
return genSuccessResult("修改成功!", null);
}

/**
* 当前用户修改密码
* @param request
* @param response
* @param passwdEditForm
* @return
*/
@RequestMapping(value="/admin/user/changepwd/current", method=POST, consumes=APPLICATION_JSON, produces=APPLICATION_JSON)
@HttpAccessLogging(title="用户修改登录密码", excludeParamNames={"password", "oldpassword","repassword"})
public Object changeCurrentUserPasswd(HttpServletRequest request, HttpServletResponse response, @RequestBody AdminUser passwdEditForm) {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
passwdEditForm.setUserId(loginToken.getLoginId());
adminUserService.updatePassword(passwdEditForm, false, false);
return genSuccessResult("修改成功!", null);
}

Expand Down Expand Up @@ -212,7 +271,7 @@ protected Result<Object> updateUserStatus(HttpServletRequest request, HttpServle
* @return
*/
@RequestMapping(value="/admin/user/roles", method=GET, produces=APPLICATION_JSON)
public Object loadUserRoles(HttpServletRequest request, HttpServletResponse response, Long userId, AdminRole filterParam) {
public Object getUserRoles(HttpServletRequest request, HttpServletResponse response, Long userId, AdminRole filterParam) {
List<AdminRole> roleList = adminUserService.getUserRoleList(userId, filterParam);
return genSuccessResult(roleList);
}
Expand Down Expand Up @@ -291,4 +350,73 @@ public Object searchUsers(HttpServletRequest request, HttpServletResponse respon
return genSuccessPagingResult(dataList);
}

/**
* 获取当前登录用户拥有的角色列表
* @param request
* @param response
* @param filterParam
* @return
*/
@RequestMapping(value="/admin/user/roles/current", method=GET, produces=APPLICATION_JSON)
public Object getCurrentUserRoles(HttpServletRequest request, HttpServletResponse response, AdminRole filterParam) {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
List<AdminRole> roleList = adminUserService.getUserRoleList(loginToken.getLoginId(), filterParam);
return genSuccessResult(roleList);
}

/**
* 获取当前登录用户拥有的操作日志
* @param request
* @param response
* @param userAccessLogQueryForm
* @param orderBy
* @param pager
* @return
*/
@RequestMapping(value="/admin/user/accesslogs/current", method=GET, produces=APPLICATION_JSON)
public Object getCurrentUserAccessLogs(HttpServletRequest request, HttpServletResponse response, AdminUserAccessLog userAccessLogQueryForm, OrderBy orderBy, Pager pager) {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
userAccessLogQueryForm.setAccessUserId(loginToken.getLoginId());
PagingList<AdminUserAccessLog> dataList = adminUserAccessLogService.getUserAccessLogList(userAccessLogQueryForm, pager, orderBy);
return genSuccessPagingResult(dataList);
}

/**
* 获取当前登录用户信息
* @param request
* @param response
* @return
*/
@RequestMapping(value="/admin/user/info/current", method=GET, produces=APPLICATION_JSON)
public Object getCurrentUserInfo(HttpServletRequest request, HttpServletResponse response) {
LoginToken<AdminUser> loginToken = ShiroUtils.getSessionAttribute(LoginToken.LOGIN_TOKEN_SESSION_KEY);
AdminUser currentUser = loginToken.getLoginUser();
Map<String,Object> user = new HashMap<String,Object>();
user.put("userId", currentUser.getUserId());
user.put("userName", currentUser.getUserName());
user.put("realName", currentUser.getRealName());
user.put("mobilePhone", currentUser.getMobilePhone());
user.put("email", currentUser.getEmail());
user.put("userType", currentUser.getUserType());
user.put("userTypeName", currentUser.getUserTypeName());
user.put("status", currentUser.getStatus());
user.put("statusName", currentUser.getStatusName());
user.put("lastLoginTime", currentUser.getLastLoginTime());
user.put("loginTimes", currentUser.getLoginTimes());
user.put("userIcon", currentUser.getUserIcon());
user.put("userIconUrl", currentUser.getUserIconUrl());
user.put("createTime", currentUser.getCreateTime());
user.put("updateTime", currentUser.getUpdateTime());
user.put("userRoleNames", loginToken.getLoginRoleNames());
String roleNames = loginToken.getLoginRoleNames();
int roles = 0;
if(!StringUtils.isEmpty(roleNames)){
roles = roleNames.split(",").length;
}
user.put("roles", roles);
user.put("messages", 0); //TODO
user.put("notices", 0); //TODO
return genSuccessResult(user);
}

}
4 changes: 3 additions & 1 deletion xproject-admin/src/main/resources/spring/spring-mvc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
</context:component-scan>

<!-- mvc:annotation-driven自动注册DefaultAnnotationHandlerMapping、AnnotationMethodHandlerAdapter两个bean -->
<mvc:annotation-driven/>
<mvc:annotation-driven>

</mvc:annotation-driven>

<!-- 防表单重复提交拦截器 -->
<mvc:interceptors>
Expand Down
8 changes: 4 additions & 4 deletions xproject-admin/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@
<filter>
<filter-name>httpAccessLoggingStreamFilter</filter-name>
<filter-class>com.certusnet.xproject.common.web.filter.HttpAccessLoggingServletStreamFilter</filter-class>
<init-param>
<param-name>supportedReqContentTypes</param-name>
<param-value>application/json</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>httpAccessLoggingStreamFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 对客户端请求的静态资源如图片、JS文件等的请求交由默认的Servlet进行处理,不经过DispatcherServlet -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
Expand Down
2 changes: 1 addition & 1 deletion xproject-admin/src/main/webapp/admin/user/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ <h3 class="el-title">
<el-upload class="el-upload-plusuploader" :headers="uploadHeaders" :action="userIconUploadUrl" :data="userIconUploadParam" :show-file-list="false" :before-upload="beforeUserIconUpload" :on-remove="handleUserIconRemove" :on-success="handleUserIconUploadSuccess" :on-error="handleUploadError">
<img v-if="userEditForm.userIcon" :src="userEditForm.userIconUrl" title="点击原图片可以重新上传新图片!">
<i v-else class="el-icon-plus"></i>
<div class="el-upload__tip" slot="tip">只能上传jpg|png文件,大小不超过50kb,图片像素限100x100像素附近(长宽误差不超过10个像素),点击原图片可以重新上传新图片!</div>
<div class="el-upload__tip" slot="tip">只能上传jpg|png文件,大小不超过50kb,图片像素限90x90像素附近(长宽误差不超过10个像素),点击原图片可以重新上传新图片!</div>
</el-upload>
</el-col>
</el-form-item>
Expand Down
Loading

0 comments on commit ff3421a

Please sign in to comment.