瀏覽代碼

新增功能

hejq 7 年之前
父節點
當前提交
0b22d1af20

+ 27 - 0
pom.xml

@@ -166,6 +166,33 @@
             <groupId>org.springframework.data</groupId>
             <artifactId>spring-data-redis</artifactId>
             <version>1.6.0.RELEASE</version>
+        </dependency>
+
+		<!-- 邮件 -->
+		<dependency>
+			<groupId>com.uas.message</groupId>
+			<artifactId>message-mail-api</artifactId>
+            <version>0.0.1</version>
+		</dependency>
+
+        <!-- dubbo -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>dubbo</artifactId>
+            <exclusions>
+                <exclusion>
+                    <groupId>javax.servlet</groupId>
+                    <artifactId>javax.servlet-api</artifactId>
+                </exclusion>
+                <exclusion>
+                    <groupId>org.apache.httpcomponents</groupId>
+                    <artifactId>httpcore</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <dependency>
+            <groupId>com.github.sgroschupf</groupId>
+            <artifactId>zkclient</artifactId>
         </dependency>
     </dependencies>
 	<build>

+ 68 - 2
src/main/java/com/uas/platform/b2bManage/controller/AccountController.java

@@ -1,19 +1,25 @@
 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.UseType;
+import com.uas.platform.b2bManage.model.User;
+import com.uas.platform.b2bManage.page.exception.IllegalOperatorException;
 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 javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 
 /**
@@ -43,7 +49,7 @@ public class AccountController extends BaseController {
 	 *
 	 */
 	@RequestMapping(value = "/login", method = RequestMethod.POST)
-	public void login(String userName, String passWord, HttpServletRequest request) throws IllegalAccessException {
+	public void login(String userName, String passWord) throws IllegalAccessException {
         userService.login(userName.trim(), passWord.trim(), request);
         useLogService.appendLog(UseType.LOGIN.code(), null, AgentUtils.getIp(request));
 	}
@@ -54,10 +60,70 @@ public class AccountController extends BaseController {
 	 * @throws IOException
 	 */
 	@RequestMapping(value = "/logout", method = RequestMethod.POST)
-	public ModelMap logout(HttpServletRequest request) throws IOException {
+	public ModelMap logout() throws IOException {
 		SystemSession.clear();
 		request.getSession().removeAttribute("user");
+        useLogService.appendLog(UseType.LOGOUT.code(), null, AgentUtils.getIp(request));
 		return success();
 	}
 
+    /**
+     * 检验手机号
+     *
+     * @param tel 手机号码
+     * @return
+     */
+	@RequestMapping(value = "/valid/tel", method = RequestMethod.POST)
+    public ModelMap validTel(String tel) {
+	    User user = userService.findByTel(tel);
+	    if (null != user) {
+            throw new IllegalOperatorException("手机已注册");
+        }
+        return success();
+    }
+
+    /**
+     * 检验邮箱
+     *
+     * @param email 邮箱
+     * @return
+     */
+    @RequestMapping(value = "/valid/email", method = RequestMethod.POST)
+    public ModelMap validEmail(String email) {
+        User user = userService.findUserByUserEmail(email);
+        if (null != user) {
+            throw new IllegalOperatorException("邮箱已注册");
+        }
+        return success();
+    }
+
+    /**
+     * 注册
+     *
+     * @param user 用户信息
+     * @return
+     */
+    @RequestMapping(value = "/register", method = RequestMethod.POST)
+    public ModelMap register(User user) {
+        return success(userService.register(user));
+    }
+
+    /**
+     * 找回密码
+     */
+    @RequestMapping(value = "/restPwd", method = RequestMethod.POST)
+    public void resetPwd(@RequestBody String email) {
+        if (StringUtils.isEmpty(email)) {
+            throw new IllegalOperatorException("请输入邮箱地址");
+        }
+        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));
+    }
 }

+ 30 - 0
src/main/java/com/uas/platform/b2bManage/dao/SecretKeyRecordDao.java

@@ -0,0 +1,30 @@
+package com.uas.platform.b2bManage.dao;
+
+import com.uas.platform.b2bManage.model.SecretKeyRecord;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.stereotype.Repository;
+
+/**
+ * 秘钥记录
+ *
+ * Created by hejq on 2018-04-27.
+ */
+@Repository
+public interface SecretKeyRecordDao extends JpaRepository<SecretKeyRecord, Long> {
+
+    /**
+     * 通过秘钥查询相关信息
+     *
+     * @param secretKey
+     * @return
+     */
+    SecretKeyRecord findBySecretKey(String secretKey);
+
+    /**
+     * 通过邮箱查询时间
+     *
+     * @param email 邮箱
+     * @return
+     */
+    SecretKeyRecord findByEmail(String email);
+}

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

@@ -0,0 +1,14 @@
+package com.uas.platform.b2bManage.model;
+
+/**
+ * 常量
+ *
+ * Created by hejq on 2018-04-27.
+ */
+public class Constant {
+
+    /**
+     * 找回密码有效期
+     */
+    public static final Long SECRECTTIME = Long.valueOf(2 * 60 * 60 * 1000);
+}

+ 104 - 0
src/main/java/com/uas/platform/b2bManage/model/SecretKeyRecord.java

@@ -0,0 +1,104 @@
+package com.uas.platform.b2bManage.model;
+
+import com.uas.platform.b2bManage.core.support.SystemSession;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * 生成秘钥记录
+ *
+ * Created by hejq on 2018-04-27.
+ */
+@Table(name = "secretkey")
+@Entity
+public class SecretKeyRecord implements Serializable {
+
+    /**
+     * 序列号
+     */
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * id
+     */
+    @Id
+    @Column(name = "id")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "secretkey_gen")
+    @SequenceGenerator(name = "secretkey_gen", sequenceName = "secretkey_seq", allocationSize = 1)
+    private Long id;
+
+    /**
+     * 邮箱
+     */
+    @Column(name = "email")
+    private String email;
+
+    /**
+     * 是否可用 1.yes 0.no
+     */
+    @Column(name = "enable")
+    private Short enable;
+
+    /**
+     * 秘钥
+     */
+    @Column(name = "secretkey")
+    private String secretKey;
+
+    /**
+     * 生成时间
+     */
+    @Column(name = "time")
+    private Long time;
+
+    public SecretKeyRecord(String email, String secretKey) {
+        this.email = email;
+        this.secretKey = secretKey;
+        this.time = System.currentTimeMillis();
+    }
+
+    public SecretKeyRecord() {
+    }
+
+    public Long getId() {
+        return id;
+    }
+
+    public void setId(Long id) {
+        this.id = id;
+    }
+
+    public String getEmail() {
+        return email;
+    }
+
+    public void setEmail(String email) {
+        this.email = email;
+    }
+
+    public Short getEnable() {
+        return enable;
+    }
+
+    public void setEnable(Short enable) {
+        this.enable = enable;
+    }
+
+    public String getSecretKey() {
+        return secretKey;
+    }
+
+    public void setSecretKey(String secretKey) {
+        this.secretKey = secretKey;
+    }
+
+    public Long getTime() {
+        return time;
+    }
+
+    public void setTime(Long time) {
+        this.time = time;
+    }
+}

+ 10 - 0
src/main/java/com/uas/platform/b2bManage/model/UseType.java

@@ -12,6 +12,16 @@ public enum UseType {
      */
     LOGIN("登录"),
 
+    /**
+     * 退出
+     */
+    LOGOUT("退出"),
+
+    /**
+     * 注册
+     */
+    REGISTER("注册"),
+
     /**
      * 搜索
      */

+ 3 - 18
src/main/java/com/uas/platform/b2bManage/model/User.java

@@ -1,9 +1,6 @@
 package com.uas.platform.b2bManage.model;
 
-import javax.persistence.Column;
-import javax.persistence.Entity;
-import javax.persistence.Id;
-import javax.persistence.Table;
+import javax.persistence.*;
 import java.io.Serializable;
 
 /**
@@ -23,6 +20,8 @@ public class User implements Serializable {
      */
     @Id
     @Column(name = "id")
+    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "users_gen")
+    @SequenceGenerator(name = "users_gen", sequenceName = "users_seq", allocationSize = 1)
     private Long id;
 
     /**
@@ -130,18 +129,4 @@ public class User implements Serializable {
     public void setRole(String role) {
         this.role = role;
     }
-
-    @Override
-    public String toString() {
-        return "User{" +
-                "id=" + id +
-                ", email='" + email + '\'' +
-                ", enable=" + enable +
-                ", name='" + name + '\'' +
-                ", password='" + password + '\'' +
-                ", tel='" + tel + '\'' +
-                ", fullName='" + fullName + '\'' +
-                ", role='" + role + '\'' +
-                '}';
-    }
 }

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

@@ -1,8 +1,12 @@
 package com.uas.platform.b2bManage.service;
 
 import com.uas.platform.b2bManage.model.User;
+import javassist.NotFoundException;
+import org.springframework.ui.ModelMap;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 
 /**
  * 用户接口
@@ -42,4 +46,28 @@ public interface UserService {
      * @param passWord 密码
      */
     void login(String userName, String passWord, HttpServletRequest request) throws IllegalAccessException;
+
+    /**
+     * 注册用户
+     *
+     * @param user 用户信息
+     * @return
+     */
+    User register(User user);
+
+    /**
+     * 根据填写邮箱发送修改密码链接
+     *
+     * @param email 邮箱
+     */
+    void sendResetPwdUrl(String email);
+
+    /**
+     * 通过访问链接修改密码
+     *
+     * @param secretKey 秘钥
+     * @param response 请求
+     * @return
+     */
+    User resetPwd(String secretKey, HttpServletResponse response) throws IOException, NotFoundException;
 }

+ 103 - 0
src/main/java/com/uas/platform/b2bManage/service/impl/UserServiceImpl.java

@@ -1,16 +1,26 @@
 package com.uas.platform.b2bManage.service.impl;
 
+import com.uas.message.mail.service.MailService;
 import com.uas.platform.b2bManage.core.support.SystemSession;
+import com.uas.platform.b2bManage.core.util.StringUtils;
+import com.uas.platform.b2bManage.dao.SecretKeyRecordDao;
 import com.uas.platform.b2bManage.dao.UserDao;
+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.StringUtil;
 import com.uas.platform.core.util.encry.Md5Utils;
+import javassist.NotFoundException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 import org.springframework.stereotype.Service;
+import org.springframework.ui.ModelMap;
 import org.springframework.util.CollectionUtils;
 
 import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.util.List;
 
 /**
@@ -23,6 +33,28 @@ public class UserServiceImpl implements UserService {
 
     @Autowired
     private UserDao userDao;
+
+    @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;
+
     /**
      * 通过电话号码查询用户信息
      *
@@ -85,4 +117,75 @@ public class UserServiceImpl implements UserService {
             throw new IllegalAccessException("账号或密码错误");
         }
     }
+
+    /**
+     * 注册用户
+     *
+     * @param user 用户信息
+     * @return
+     */
+    @Override
+    public User register(User user) {
+        String name = user.getEmail().substring(0, user.getEmail().indexOf("@"));
+        user.setPassword(Md5Utils.encode(user.getPassword(), name));
+        user.setName(name);
+        return userDao.save(user);
+    }
+
+    /**
+     * 根据填写邮箱发送修改密码链接
+     *
+     * @param email 邮箱
+     */
+    @Override
+    public void sendResetPwdUrl(String email) {
+        SecretKeyRecord record = recordDao.findByEmail(email);
+        if (null != record) {
+            if (System.currentTimeMillis() - record.getTime() > Constant.SECRECTTIME) {
+                recordDao.delete(record);
+                record = recordDao.save(new SecretKeyRecord(email, StringUtil.uuid()));
+            }
+        } else {
+            record = recordDao.save(new SecretKeyRecord(email, StringUtil.uuid()));
+        }
+        String url = MANAGEURL + "/restPwd?secretKey=" + record.getSecretKey();
+        ModelMap map = new ModelMap();
+        map.put("resetPwdUrl", url);
+        try {
+            mailService.send(RESETPWDURL, email, map);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 通过访问链接修改密码
+     *
+     * @param secretKey 秘钥
+     * @param response  请求
+     * @return
+     */
+    @Override
+    public User resetPwd(String secretKey, HttpServletResponse response) throws IOException, NotFoundException {
+        if (StringUtils.isEmpty(secretKey)) {
+            response.sendRedirect(INVALIDURL);
+        }
+        SecretKeyRecord record = recordDao.findBySecretKey(secretKey);
+        if (null == record) {
+            response.sendRedirect(INVALIDURL);
+        } else {
+            if (System.currentTimeMillis() - record.getTime() > Constant.SECRECTTIME) {
+                recordDao.delete(record);
+                response.sendRedirect(INVALIDURL);
+            } else {
+                List<User> users = userDao.findByEmail(record.getEmail());
+                if (!CollectionUtils.isEmpty(users)) {
+                    throw new NotFoundException("未找到该邮箱用户信息");
+                } else {
+                    return users.get(0);
+                }
+            }
+        }
+        return null;
+    }
 }

+ 34 - 0
src/main/java/com/uas/platform/b2bManage/support/StringUtil.java

@@ -0,0 +1,34 @@
+package com.uas.platform.b2bManage.support;
+
+import java.util.Random;
+import java.util.UUID;
+
+public class StringUtil {
+
+	/**
+	 * 产生唯一字符串
+	 * 
+	 * @return
+	 */
+	public static String uuid() {
+		return UUID.randomUUID().toString().replaceAll("\\-", "");
+	}
+
+	public static String substr(String str, int begin, int end) {
+		return str.substring(begin, Math.min(str.length(), end));
+	}
+
+	/**
+	 * 随机数字
+	 * 
+	 * @param len
+	 *            数字长度
+	 * @return
+	 */
+	public static String getRandomNumber(int len) {
+		int max = (int) Math.pow(10, len) - 1;
+		int min = (int) Math.pow(10, len - 1);
+		return String.valueOf(new Random().nextInt(max) % (max - min + 1) + min);
+	}
+
+}

+ 4 - 0
src/main/java/com/uas/platform/b2bManage/web/BaseController.java

@@ -3,6 +3,7 @@ package com.uas.platform.b2bManage.web;
 import java.io.IOException;
 import java.io.PrintWriter;
 
+import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
@@ -27,6 +28,9 @@ public class BaseController {
 	@Autowired
 	protected HttpServletResponse response;
 
+	@Autowired
+	protected HttpServletRequest request;
+
 	protected static ModelMap success() {
 		return new ModelMap("success", true);
 	}

+ 14 - 0
src/main/resources/spring/dubbo-consumer.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="http://www.springframework.org/schema/beans"
+	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
+	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
+	http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
+
+	<dubbo:application name="b2bManage_consumer" />
+
+	<dubbo:registry address="zookeeper://10.10.100.11:2181" check="false" />
+
+	<!-- 邮件服务 -->
+	<dubbo:reference id="mailService"
+		interface="com.uas.message.mail.service.MailService" timeout="10000" />
+</beans>

+ 60 - 1
src/main/webapp/WEB-INF/views/normal/signIn.html

@@ -49,7 +49,8 @@
 					<input id="p_pwd" type="password" class="form-control" placeholder="密码" />
 				</div>
 				<div class="form-group">
-                    <a class="reg" id="signUp">快速注册</a> <a class="forget" id="restPwd">忘记密码?</a>
+                    <a class="reg" id="signUp" data-toggle="modal" data-target="#registerModal">快速注册</a>
+					<a class="forget" id="restPwd" data-toggle="modal" data-target="#forgetPwd">忘记密码?</a>
 					<a class="btn" id="link-login" type="submit">登录</a>
 				</div>
 			</form>
@@ -57,6 +58,64 @@
 	</div>
 </section>
 <!-- section end -->
+<!-- 快速注册 -->
+<form class="modal fade" id="registerModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+	<div class="modal-dialog">
+		<div class="modal-content">
+			<div class="modal-header">
+				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
+				</button>
+				<span class="modal-title" id="myModalLabel">
+					快速注册
+				</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="modal-footer">
+				<a type="button" class="btn btn-default" data-dismiss="modal">
+					关闭
+				</a>
+				<a type="button" class="btn btn-primary" id="u_register">
+					注册
+				</a>
+			</div>
+		</div><!-- /.modal-content -->
+	</div><!-- /.modal-dialog -->
+</form>
+
+<!-- 找回密码 -->
+<div class="modal fade" id="forgetPwd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+    <div class="modal-dialog">
+        <div class="modal-content">
+            <div class="modal-header">
+                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×
+                </button>
+                <span class="modal-title" id="forgetPwdLabel">
+					找回密码
+				</span>
+            </div>
+            <div class="modal-body">
+                <span>电子邮箱</span><input id="p_email">
+            </div>
+            <div class="modal-footer">
+                <a type="button" class="btn btn-default" data-dismiss="modal">
+                    关闭
+                </a>
+                <a type="button" class="btn btn-primary" id="p_restPwd">
+                    确定
+                </a>
+            </div>
+        </div><!-- /.modal-content -->
+    </div><!-- /.modal-dialog -->
+</div>
 
 </body>
 <script type="text/javascript" src="static/lib/jquery/jquery.min.js"></script>

+ 3 - 0
src/main/webapp/WEB-INF/webmvc.xml

@@ -59,6 +59,9 @@
             <mvc:exclude-mapping path="/**/login"/>
             <mvc:exclude-mapping path="/**/logout"/>
             <mvc:exclude-mapping path="/**/img/**"/>
+			<mvc:exclude-mapping path="/**/register/**"/>
+			<mvc:exclude-mapping path="/**/valid/**"/>
+			<mvc:exclude-mapping path="/**/restPwd/**"/>
 			<bean class="com.uas.platform.b2bManage.web.filter.SSOInterceptor"></bean>
 		</mvc:interceptor>
 	</mvc:interceptors>

+ 4 - 0
src/main/webapp/resources/css/enterprise.css

@@ -215,3 +215,7 @@ tr:hover {
 #m-page {
     float: right;
 }
+
+#code:hover {
+    cursor: pointer;
+}

+ 124 - 1
src/main/webapp/resources/js/account/signIn.js

@@ -3,6 +3,11 @@
  */
 document.write("<script language=javascript src='static/js/common/toastr.js'></script>");
 
+/**
+ * 引入base方法
+ */
+document.write("<script language=javascript src='static/js/common/base.js'></script>");
+
 // 登录点击
 function login() {
     var userName = $('#p_username').val();
@@ -24,7 +29,9 @@ function login() {
     });
 }
 
-// 键盘确认按钮
+/**
+ * 键盘确认按钮
+ */
 document.onkeydown = function(event) {
     var e = event || window.event;
     if (e && e.keyCode == 13) { // enter 键
@@ -32,6 +39,107 @@ document.onkeydown = function(event) {
     }
 };
 
+
+/**
+ * 注册
+ */
+function register() {
+    checkInfo();
+    var user = {
+        fullName: $('#u_name').val(),
+        password: $('#u_pwd').val(),
+        tel: $('#u_tel').val(),
+        email: $('#u_email').val()
+    };
+    $.ajax('register', {
+        data: user,
+        method: 'POST',
+        async: false,
+        success: function() {
+            window.location.href = "/signIn";
+        },
+        error: function (error) {
+            alert('注册失败');
+        }
+    });
+}
+
+/**
+ * 检验信息
+ */
+function checkInfo() {
+    if (isEmpty($('#u_email').val())) {
+        alert("邮箱不能为空");
+        return;
+    }
+    if ($('#u_email').val().indexOf('@usoftchina.com') < 0) {
+        alert("请填写优软企业邮箱");
+        return;
+    }
+    if (isEmpty($('#u_pwd').val())) {
+        alert("密码不能为空");
+        return;
+    }
+    if (isEmpty($('#u_confirmPwd').val())) {
+        alert("请确认密码");
+        return;
+    }
+    if ($('#u_pwd').val() != $('#u_confirmPwd').val()) {
+        alert("两次密码不一致");
+        return;
+    }
+    validate();
+}
+
+/**
+ * 验证码
+ */
+var code;
+function createCode() {
+    code = "";
+    var codeLength = 4;//验证码的长度
+    var checkCode = document.getElementById("code");
+    var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',
+        'S','T','U','V','W','X','Y','Z');//随机数
+    for (var i = 0; i < codeLength; i++) {//循环操作
+        var index = Math.floor(Math.random() * 36);//取得随机数的索引(0~35)
+        code += random[index];//根据索引取得随机数加到code上
+    }
+    checkCode.value = code;//把code值赋给验证码
+}
+
+/**
+ * 校验验证码
+ */
+function validate() {
+    var inputCode = document.getElementById("captcha").value.toUpperCase(); //取得输入的验证码并转化为大写
+    if (inputCode.length <= 0) { //若输入的验证码长度为0
+        alert("请输入验证码!"); //则弹出请输入验证码
+       return;
+    } else if (inputCode != code ) { //若输入的验证码与产生的验证码不一致时
+        alert("验证码输入错误"); //则弹出验证码输入错误
+        createCode();//刷新验证码
+        document.getElementById("captcha").value = "";//清空文本框
+        return;
+    }
+}
+
+/**
+ * 重置密码
+ */
+function resetPwd() {
+    $.ajax('restPwd', {
+        data: $('#p_email').val(),
+        method: 'POST',
+        async: false,
+        success: function() {
+            window.location.href = "/signIn";
+        },
+        error: function (error) {
+            alert('注册失败');
+        }
+    });
+}
 $(function() {
     'use strict';
 
@@ -44,5 +152,20 @@ $(function() {
         }
     });
 
+    /**
+     * 登录
+     */
     $('#link-login').click(login);
+
+    /**
+     * 注册
+     */
+    $('#u_register').click(register);
+
+    /**
+     * 生成验证码
+     */
+    createCode();
+
+    $('#p_restPwd').click(resetPwd);
 });

+ 7 - 0
src/main/webapp/resources/js/common/base.js

@@ -0,0 +1,7 @@
+// 判断字符是否为空
+function isEmpty(exp) {
+    if (null == exp || typeof exp == "null" || typeof(exp) == "undefined" || !exp || "" == exp) {
+        return true;
+    }
+    return false;
+}