|
2 | 2 |
|
3 | 3 | import com.alibaba.fastjson.JSONObject; |
4 | 4 | import info.xiaomo.admin.test.base.BaseTest; |
| 5 | +import info.xiaomo.core.constant.GenderType; |
5 | 6 | import info.xiaomo.core.constant.WebDefaultValueConst; |
6 | 7 | import info.xiaomo.core.exception.UserNotFoundException; |
7 | 8 | import info.xiaomo.core.model.UserModel; |
8 | 9 | import info.xiaomo.core.service.UserService; |
| 10 | +import info.xiaomo.core.untils.DateUtil; |
9 | 11 | import info.xiaomo.core.untils.MD5Util; |
10 | 12 | import org.junit.Test; |
11 | 13 | import org.springframework.beans.factory.annotation.Autowired; |
12 | 14 | import org.springframework.data.domain.Page; |
13 | 15 |
|
| 16 | +import java.util.Date; |
| 17 | + |
14 | 18 | /** |
15 | 19 | * │\__╭╭╭╭╭__/│ |
16 | 20 | * │ │ |
@@ -93,4 +97,37 @@ public void testDelete() throws UserNotFoundException { |
93 | 97 | UserModel userModel = service.deleteUserById(26L); |
94 | 98 | System.out.println(JSONObject.toJSON(userModel)); |
95 | 99 | } |
| 100 | + |
| 101 | + @Test |
| 102 | + public void testValidateEmail() { |
| 103 | + String email = "83387856@qq.com"; |
| 104 | + String password = "woshixiaomo"; |
| 105 | + //数据访问层,通过email获取用户信息 |
| 106 | + UserModel userModel = service.findUserByEmail("83387856@qq.com"); |
| 107 | + //验证用户是否存在 |
| 108 | + if (userModel != null) { |
| 109 | + System.out.println(201); |
| 110 | + return; |
| 111 | + } |
| 112 | + //验证码是否过期 |
| 113 | + if (DateUtil.getNowOfMills() + DateUtil.ONE_DAY_IN_MILLISECONDS * 2 < DateUtil.getNowOfMills()) { |
| 114 | + System.out.println("己过期"); |
| 115 | + return; |
| 116 | + } |
| 117 | + //激活 |
| 118 | + userModel = new UserModel(); |
| 119 | + userModel.setNickName(email); |
| 120 | + userModel.setEmail(email); |
| 121 | + userModel.setGender(GenderType.secret); |
| 122 | + userModel.setImgUrl(WebDefaultValueConst.defaultImage);//默认是个百度的LOGO,作测试用 |
| 123 | + userModel.setValidateStatus(1);//状态:己激活 |
| 124 | + userModel.setValidateCode(MD5Util.encode(email)); |
| 125 | + userModel.setPhone(0L); |
| 126 | + userModel.setAddress(""); |
| 127 | + userModel.setPassword(MD5Util.encode(password)); |
| 128 | + userModel.setCreateTime(new Date()); |
| 129 | + userModel.setUpdateTime(new Date()); |
| 130 | + userModel = service.addUser(userModel); |
| 131 | + System.out.println(userModel.getNickName()); |
| 132 | + } |
96 | 133 | } |
0 commit comments