Explorar o código

增加注册、修改密码功能

hejq %!s(int64=7) %!d(string=hai) anos
pai
achega
53b1167cff

+ 22 - 10
src/main/java/com/uas/platform/b2bManage/controller/AccountController.java

@@ -2,6 +2,7 @@ package com.uas.platform.b2bManage.controller;
 
 import com.uas.platform.b2bManage.core.support.SystemSession;
 import com.uas.platform.b2bManage.core.util.StringUtils;
+import com.uas.platform.b2bManage.model.Constant;
 import com.uas.platform.b2bManage.model.UseType;
 import com.uas.platform.b2bManage.model.User;
 import com.uas.platform.b2bManage.page.exception.IllegalOperatorException;
@@ -9,16 +10,11 @@ import com.uas.platform.b2bManage.service.UseLogService;
 import com.uas.platform.b2bManage.service.UserService;
 import com.uas.platform.b2bManage.web.BaseController;
 import com.uas.platform.core.util.AgentUtils;
-import com.uas.platform.core.util.encry.Md5Utils;
 import javassist.NotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 
-import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 
@@ -90,6 +86,7 @@ public class AccountController extends BaseController {
      */
     @RequestMapping(value = "/valid/email", method = RequestMethod.POST)
     public ModelMap validEmail(String email) {
+        email = email + Constant.EMAIL_SUFFIX;
         User user = userService.findUserByUserEmail(email);
         if (null != user) {
             throw new IllegalOperatorException("邮箱已注册");
@@ -111,19 +108,34 @@ public class AccountController extends BaseController {
     /**
      * 找回密码
      */
-    @RequestMapping(value = "/restPwd", method = RequestMethod.POST)
+    @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
     public void resetPwd(@RequestBody String email) {
         if (StringUtils.isEmpty(email)) {
             throw new IllegalOperatorException("请输入邮箱地址");
         }
+        if (email.contains("=")) {
+            email = email.replace("=", "");
+        }
+        email = email + Constant.EMAIL_SUFFIX;
         userService.sendResetPwdUrl(email);
     }
 
     /**
      * 通过链接修改密码
      */
-    @RequestMapping(value = "/restPwd", method = RequestMethod.GET)
-    public ModelMap resetPwdByUrl(String secretKey, HttpServletResponse response) throws IOException, NotFoundException {
-        return success(userService.resetPwd(secretKey,response));
+    @RequestMapping(value = "/resetPwd/url", method = RequestMethod.GET)
+    public void resetPwdByUrl(String secretKey, HttpServletResponse response) throws IOException, NotFoundException {
+        userService.resetPwd(secretKey, response);
+    }
+
+    /**
+     * 修改密码
+     *
+     * @param id 用户id
+     * @param password 密码
+     */
+    @RequestMapping(value = "/resetPassword/{id}", method = RequestMethod.POST)
+    public void resetPassword(@PathVariable("id") Long id, String password, HttpServletResponse response) throws IOException {
+        userService.resetPassword(id, password, response);
     }
 }

+ 26 - 0
src/main/java/com/uas/platform/b2bManage/model/Constant.java

@@ -11,4 +11,30 @@ public class Constant {
      * 找回密码有效期
      */
     public static final Long SECRECTTIME = Long.valueOf(2 * 60 * 60 * 1000);
+
+
+    /**
+     * 找回密码邮件模板地址
+     */
+    public static final String RESETPWD_MOULD_URL = "276896ec-e480-4c32-b6d4-a6c07c6e0d21";
+
+    /**
+     * 管理平台地址
+     */
+    public static final String MANAGEURL = "http://192.168.253.12:23396";
+
+    /**
+     * 失效链接地址
+     */
+    public static final String INVALIDURL = "/invalid";
+
+    /**
+     * 优软邮箱后缀
+     */
+    public static final String EMAIL_SUFFIX = "@usoftchina.com";
+
+    /**
+     * 重置密码地址
+     */
+    public static final String RESETPWD_URL = "/resetPassword";
 }

+ 8 - 0
src/main/java/com/uas/platform/b2bManage/service/UserService.java

@@ -70,4 +70,12 @@ public interface UserService {
      * @return
      */
     User resetPwd(String secretKey, HttpServletResponse response) throws IOException, NotFoundException;
+
+    /**
+     * 修改密码
+     *
+     * @param id 用户id
+     * @param password 密码
+     */
+    void resetPassword(Long id, String password, HttpServletResponse response) throws IOException;
 }

+ 27 - 23
src/main/java/com/uas/platform/b2bManage/service/impl/UserServiceImpl.java

@@ -9,6 +9,7 @@ import com.uas.platform.b2bManage.model.Constant;
 import com.uas.platform.b2bManage.model.SecretKeyRecord;
 import com.uas.platform.b2bManage.model.User;
 import com.uas.platform.b2bManage.service.UserService;
+import com.uas.platform.b2bManage.support.SecurityConstant;
 import com.uas.platform.b2bManage.support.StringUtil;
 import com.uas.platform.core.util.encry.Md5Utils;
 import javassist.NotFoundException;
@@ -37,21 +38,6 @@ public class UserServiceImpl implements UserService {
     @Autowired
     private MailService mailService;
 
-    /**
-     * 找回密码邮件模板地址
-     */
-    private final String RESETPWDURL = "276896ec-e480-4c32-b6d4-a6c07c6e0d21";
-
-    /**
-     * 管理平台地址
-     */
-    private final String MANAGEURL = "http://192.168.253.12:23396";
-
-    /**
-     * 失效链接地址
-     */
-    private final String INVALIDURL = "/invalid";
-
     @Autowired
     private SecretKeyRecordDao recordDao;
 
@@ -128,6 +114,7 @@ public class UserServiceImpl implements UserService {
     public User register(User user) {
         String name = user.getEmail().substring(0, user.getEmail().indexOf("@"));
         user.setPassword(Md5Utils.encode(user.getPassword(), name));
+        user.setEmail(user.getEmail() + Constant.EMAIL_SUFFIX);
         user.setName(name);
         return userDao.save(user);
     }
@@ -148,11 +135,11 @@ public class UserServiceImpl implements UserService {
         } else {
             record = recordDao.save(new SecretKeyRecord(email, StringUtil.uuid()));
         }
-        String url = MANAGEURL + "/restPwd?secretKey=" + record.getSecretKey();
+        String url = Constant.MANAGEURL + "/resetPwd/url?secretKey=" + record.getSecretKey();
         ModelMap map = new ModelMap();
         map.put("resetPwdUrl", url);
         try {
-            mailService.send(RESETPWDURL, email, map);
+            mailService.send(Constant.RESETPWD_MOULD_URL, email, map);
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -168,24 +155,41 @@ public class UserServiceImpl implements UserService {
     @Override
     public User resetPwd(String secretKey, HttpServletResponse response) throws IOException, NotFoundException {
         if (StringUtils.isEmpty(secretKey)) {
-            response.sendRedirect(INVALIDURL);
+            response.sendRedirect(Constant.INVALIDURL);
         }
         SecretKeyRecord record = recordDao.findBySecretKey(secretKey);
         if (null == record) {
-            response.sendRedirect(INVALIDURL);
+            response.sendRedirect(Constant.INVALIDURL);
         } else {
             if (System.currentTimeMillis() - record.getTime() > Constant.SECRECTTIME) {
                 recordDao.delete(record);
-                response.sendRedirect(INVALIDURL);
+                response.sendRedirect(Constant.INVALIDURL);
             } else {
-                List<User> users = userDao.findByEmail(record.getEmail());
-                if (!CollectionUtils.isEmpty(users)) {
+                List<User> users = userDao.findByEmail(record.getEmail().trim());
+                if (CollectionUtils.isEmpty(users)) {
                     throw new NotFoundException("未找到该邮箱用户信息");
                 } else {
-                    return users.get(0);
+                    SystemSession.setUser(users.get(0));
+                    recordDao.delete(record);
+                    response.sendRedirect(Constant.RESETPWD_URL);
                 }
             }
         }
         return null;
     }
+
+    /**
+     * 修改密码
+     *
+     * @param id 用户id
+     * @param password 密码
+     */
+    @Override
+    public void resetPassword(Long id, String password, HttpServletResponse response) throws IOException {
+        User user = userDao.findOne(id);
+        user.setPassword(Md5Utils.encode(password, user.getName()));
+        userDao.save(user);
+        SystemSession.clear();
+        response.sendRedirect(SecurityConstant.LOGIN_URL);
+    };
 }

+ 87 - 0
src/main/webapp/WEB-INF/views/normal/invalid.html

@@ -0,0 +1,87 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<meta name="renderer" content="webkit"> 
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="author" content="优软科技">
+<meta name="Keywords" content="优软,UAS,ERP,企业管理">
+<link href="static/img/icon/icon_32.png" rel="icon" type="image/x-icon" />
+<link rel="stylesheet" href="static/lib/bootstrap/css/bootstrap.min.css" />
+<link rel="stylesheet"
+	href="static/lib/fontawesome/css/font-awesome.min.css" />
+<link rel="stylesheet" href="static/lib/bootstrap-tour/css/bootstrap-tour.min.css" />
+<link rel="stylesheet" href="static/css/signIn.css" />
+	<link rel="stylesheet" href="static/css/common.css" />
+<link rel="stylesheet" href="static/css/404.css" />
+<title>链接已失效-优软云</title>
+</head>
+<body>
+	<!-- nav start -->
+	<nav id="nav" class="navbar navbar-inverse navbar-fixed-top">
+		<div class="container">
+			<div class="navbar-header">
+				<a href="http://www.ubtob.com" id="logo"><img src="static/img/logo.png" alt="" height="25px" /></a>
+			</div>
+			<div class="collapse navbar-collapse">
+				<div class="nav navbar-nav navbar-left">
+					<span>B2B商务平台后台管理</span>
+				</div>
+			</div>
+		</div>
+	</nav>
+	<!-- nav end -->
+	
+	<!-- section notFound -->
+	<section id="notFound">
+		<div class="container text-center">
+			<h4>链接已失效,您可以点击<a href="sigIn">重新发送</a>!</h4>
+		</div>
+	</section>
+
+	<!-- footer start -->
+	<footer>
+		<div class="container">
+			<div class="row">
+				<div class="col-sm-3 col-sm-offset-2">
+					<div class="qrcode qrcode-uu">
+						<div class="qrcode-img pull-left">
+							<img src="static/img/qrcode/uu.png" width="100px" height="100px"
+								alt="UU互联" />
+						</div>
+						<div class="qrcode-text pull-left">
+							<div>手机UU</div>
+							<div>快人一步</div>
+						</div>
+						<div class="clearfix"></div>
+					</div>
+				</div>
+				<div class="col-sm-3">
+					<div class="qrcode qrcode-uas">
+						<div class="qrcode-img pull-left">
+							<img src="static/img/qrcode/uas.png" width="100px" height="100px"
+								alt="优软公众号" />
+						</div>
+						<div class="qrcode-text pull-left">
+							<div>微信扫描</div>
+							<div>关注公众号</div>
+						</div>
+						<div class="clearfix"></div>
+					</div>
+				</div>
+				<div class="col-sm-4">
+					<p>
+						<a href="">关于优软</a><a href="">联系我们</a><a href="">帮助</a>
+					</p>
+					<p>©2016 深圳市优软科技有限公司</p>
+					<p>粤ICP备15112126号-2</p>
+				</div>
+			</div>
+		</div>
+	</footer>
+	<!-- footer end -->
+</body>
+<script type="text/javascript" src="static/lib/jquery/jquery.min.js"></script>
+<script type="text/javascript" src="static/js/common/common.js"></script>
+</html>

+ 73 - 0
src/main/webapp/WEB-INF/views/normal/resetPassword.html

@@ -0,0 +1,73 @@
+<!DOCTYPE html>
+<html>
+<head>
+    <meta charset="utf-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="renderer" content="webkit">
+    <meta http-equiv="Content-Language" Content="zh-CN">
+    <meta name="viewport" content="width=device-width, initial-scale=1">
+    <meta name="author" content="优软科技">
+    <meta name="Keywords" content="优软,优软云,优企云服,SAAS,UAS,ERP,企业管理">
+    <meta name="baidu-site-verification" content="tamBdrxeYx" />
+    <link href="static/img/icon/icon_32.png" rel="icon" type="image/x-icon" />
+    <link rel="stylesheet" href="static/lib/bootstrap/css/bootstrap.min.css" />
+    <link rel="stylesheet"
+          href="static/lib/fontawesome/css/font-awesome.min.css" />
+    <link rel="stylesheet" href="static/lib/bootstrap-tour/css/bootstrap-tour.min.css" />
+    <link rel="stylesheet" href="static/css/common.css" />
+    <link rel="stylesheet" href="static/css/signIn.css" />
+    <title>修改密码</title>
+</head>
+<body>
+<!-- nav start -->
+<nav id="nav" class="navbar navbar-inverse navbar-fixed-top">
+    <div class="container">
+        <div class="navbar-header">
+            <a href="http://www.ubtob.com" id="logo"><img src="static/img/logo.png" alt="" height="25px" /></a>
+        </div>
+        <div class="collapse navbar-collapse">
+            <div class="nav navbar-nav navbar-left">
+                <span>B2B商务平台后台管理</span>
+            </div>
+        </div>
+    </div>
+</nav>
+<!-- nav end -->
+
+<!-- section start -->
+<section>
+    <div class="container">
+        <div class="section-title">
+            <h3>修改密码</h3>
+        </div>
+        <div class="section-choose show">
+            <form action="">
+                <div class="form-group">
+                    <input id="re_name" type="text" class="form-control" readonly/>
+                </div>
+                <div class="form-group">
+                    <input id="re_email" type="text" class="form-control" readonly/>
+                </div>
+                <div class="form-group">
+                    <input id="re_tel" type="text" class="form-control" readonly/>
+                </div>
+                <div class="form-group">
+                    <input id="re_pwd" type="password" class="form-control" placeholder="请输入密码" />
+                </div>
+                <div class="form-group">
+                    <input id="re_confirmPwd" type="password" class="form-control" placeholder="请确认密码" />
+                </div>
+                <div class="form-group">
+                    <a class="btn" id="link-reset" type="submit">确定</a>
+                </div>
+            </form>
+        </div>
+    </div>
+</section>
+</body>
+<script type="text/javascript" src="static/lib/jquery/jquery.min.js"></script>
+<script type="text/javascript" src="static/lib/bootstrap/js/bootstrap.min.js"></script>
+<script type="text/javascript" src="static/lib/bootstrap-tour/js/bootstrap-tour.min.js"></script>
+<script type="text/javascript" src="static/js/account/resetPassword.js"></script>
+<script type="text/javascript" src="static/js/index/app.js"></script>
+</html>

+ 44 - 10
src/main/webapp/WEB-INF/views/normal/signIn.html

@@ -15,7 +15,7 @@
 		  href="static/lib/fontawesome/css/font-awesome.min.css" />
 	<link rel="stylesheet" href="static/lib/bootstrap-tour/css/bootstrap-tour.min.css" />
 	<link rel="stylesheet" href="static/css/common.css" />
-	<link rel="stylesheet" href="static/css/setHrAccount.css" />
+	<link rel="stylesheet" href="static/css/signIn.css" />
 	<title>登录界面</title>
 </head>
 <body>
@@ -70,14 +70,42 @@
 				</span>
 			</div>
 			<div class="modal-body">
-                <span>电子邮箱</span><input type="text" id="u_email" placeholder="请填写优软企业邮箱" required="required">
-                <span>手机号</span><input id="u_tel" placeholder="请填写手机号" required="required">
-                <span>姓名</span><input id="u_name" placeholder="请填写姓名">
-                <span>密码</span><input id="u_pwd" type="password" required="required">
-                <span>确认密码</span><input id="u_confirmPwd" type="password" required="required">
-				<span>验证码 <input type="text" id = "captcha"/>
-					<input type="button" id="code" onclick="createCode()" style="width:60px" title='点击更换验证码' readonly/>
-				</span>
+                <div>
+                    <div class="col-xs-3">电子邮箱</div>
+                    <div class="col-xs-8">
+                        <input type="text" id="u_email" placeholder="请填写优软企业邮箱" required="required">
+                        <span>@usoftchina.com</span>
+                    </div>
+                </div>
+                <div>
+                    <div class="col-xs-3">手机号</div>
+                    <div class="col-xs-8">
+                        <input id="u_tel" placeholder="请填写手机号" required="required">
+                    </div>
+                </div>
+                <div>
+                    <div class="col-xs-3">姓名</div>
+                    <div class="col-xs-8">
+                        <input id="u_name" placeholder="请填写姓名">
+                    </div>
+                </div>
+                <div>
+                    <div class="col-xs-3">密码</div>
+                    <div class="col-xs-8">
+                        <input id="u_pwd" type="password" required="required" placeholder="请填写密码">
+                    </div>
+                </div>
+                <div>
+                    <div class="col-xs-3">确认密码</div>
+                    <div class="col-xs-8">
+                        <input id="u_confirmPwd" type="password" required="required" placeholder="请确认密码">
+                    </div>
+                </div>
+                <div>
+                    <div class="col-xs-3">验证码 </div>
+                    <div class="col-xs-4"> <input type="text" id = "captcha" placeholder="请输入验证码"/></div>
+                    <div class="col-xs-4"> <input type="button" id="code" onclick="createCode()" style="width:60px" title='点击更换验证码' readonly/></div>
+                </div>
 			</div>
 			<div class="modal-footer">
 				<a type="button" class="btn btn-default" data-dismiss="modal">
@@ -103,7 +131,13 @@
 				</span>
             </div>
             <div class="modal-body">
-                <span>电子邮箱</span><input id="p_email">
+                <div>
+                    <div class="col-xs-3">电子邮箱</div>
+                    <div class="col-xs-8">
+                        <input type="text" id="p_email" placeholder="请填写优软企业邮箱" required="required">
+                        <span>@usoftchina.com</span>
+                    </div>
+                </div>
             </div>
             <div class="modal-footer">
                 <a type="button" class="btn btn-default" data-dismiss="modal">

+ 4 - 1
src/main/webapp/WEB-INF/webmvc.xml

@@ -48,6 +48,8 @@
 	<mvc:view-controller path="/index" view-name="index" />
 	<mvc:view-controller path="/signIn" view-name="signIn" />
 	<mvc:view-controller path="/enterprise" view-name="enterprise" />
+	<mvc:view-controller path="/resetPassword" view-name="resetPassword" />
+    <mvc:view-controller path="/invalid" view-name="invalid" />
     <mvc:view-controller path="/**#" view-name="signIn" />
 	<mvc:interceptors>
 		<!-- SSO过滤 -->
@@ -61,7 +63,8 @@
             <mvc:exclude-mapping path="/**/img/**"/>
 			<mvc:exclude-mapping path="/**/register/**"/>
 			<mvc:exclude-mapping path="/**/valid/**"/>
-			<mvc:exclude-mapping path="/**/restPwd/**"/>
+            <mvc:exclude-mapping path="/**/resetPwd/**"/>
+            <mvc:exclude-mapping path="/**/*invalid*"/>
 			<bean class="com.uas.platform.b2bManage.web.filter.SSOInterceptor"></bean>
 		</mvc:interceptor>
 	</mvc:interceptors>

+ 15 - 9
src/main/webapp/resources/css/setHrAccount.css → src/main/webapp/resources/css/signIn.css

@@ -152,15 +152,6 @@ section .container{
 .section-choose .form-group ul li span.phone{
 	margin: 0 20px;
 }
-/*点击切换*/
-.section-choose{
-	display: none;
-}
-.show{
-	display: block;
-}
-/*section end*/
-
 
 #toast-container {
     margin: 0 auto;
@@ -174,4 +165,19 @@ section .container{
 #toast-container .toast-message {
     font-size: 16px;
     color: #fff;
+}
+
+#registerModal .modal-body {
+    height: 275px;
+}
+#registerModal .modal-body div {
+    margin-top: 10px;
+}
+
+#registerModal .modal-body #code {
+    background-color: #f7f7f7;
+}
+
+#forgetPwd .modal-body {
+    height: 60px;
 }

+ 82 - 0
src/main/webapp/resources/js/account/resetPassword.js

@@ -0,0 +1,82 @@
+/**
+ * 引入base方法
+ */
+document.write("<script language=javascript src='static/js/common/base.js'></script>");
+
+/**
+ *  获取用户信息
+ */
+var user = null;
+function getAccountInfo() {
+    $.get('/account', function(data) {
+        if (data.content) {
+            window.loginInfo = data;
+            user = data.content;
+            $('#re_email').val(user.email);
+            $('#re_tel').val(user.tel);
+            $('#re_name').val(user.name);
+        } else {
+            window.location.href = "/signIn";
+        }
+    });
+}
+
+/**
+ * 重置密码
+ */
+function resetPassWord() {
+    if (checkUserInfo()) {
+        var userInfo = {password: $('#re_pwd').val()};
+        $.ajax('resetPassword/' + user.id, {
+            data: userInfo,
+            method: 'POST',
+            async: false,
+            success: function() {
+                alert('密码修改成功');
+                window.location.href = "/signIn";
+            },
+            error: function (error) {
+                alert('密码修改失败');
+            }
+        });
+    }
+}
+/**
+ * 检验信息
+ */
+function checkUserInfo() {
+    var result = true;
+    if (isEmpty($('#re_pwd').val())) {
+        alert("密码不能为空");
+        result = false;
+    }
+    if (result && isEmpty($('#re_confirmPwd').val())) {
+        alert("请确认密码");
+        result = false;
+    }
+    if (result && ($('#re_pwd').val() != $('#re_confirmPwd').val())) {
+        alert("两次密码不一致");
+        result = false;
+    }
+    return result;
+}
+
+
+$(function() {
+    'use strict';
+
+    // 监听页面滚动
+    $(window).scroll(function() {
+        if($(window).scrollTop() >= 400) {
+            $('#nav').addClass('on');
+        } else {
+            $('#nav').removeClass('on');
+        }
+    });
+
+    // 查询登录信息
+    getAccountInfo();
+
+    // 重置密码
+    $('#link-reset').click(resetPassWord);
+});

+ 35 - 6
src/main/webapp/resources/js/account/signIn.js

@@ -72,10 +72,36 @@ function checkInfo() {
         alert("邮箱不能为空");
         return;
     }
-    if ($('#u_email').val().indexOf('@usoftchina.com') < 0) {
-        alert("请填写优软企业邮箱");
+    if ($('#u_email').val().indexOf('@usoftchina.com') > 0) {
+        alert("只填邮箱前缀");
         return;
     }
+    if (!isEmpty($('#u_email').val())) {
+        $.ajax('valid/email', {
+            data: $('#u_email').val(),
+            method: 'POST',
+            async: false,
+            success: function() {
+            },
+            error: function (error) {
+                alert(error);
+                return;
+            }
+        });
+    }
+    if (!isEmpty($('#u_tel').val())) {
+        $.ajax('valid/tel', {
+            data: $('#u_tel').val(),
+            method: 'POST',
+            async: false,
+            success: function() {
+            },
+            error: function (error) {
+                alert(error);
+                return;
+            }
+        });
+    }
     if (isEmpty($('#u_pwd').val())) {
         alert("密码不能为空");
         return;
@@ -128,15 +154,18 @@ function validate() {
  * 重置密码
  */
 function resetPwd() {
-    $.ajax('restPwd', {
-        data: $('#p_email').val(),
+    var email = $('#p_email').val();
+    $.ajax('resetPwd', {
+        data: email,
         method: 'POST',
         async: false,
         success: function() {
-            window.location.href = "/signIn";
+            var email = $('#p_email').val() + "@usoftchina.com";
+            alert('邮件已发送到' + email + ',请注已查收');
+            $('#forgetPwd').modal('hide');
         },
         error: function (error) {
-            alert('注册失败');
+            alert('邮件发送失败,请重新填写');
         }
     });
 }