Authored by zhengyouwei

密码修改

... ... @@ -13,11 +13,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
... ... @@ -47,17 +49,17 @@ public class ManagerCtrl {
@ResponseBody
public BaseResponse saveUser(@RequestBody User user) {
BaseResponse baseResponse = null;
if(user.getId() < 1){//add
if(userAuthLocal.getUserByname(user.getName()) != null){
return new BaseResponse(201,"用户已经存在");
if (user.getId() < 1) {//add
if (userAuthLocal.getUserByname(user.getName()) != null) {
return new BaseResponse(201, "用户已经存在");
}
user.setPwd(MD5Util.encryption(user.getPwd()));
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_INSERT,user,BaseResponse.class);
}else{
if("admin".equals(user.getName())){
return new BaseResponse(201,"此用户无法修改");
user.setPwd(MD5Util.encryption("123456"));
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_INSERT, user, BaseResponse.class);
} else {
if ("admin".equals(user.getName())) {
return new BaseResponse(201, "此用户无法修改");
}
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_UPDATE,user,BaseResponse.class);
baseResponse = httpRestClient.defaultPost(HttpUriContants.USER_UPDATE, user, BaseResponse.class);
}
userAuthLocal.flushUser(user.getName());
... ... @@ -75,7 +77,7 @@ public class ManagerCtrl {
@ResponseBody
public BaseResponse deleteUser(String name) {
Map map = new HashMap<>();
map.put("name",name);
map.put("name", name);
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.USER_DELETE_NAME, BaseResponse.class, map);
userAuthLocal.flushUser(name);
return response;
... ... @@ -85,13 +87,13 @@ public class ManagerCtrl {
@ResponseBody
public BaseResponse saveAuthModule(@RequestBody AuthModule authModule) {
BaseResponse baseResponse = null;
if(authModule.getId() < 1){//add
if(userAuthLocal.getAuthModuleByname(authModule.getModuleName()) != null){
return new BaseResponse(201,"模块已经存在");
if (authModule.getId() < 1) {//add
if (userAuthLocal.getAuthModuleByname(authModule.getModuleName()) != null) {
return new BaseResponse(201, "模块已经存在");
}
baseResponse = httpRestClient.defaultPost(HttpUriContants.MODULE_INSERT,authModule,BaseResponse.class);
}else{
baseResponse = httpRestClient.defaultPost(HttpUriContants.MODULE_UPDATE,authModule,BaseResponse.class);
baseResponse = httpRestClient.defaultPost(HttpUriContants.MODULE_INSERT, authModule, BaseResponse.class);
} else {
baseResponse = httpRestClient.defaultPost(HttpUriContants.MODULE_UPDATE, authModule, BaseResponse.class);
}
userAuthLocal.flushModule(authModule.getModuleName());
... ... @@ -108,11 +110,11 @@ public class ManagerCtrl {
@RequestMapping("/deleteAuthModule")
@ResponseBody
public BaseResponse deleteAuthModule(String name) {
if("manage".equals(name)){
return new BaseResponse(201,"此模块无法delete");
if ("manage".equals(name)) {
return new BaseResponse(201, "此模块无法delete");
}
Map map = new HashMap<>();
map.put("name",name);
map.put("name", name);
BaseResponse response = httpRestClient.defaultGet(HttpUriContants.MODULE_DELETE_NAME, BaseResponse.class, map);
userAuthLocal.flushModule(name);
return response;
... ...
... ... @@ -3,7 +3,9 @@ package com.ui.ctrl;
import com.ui.User.MD5Util;
import com.ui.User.UserAuthLocal;
import com.ui.contants.HttpUriContants;
import com.ui.http.HttpRestClient;
import com.ui.model.BaseResponse;
import com.ui.model.req.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -41,6 +43,9 @@ public class UserCtrl {
}
if (u.getPwd().equals(MD5Util.encryption(user.getPwd()))) {
session.setAttribute("user", user.getName());
if("123456".equals(user.getPwd())){
return new ModelAndView("user/modifypwd");
}
return new ModelAndView("dashBoard/dashBoard");
} else {
model.addAttribute("message", "密码错误");
... ... @@ -55,5 +60,39 @@ public class UserCtrl {
return new ModelAndView("user/login");
}
@RequestMapping("/updatePwd")
public ModelAndView updatePwd(String name, String oldpwd, String newpwd, HttpSession session, Model model) {
Object obj = session.getAttribute("user");
String username = String.valueOf(obj);
if ("admin".equals(username)) {
User user = userAuthLocal.getUserByname(username);
if (user == null) {
model.addAttribute("message", "当前用户不存在");
return new ModelAndView("user/modifypwd");
}
user.setPwd(MD5Util.encryption(newpwd));
httpRestClient.defaultPost(HttpUriContants.USER_UPDATE_PWD, user, BaseResponse.class);
userAuthLocal.flushUser(name);
return new ModelAndView("dashboard/toDashboard");
} else if (name.equals(username)) {
User user = userAuthLocal.getUserByname(username);
if (!user.getPwd().equals(MD5Util.encryption(oldpwd))) {
model.addAttribute("message", "旧密码错误");
return new ModelAndView("user/modifypwd");
}
user.setPwd(MD5Util.encryption(newpwd));
httpRestClient.defaultPost(HttpUriContants.USER_UPDATE_PWD, user, BaseResponse.class);
session.removeAttribute("user");
userAuthLocal.flushUser(name);
return new ModelAndView("user/login");
} else {
model.addAttribute("message", "无权限修改当前账户");
return new ModelAndView("user/modifypwd");
}
}
}
... ...
... ... @@ -103,14 +103,6 @@
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>密码:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="pwd" name="pwd"
placeholder="密码" maxlength="30" size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>等级:</label>
<div class="col-sm-8">
... ... @@ -205,11 +197,9 @@
if (id == 0) {//新增页面
$("input[name='id']").val(0);
$("input[name='name']").val("");
$("input[name='pwd']").val("");
$("input[name='level']").val("");
$("input[name='email']").val("");
$("input[name='mobile']").val("");
$("input[name='pwd']").show();
$("input[name='name']").removeAttr("readonly");
$("#myModalLabel").text("新增用户信息");
} else {
... ... @@ -220,7 +210,6 @@
$("input[name='level']").val(level);
$("input[name='email']").val(email);
$("input[name='mobile']").val(maobile);
$("input[name='pwd']").hide();
}
$("#myModal").modal('show');
... ... @@ -268,7 +257,6 @@
function saveuser() {
var id = $("input[name='id']").val();
var name = $("input[name='name']").val();
var pwd = $("input[name='pwd']").val();
var level = $("input[name='level']").val();
var email = $("input[name='email']").val();
var mobile = $("input[name='mobile']").val();
... ... @@ -279,15 +267,6 @@
});
return;
}
if(id == 0){
if (pwd == null || pwd == "") {
$("#hostGroupForm #messageAlert").alerts({
content: "请输入密码",
type: "danger"
});
return;
}
}
if (level == null || level == "") {
$("#hostGroupForm #messageAlert").alerts({
content: "请输入等级",
... ... @@ -301,7 +280,6 @@
level: level,
email: email,
mobile: mobile,
pwd: pwd
}
$.ajax({
url: contextPath + 'manage/saveUser',
... ...
<%@page language="java" contentType="text/html;charset=utf-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
<link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/uniform.css"/>
<link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
<script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>/js/bootstrap.min.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jstree/jstree.min.js"></script>
<script src="<%=basePath %>js/jquery.toaster.js"></script>
<script>
var contextPath = '<%=basePath %>';
</script>
<title>YOHO!运维</title>
</head>
<body>
<!-- 头部 -->
<div id="head">
</div>
<!-- 右侧具体内容 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">&times;</button>
<h4 class="modal-title" id="myModalLabel"></h4>
</div>
<div class="modal-body">
<form id="hostGroupForm" class="form-horizontal" action="<%=basePath %>/user/updatePwd" method="post" onsubmit="return saveuser();">
<input type="hidden" name="id">
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>用户名:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="name" name="name"
placeholder="用户名" maxlength="30" size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>老密码:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="oldpwd" name="oldpwd"
placeholder="old pwd" maxlength="30" size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> <span style="color:red">*</span>新密码:</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="newpwd" name="newpwd"
placeholder="new pwd" maxlength="30" size="40"/>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label"> </label>
<div class="col-sm-8" id="messageAlert">
${message}
</div>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-success" value="提交"></input>
</div>
</form>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
<script type="text/javascript">
jQuery(document).ready(function () {
$("#myModalLabel").text("修改用户密码");
$("#myModal").modal('show');
});
function saveuser() {
var name = $("input[name='name']").val();
var oldpwd = $("input[name='oldpwd']").val();
var newpwd = $("input[name='newpwd']").val();
if (name == null || name == "") {
$("#hostGroupForm #messageAlert").alerts({
content: "请输入用户名",
type: "danger"
});
return false;
}
if (oldpwd == null || oldpwd == "") {
$("#hostGroupForm #messageAlert").alerts({
content: "请输入旧密码",
type: "danger"
});
return false;
}
if (newpwd == null || newpwd == "") {
$("#hostGroupForm #messageAlert").alerts({
content: "请输入新密码",
type: "danger"
});
return false;
}
return true;
}
</script>
</body>
</html>
... ...