|
@ -46,14 +46,14 @@ public class SysService {
|
46
|
46
|
private String bindMailReplaceKey;
|
47
|
47
|
private String bindMailReplaceContentTempalte;
|
48
|
48
|
private long timeLimitWithBindMail = 10 * 60 * 1000;
|
49
|
|
|
|
49
|
|
50
|
50
|
private String regMailReplaceKey;
|
51
|
51
|
private String regMailReplaceContentTempalte;
|
52
|
52
|
private long timeLimitWithRegMail = 10 * 60 * 1000;
|
53
|
53
|
|
54
|
54
|
private String bindMobilePhoneReplaceKey;
|
55
|
55
|
private String bindMobilePhoneContentTemplate;
|
56
|
|
private long timeLimitWithBindMobilePhone =3 * 60 * 1000;
|
|
56
|
private long timeLimitWithBindMobilePhone = 3 * 60 * 1000;
|
57
|
57
|
|
58
|
58
|
private String phoneRetrievePasswordReplaceKey;
|
59
|
59
|
private String phoneRetrievePasswordContentTemplate;
|
|
@ -63,11 +63,11 @@ public class SysService {
|
63
|
63
|
private String mailRetrievePasswordReplaceKey;
|
64
|
64
|
private String mailRetrievePasswordSubject;
|
65
|
65
|
private long timeLimitWithMailRetrivePassword = 10 * 60 * 1000;
|
66
|
|
|
|
66
|
|
67
|
67
|
private String regMobilePhoneReplaceKey;
|
68
|
68
|
private String regMobilePhoneContentTemplate;
|
69
|
69
|
private long timeLimitWithRegMobilePhone = 3 * 60 * 1000;
|
70
|
|
|
|
70
|
|
71
|
71
|
public String getRegMailReplaceKey() {
|
72
|
72
|
return regMailReplaceKey;
|
73
|
73
|
}
|
|
@ -122,7 +122,8 @@ public class SysService {
|
122
|
122
|
return mailRetrievePasswordSubject;
|
123
|
123
|
}
|
124
|
124
|
|
125
|
|
public void setMailRetrievePasswordSubject(String mailRetrievePasswordSubject) {
|
|
125
|
public void setMailRetrievePasswordSubject(
|
|
126
|
String mailRetrievePasswordSubject) {
|
126
|
127
|
this.mailRetrievePasswordSubject = mailRetrievePasswordSubject;
|
127
|
128
|
}
|
128
|
129
|
|
|
@ -138,7 +139,8 @@ public class SysService {
|
138
|
139
|
return phoneRetrievePasswordReplaceKey;
|
139
|
140
|
}
|
140
|
141
|
|
141
|
|
public void setPhoneRetrievePasswordReplaceKey(String phoneRetrievePasswordReplaceKey) {
|
|
142
|
public void setPhoneRetrievePasswordReplaceKey(
|
|
143
|
String phoneRetrievePasswordReplaceKey) {
|
142
|
144
|
this.phoneRetrievePasswordReplaceKey = phoneRetrievePasswordReplaceKey;
|
143
|
145
|
}
|
144
|
146
|
|
|
@ -146,7 +148,8 @@ public class SysService {
|
146
|
148
|
return phoneRetrievePasswordContentTemplate;
|
147
|
149
|
}
|
148
|
150
|
|
149
|
|
public void setPhoneRetrievePasswordContentTemplate(String phoneRetrievePasswordContentTemplate) {
|
|
151
|
public void setPhoneRetrievePasswordContentTemplate(
|
|
152
|
String phoneRetrievePasswordContentTemplate) {
|
150
|
153
|
this.phoneRetrievePasswordContentTemplate = phoneRetrievePasswordContentTemplate;
|
151
|
154
|
}
|
152
|
155
|
|
|
@ -154,7 +157,8 @@ public class SysService {
|
154
|
157
|
return timeLimitWithPhoneRetrievePassword;
|
155
|
158
|
}
|
156
|
159
|
|
157
|
|
public void setTimeLimitWithPhoneRetrievePassword(long timeLimitWithPhoneRetrievePassword) {
|
|
160
|
public void setTimeLimitWithPhoneRetrievePassword(
|
|
161
|
long timeLimitWithPhoneRetrievePassword) {
|
158
|
162
|
this.timeLimitWithPhoneRetrievePassword = timeLimitWithPhoneRetrievePassword;
|
159
|
163
|
}
|
160
|
164
|
|
|
@ -162,7 +166,8 @@ public class SysService {
|
162
|
166
|
return timeLimitWithMailRetrivePassword;
|
163
|
167
|
}
|
164
|
168
|
|
165
|
|
public void setTimeLimitWithMailRetrivePassword(long timeLimitWithMailRetrivePassword) {
|
|
169
|
public void setTimeLimitWithMailRetrivePassword(
|
|
170
|
long timeLimitWithMailRetrivePassword) {
|
166
|
171
|
this.timeLimitWithMailRetrivePassword = timeLimitWithMailRetrivePassword;
|
167
|
172
|
}
|
168
|
173
|
|
|
@ -178,7 +183,8 @@ public class SysService {
|
178
|
183
|
return bindMobilePhoneContentTemplate;
|
179
|
184
|
}
|
180
|
185
|
|
181
|
|
public void setBindMobilePhoneContentTemplate(String bindMobilePhoneContentTemplate) {
|
|
186
|
public void setBindMobilePhoneContentTemplate(
|
|
187
|
String bindMobilePhoneContentTemplate) {
|
182
|
188
|
this.bindMobilePhoneContentTemplate = bindMobilePhoneContentTemplate;
|
183
|
189
|
}
|
184
|
190
|
|
|
@ -186,11 +192,13 @@ public class SysService {
|
186
|
192
|
return timeLimitWithBindMobilePhone;
|
187
|
193
|
}
|
188
|
194
|
|
189
|
|
public void setTimeLimitWithBindMobilePhone(long timeLimitWithBindMobilePhone) {
|
|
195
|
public void setTimeLimitWithBindMobilePhone(
|
|
196
|
long timeLimitWithBindMobilePhone) {
|
190
|
197
|
this.timeLimitWithBindMobilePhone = timeLimitWithBindMobilePhone;
|
191
|
198
|
}
|
192
|
199
|
|
193
|
|
public void setMailRetrievePasswordContentTemplate(String retrievePasswordContentTemplate) {
|
|
200
|
public void setMailRetrievePasswordContentTemplate(
|
|
201
|
String retrievePasswordContentTemplate) {
|
194
|
202
|
this.mailRetrievePasswordContentTemplate = retrievePasswordContentTemplate;
|
195
|
203
|
}
|
196
|
204
|
|
|
@ -214,7 +222,8 @@ public class SysService {
|
214
|
222
|
return mailRetrievePasswordReplaceKey;
|
215
|
223
|
}
|
216
|
224
|
|
217
|
|
public void setMailRetrievePasswordReplaceKey(String retrievePasswordReplaceKey) {
|
|
225
|
public void setMailRetrievePasswordReplaceKey(
|
|
226
|
String retrievePasswordReplaceKey) {
|
218
|
227
|
this.mailRetrievePasswordReplaceKey = retrievePasswordReplaceKey;
|
219
|
228
|
}
|
220
|
229
|
|
|
@ -234,7 +243,8 @@ public class SysService {
|
234
|
243
|
return bindMailReplaceContentTempalte;
|
235
|
244
|
}
|
236
|
245
|
|
237
|
|
public void setBindMailReplaceContentTempalte(String bindMailReplaceContentTempalte) {
|
|
246
|
public void setBindMailReplaceContentTempalte(
|
|
247
|
String bindMailReplaceContentTempalte) {
|
238
|
248
|
this.bindMailReplaceContentTempalte = bindMailReplaceContentTempalte;
|
239
|
249
|
}
|
240
|
250
|
|
|
@ -264,42 +274,53 @@ public class SysService {
|
264
|
274
|
|
265
|
275
|
@Get
|
266
|
276
|
@Path("/getUUID")
|
267
|
|
public String getUUID(@JdbcConn Connection con, String pass) throws SQLException {
|
|
277
|
public String getUUID(@JdbcConn Connection con, String pass)
|
|
278
|
throws SQLException {
|
268
|
279
|
return StringUtil.md5(pass);
|
269
|
280
|
}
|
270
|
|
|
|
281
|
|
271
|
282
|
@Get
|
272
|
283
|
@Path("/isReg")
|
273
|
|
public boolean isReg(@JdbcConn Connection con, String key) throws SQLException {
|
|
284
|
public boolean isReg(@JdbcConn Connection con, String key)
|
|
285
|
throws SQLException {
|
274
|
286
|
User user = this.userDao.queryByEmailOrMobilePhone(con, key);
|
275
|
|
if(null != user) {
|
|
287
|
if (null != user) {
|
276
|
288
|
return false;
|
277
|
|
}else{
|
|
289
|
} else {
|
278
|
290
|
return true;
|
279
|
291
|
}
|
280
|
292
|
}
|
281
|
293
|
|
282
|
294
|
/**
|
283
|
295
|
* 手机验证注册
|
|
296
|
*
|
284
|
297
|
* @param con
|
285
|
|
* @param state 发送手机验证码的返回值
|
286
|
|
* @param mobilePhone 验证的手机号
|
287
|
|
* @param validateCode 手机验证码
|
288
|
|
* @param password 注册密码
|
|
298
|
* @param state
|
|
299
|
* 发送手机验证码的返回值
|
|
300
|
* @param mobilePhone
|
|
301
|
* 验证的手机号
|
|
302
|
* @param validateCode
|
|
303
|
* 手机验证码
|
|
304
|
* @param password
|
|
305
|
* 注册密码
|
289
|
306
|
* @return
|
290
|
307
|
* @throws SQLException
|
291
|
308
|
*/
|
292
|
309
|
@Post
|
293
|
310
|
@Path("/regmobile")
|
294
|
|
public String regMobile(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password) throws SQLException {
|
|
311
|
public String regMobile(@JdbcConn(true) Connection con, String state,
|
|
312
|
String mobilePhone, String validateCode, String password)
|
|
313
|
throws SQLException {
|
295
|
314
|
@SuppressWarnings("unchecked")
|
296
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
|
|
315
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
316
|
.getCachedObject(state);
|
297
|
317
|
if (sc == null)
|
298
|
318
|
return null;
|
299
|
319
|
if (sc.getExpiredTime() < System.currentTimeMillis())
|
300
|
320
|
return null;
|
301
|
321
|
try {
|
302
|
|
if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(validateCode)){
|
|
322
|
if (!sc.getKey().equals(mobilePhone)
|
|
323
|
|| !sc.getValue().equals(validateCode)) {
|
303
|
324
|
return null;
|
304
|
325
|
}
|
305
|
326
|
User user = new User();
|
|
@ -307,91 +328,124 @@ public class SysService {
|
307
|
328
|
String passwd = StringUtil.md5(password);
|
308
|
329
|
user.setMobilePhone(mobilePhone);
|
309
|
330
|
user.setPasswd(passwd);
|
310
|
|
user.setUserType(0+"");
|
|
331
|
user.setUserType(0 + "");
|
311
|
332
|
this.userDao.insert(con, user);
|
312
|
333
|
return user.getId();
|
313
|
334
|
} finally {
|
314
|
335
|
JfwAppContext.removeCachedObject(state);
|
315
|
336
|
}
|
316
|
337
|
}
|
317
|
|
|
|
338
|
|
318
|
339
|
/**
|
319
|
|
* 邮箱验证注册
|
|
340
|
* 邮箱验证
|
|
341
|
*
|
320
|
342
|
* @param con
|
321
|
|
* @param key 发送邮箱验证的返回值
|
322
|
|
* @param mail 验证的邮箱地址
|
323
|
|
* @param password 注册密码
|
324
|
|
* @return
|
|
343
|
* @param key
|
|
344
|
* 发送邮箱验证的返回值
|
|
345
|
* @param mail
|
|
346
|
* 验证的邮箱地址
|
|
347
|
* @return 验证成功 用户登录并返回用户信息 验证失败返回null
|
325
|
348
|
* @throws SQLException
|
326
|
349
|
*/
|
|
350
|
@SetCookie(checkResultNull = true, path = "/", value = {
|
|
351
|
"userid=result.getId()", "userMobilePhone=result.getMobilePhone()",
|
|
352
|
"userType=result.getType()",
|
|
353
|
"userAuth=String.valueOf(result.isAuth())",
|
|
354
|
"userEmail=result.getEmail()==null?\"\":result.getEmail()",
|
|
355
|
"userName=result.getName()" })
|
327
|
356
|
@Post
|
328
|
357
|
@Path("/regmail/{key}")
|
329
|
|
public String regeMail(@JdbcConn(true) Connection con, @PathVar String key, String mail, String password) throws SQLException {
|
|
358
|
public SessionUser regeMail(@JdbcConn(true) Connection con, @PathVar String key, String mail) throws SQLException {
|
330
|
359
|
@SuppressWarnings("unchecked")
|
331
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
|
|
360
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
361
|
.getCachedObject(key);
|
332
|
362
|
if (sc == null)
|
333
|
363
|
return null;
|
334
|
364
|
if (sc.getExpiredTime() < System.currentTimeMillis())
|
335
|
365
|
return null;
|
336
|
366
|
try {
|
337
|
|
User user = new User();
|
338
|
|
user.setId(StringUtil.buildUUID());
|
339
|
|
String passwd = StringUtil.md5(password);
|
340
|
|
user.setEmail(mail);
|
341
|
|
user.setPasswd(passwd);
|
342
|
|
user.setUserType(0+"");
|
343
|
|
this.userDao.insert(con, user);
|
344
|
|
return user.getId();
|
|
367
|
User user = userDao.queryByEmailOrMobilePhone(con, mail);
|
|
368
|
if (null == user)
|
|
369
|
return null;
|
|
370
|
SessionUser ret = new SessionUser();
|
|
371
|
ret.setId(user.getId());
|
|
372
|
if (null != this.professorDao.query(con, user.getId())) {
|
|
373
|
ret.setName(this.professorDao.query(con, user.getId()).getName());
|
|
374
|
}
|
|
375
|
ret.setMobilePhone(user.getMobilePhone());
|
|
376
|
ret.setType(user.getUserType());
|
|
377
|
ret.setEmail(user.getEmail());
|
|
378
|
ret.setAuth(true);
|
|
379
|
return ret;
|
345
|
380
|
} finally {
|
346
|
381
|
JfwAppContext.removeCachedObject(key);
|
347
|
382
|
}
|
348
|
383
|
}
|
349
|
|
|
|
384
|
|
350
|
385
|
/**
|
351
|
|
* 发送邮箱验证
|
|
386
|
* 邮箱注册并发送邮箱验证
|
352
|
387
|
* @param con
|
353
|
|
* @param mail 验证的邮箱地址
|
354
|
|
* @return
|
|
388
|
* @param mail 待验证的邮箱地址
|
|
389
|
* @param password 密码
|
|
390
|
* @return 注册成功并发动验证返回用户ID 用户已注册返回null 邮件发送失败抛出异常
|
355
|
391
|
* @throws JfwBaseException
|
356
|
392
|
* @throws SQLException
|
357
|
393
|
*/
|
|
394
|
@SuppressWarnings("null")
|
358
|
395
|
@Get
|
359
|
396
|
@Path("/regmail")
|
360
|
|
public boolean regMail(@JdbcConn(false) Connection con, String mail) throws JfwBaseException, SQLException {
|
|
397
|
public String regMail(@JdbcConn(true) Connection con, String mail,
|
|
398
|
String password) throws JfwBaseException, SQLException {
|
361
|
399
|
User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
|
362
|
|
if(null != user){
|
363
|
|
return false;
|
364
|
|
}
|
365
|
|
|
366
|
|
StateCode<String, String> sc = new StateCode<String, String>();
|
367
|
|
final String key = JfwAppContext.cacheObjectAndGenKey(sc);
|
368
|
|
|
369
|
|
Map<String, String> map = new HashMap<String, String>();
|
370
|
|
map.put(this.regMailReplaceKey, key);
|
371
|
|
try {
|
372
|
|
mailservice.sendSimpleMail(mail, this.regMailReplaceContentTempalte, map, this.bindMailSubject);
|
373
|
|
long ct = System.currentTimeMillis();
|
374
|
|
long et = ct + this.timeLimitWithRegMail + 10000;
|
375
|
|
sc.setBuildTime(ct);
|
376
|
|
sc.setExpiredTime(et);
|
377
|
|
JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
|
378
|
|
@Override
|
379
|
|
public void run() {
|
380
|
|
JfwAppContext.removeCachedObject(key);
|
381
|
|
}
|
382
|
|
}, this.timeLimitWithRegMail + 20000, TimeUnit.MILLISECONDS);
|
383
|
|
} catch (Exception e) {
|
384
|
|
JfwAppContext.removeCachedObject(key);
|
385
|
|
throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
|
|
400
|
if (null != user) {
|
|
401
|
return null;
|
|
402
|
} else {
|
|
403
|
user.setId(StringUtil.buildUUID());
|
|
404
|
String passwd = StringUtil.md5(password);
|
|
405
|
user.setEmail(mail);
|
|
406
|
user.setPasswd(passwd);
|
|
407
|
user.setUserType(0 + "");
|
|
408
|
this.userDao.insert(con, user);
|
|
409
|
StateCode<String, String> sc = new StateCode<String, String>();
|
|
410
|
final String key = JfwAppContext.cacheObjectAndGenKey(sc);
|
|
411
|
|
|
412
|
Map<String, String> map = new HashMap<String, String>();
|
|
413
|
map.put(this.regMailReplaceKey, key);
|
|
414
|
try {
|
|
415
|
mailservice.sendSimpleMail(mail,
|
|
416
|
this.regMailReplaceContentTempalte, map,
|
|
417
|
this.bindMailSubject);
|
|
418
|
long ct = System.currentTimeMillis();
|
|
419
|
long et = ct + this.timeLimitWithRegMail + 10000;
|
|
420
|
sc.setBuildTime(ct);
|
|
421
|
sc.setExpiredTime(et);
|
|
422
|
JfwAppContext.getScheduledExecutorService().schedule(
|
|
423
|
new Runnable() {
|
|
424
|
@Override
|
|
425
|
public void run() {
|
|
426
|
JfwAppContext.removeCachedObject(key);
|
|
427
|
}
|
|
428
|
}, this.timeLimitWithRegMail + 20000,
|
|
429
|
TimeUnit.MILLISECONDS);
|
|
430
|
} catch (Exception e) {
|
|
431
|
JfwAppContext.removeCachedObject(key);
|
|
432
|
throw new JfwBaseException(10011, "send mail to " + mail
|
|
433
|
+ " error", e);
|
|
434
|
}
|
386
|
435
|
}
|
387
|
|
return true;
|
|
436
|
return user.getId();
|
388
|
437
|
}
|
389
|
|
|
390
|
|
@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
|
391
|
|
"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()","userName=result.getName()" })
|
|
438
|
|
|
439
|
@SetCookie(checkResultNull = true, path = "/", value = {
|
|
440
|
"userid=result.getId()", "userMobilePhone=result.getMobilePhone()",
|
|
441
|
"userType=result.getType()",
|
|
442
|
"userAuth=String.valueOf(result.isAuth())",
|
|
443
|
"userEmail=result.getEmail()==null?\"\":result.getEmail()",
|
|
444
|
"userName=result.getName()" })
|
392
|
445
|
@Post
|
393
|
446
|
@Path("/slogin")
|
394
|
|
public SessionUser sLogin(@JdbcConn Connection con, String code, String mobile) throws SQLException {
|
|
447
|
public SessionUser sLogin(@JdbcConn Connection con, String code,
|
|
448
|
String mobile) throws SQLException {
|
395
|
449
|
User user = userDao.query(con, code);
|
396
|
450
|
if (null == user)
|
397
|
451
|
return null;
|
|
@ -408,11 +462,16 @@ public class SysService {
|
408
|
462
|
return ret;
|
409
|
463
|
}
|
410
|
464
|
|
411
|
|
@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
|
412
|
|
"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()" ,"userName=result.getName()"})
|
|
465
|
@SetCookie(checkResultNull = true, path = "/", value = {
|
|
466
|
"userid=result.getId()", "userMobilePhone=result.getMobilePhone()",
|
|
467
|
"userType=result.getType()",
|
|
468
|
"userAuth=String.valueOf(result.isAuth())",
|
|
469
|
"userEmail=result.getEmail()==null?\"\":result.getEmail()",
|
|
470
|
"userName=result.getName()" })
|
413
|
471
|
@Post
|
414
|
472
|
@Path("/login")
|
415
|
|
public SessionUser login(@JdbcConn Connection con, String lk, String pw) throws SQLException {
|
|
473
|
public SessionUser login(@JdbcConn Connection con, String lk, String pw)
|
|
474
|
throws SQLException {
|
416
|
475
|
User user = userDao.queryByEmailOrMobilePhone(con, lk);
|
417
|
476
|
if (null == user)
|
418
|
477
|
return null;
|
|
@ -421,11 +480,10 @@ public class SysService {
|
421
|
480
|
if (!StringUtil.md5(pw).equals(user.getPasswd()))
|
422
|
481
|
return null;
|
423
|
482
|
|
424
|
|
|
425
|
483
|
SessionUser ret = new SessionUser();
|
426
|
484
|
ret.setId(user.getId());
|
427
|
|
if(null!=this.professorDao.query(con,user.getId())) {
|
428
|
|
ret.setName(this.professorDao.query(con,user.getId()).getName());
|
|
485
|
if (null != this.professorDao.query(con, user.getId())) {
|
|
486
|
ret.setName(this.professorDao.query(con, user.getId()).getName());
|
429
|
487
|
}
|
430
|
488
|
ret.setMobilePhone(user.getMobilePhone());
|
431
|
489
|
ret.setType(user.getUserType());
|
|
@ -436,7 +494,8 @@ public class SysService {
|
436
|
494
|
|
437
|
495
|
@Post
|
438
|
496
|
@Path("/cp")
|
439
|
|
public boolean changePw(@JdbcConn(true) Connection con, String id, String npw, @Nullable String onw) throws SQLException {
|
|
497
|
public boolean changePw(@JdbcConn(true) Connection con, String id,
|
|
498
|
String npw, @Nullable String onw) throws SQLException {
|
440
|
499
|
User user = this.userDao.query(con, id);
|
441
|
500
|
if (user == null)
|
442
|
501
|
return false;
|
|
@ -453,7 +512,8 @@ public class SysService {
|
453
|
512
|
|
454
|
513
|
@Get
|
455
|
514
|
@Path("/reqBindMail")
|
456
|
|
public boolean reqBindMail(@JdbcConn(false) Connection con, String userid, String mail) throws JfwBaseException, SQLException {
|
|
515
|
public boolean reqBindMail(@JdbcConn(false) Connection con, String userid,
|
|
516
|
String mail) throws JfwBaseException, SQLException {
|
457
|
517
|
User user = this.userDao.query(con, userid);
|
458
|
518
|
if (null == user)
|
459
|
519
|
return false;
|
|
@ -469,29 +529,36 @@ public class SysService {
|
469
|
529
|
Map<String, String> map = new HashMap<String, String>();
|
470
|
530
|
map.put(this.bindMailReplaceKey, key);
|
471
|
531
|
try {
|
472
|
|
mailservice.sendSimpleMail(mail, this.bindMailReplaceContentTempalte, map, this.bindMailSubject);
|
|
532
|
mailservice.sendSimpleMail(mail,
|
|
533
|
this.bindMailReplaceContentTempalte, map,
|
|
534
|
this.bindMailSubject);
|
473
|
535
|
long ct = System.currentTimeMillis();
|
474
|
536
|
long et = ct + this.timeLimitWithBindMail + 10000;
|
475
|
537
|
sc.setBuildTime(ct);
|
476
|
538
|
sc.setExpiredTime(et);
|
477
|
|
JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
|
478
|
|
@Override
|
479
|
|
public void run() {
|
480
|
|
JfwAppContext.removeCachedObject(key);
|
481
|
|
}
|
482
|
|
}, this.timeLimitWithBindMail + 20000, TimeUnit.MILLISECONDS);
|
|
539
|
JfwAppContext.getScheduledExecutorService().schedule(
|
|
540
|
new Runnable() {
|
|
541
|
@Override
|
|
542
|
public void run() {
|
|
543
|
JfwAppContext.removeCachedObject(key);
|
|
544
|
}
|
|
545
|
}, this.timeLimitWithBindMail + 20000,
|
|
546
|
TimeUnit.MILLISECONDS);
|
483
|
547
|
} catch (Exception e) {
|
484
|
548
|
JfwAppContext.removeCachedObject(key);
|
485
|
|
throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
|
|
549
|
throw new JfwBaseException(10011,
|
|
550
|
"send mail to " + mail + " error", e);
|
486
|
551
|
}
|
487
|
552
|
return true;
|
488
|
553
|
}
|
489
|
554
|
|
490
|
555
|
@Get
|
491
|
556
|
@Path("/bindMail/{key}")
|
492
|
|
public boolean bindMail(@JdbcConn(true) Connection con, @PathVar String key) throws SQLException {
|
|
557
|
public boolean bindMail(@JdbcConn(true) Connection con, @PathVar String key)
|
|
558
|
throws SQLException {
|
493
|
559
|
@SuppressWarnings("unchecked")
|
494
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
|
|
560
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
561
|
.getCachedObject(key);
|
495
|
562
|
if (sc == null)
|
496
|
563
|
return false;
|
497
|
564
|
if (sc.getExpiredTime() < System.currentTimeMillis())
|
|
@ -505,7 +572,9 @@ public class SysService {
|
505
|
572
|
|
506
|
573
|
@Get
|
507
|
574
|
@Path("/vcWithBind")
|
508
|
|
public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone) throws JfwBaseException, SQLException {
|
|
575
|
public String reqBindBindMobilePhone(@JdbcConn(false) Connection con,
|
|
576
|
String userid, String mobilePhone) throws JfwBaseException,
|
|
577
|
SQLException {
|
509
|
578
|
User user = this.userDao.query(con, userid);
|
510
|
579
|
if (null == user)
|
511
|
580
|
return null;
|
|
@ -524,40 +593,48 @@ public class SysService {
|
524
|
593
|
String vc = String.format("%04d", vi);
|
525
|
594
|
sc.setKey(mobilePhone);
|
526
|
595
|
sc.setValue(vc);
|
527
|
|
this.mobilePhoneServcie.sendMessage(mobilePhone, this.bindMobilePhoneContentTemplate, this.bindMobilePhoneReplaceKey, vc);
|
|
596
|
this.mobilePhoneServcie.sendMessage(mobilePhone,
|
|
597
|
this.bindMobilePhoneContentTemplate,
|
|
598
|
this.bindMobilePhoneReplaceKey, vc);
|
528
|
599
|
long ct = System.currentTimeMillis();
|
529
|
600
|
long et = ct + this.timeLimitWithBindMobilePhone + 5000;
|
530
|
601
|
sc.setBuildTime(ct);
|
531
|
602
|
sc.setExpiredTime(et);
|
532
|
|
JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
|
533
|
|
@Override
|
534
|
|
public void run() {
|
535
|
|
JfwAppContext.removeCachedObject(key);
|
536
|
|
}
|
537
|
|
}, this.timeLimitWithBindMobilePhone + 10000, TimeUnit.MILLISECONDS);
|
|
603
|
JfwAppContext.getScheduledExecutorService().schedule(
|
|
604
|
new Runnable() {
|
|
605
|
@Override
|
|
606
|
public void run() {
|
|
607
|
JfwAppContext.removeCachedObject(key);
|
|
608
|
}
|
|
609
|
}, this.timeLimitWithBindMobilePhone + 10000,
|
|
610
|
TimeUnit.MILLISECONDS);
|
538
|
611
|
} catch (Exception e) {
|
539
|
612
|
JfwAppContext.removeCachedObject(key);
|
540
|
|
throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
|
|
613
|
throw new JfwBaseException(10012, "send mobile phone message to "
|
|
614
|
+ mobilePhone + " error", e);
|
541
|
615
|
}
|
542
|
616
|
return key;
|
543
|
617
|
}
|
544
|
618
|
|
545
|
619
|
/**
|
546
|
620
|
* 发送手机验证码
|
|
621
|
*
|
547
|
622
|
* @param con
|
548
|
|
* @param mobilePhone 验证的手机号
|
|
623
|
* @param mobilePhone
|
|
624
|
* 验证的手机号
|
549
|
625
|
* @return
|
550
|
626
|
* @throws JfwBaseException
|
551
|
627
|
* @throws SQLException
|
552
|
628
|
*/
|
553
|
629
|
@Get
|
554
|
630
|
@Path("/regmobilephone")
|
555
|
|
public String regMobilePhone(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
|
|
631
|
public String regMobilePhone(@JdbcConn(false) Connection con,
|
|
632
|
String mobilePhone) throws JfwBaseException, SQLException {
|
556
|
633
|
User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
|
557
|
|
if(null != user){
|
|
634
|
if (null != user) {
|
558
|
635
|
return null;
|
559
|
636
|
}
|
560
|
|
|
|
637
|
|
561
|
638
|
StateCode<String, String> sc = new StateCode<String, String>();
|
562
|
639
|
|
563
|
640
|
final String key = JfwAppContext.cacheObjectAndGenKey(sc);
|
|
@ -569,35 +646,44 @@ public class SysService {
|
569
|
646
|
String vc = String.format("%04d", vi);
|
570
|
647
|
sc.setKey(mobilePhone);
|
571
|
648
|
sc.setValue(vc);
|
572
|
|
this.mobilePhoneServcie.sendMessage(mobilePhone, this.regMobilePhoneContentTemplate, this.regMobilePhoneReplaceKey, vc);
|
|
649
|
this.mobilePhoneServcie.sendMessage(mobilePhone,
|
|
650
|
this.regMobilePhoneContentTemplate,
|
|
651
|
this.regMobilePhoneReplaceKey, vc);
|
573
|
652
|
long ct = System.currentTimeMillis();
|
574
|
653
|
long et = ct + this.timeLimitWithRegMobilePhone + 5000;
|
575
|
654
|
sc.setBuildTime(ct);
|
576
|
655
|
sc.setExpiredTime(et);
|
577
|
|
JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
|
578
|
|
@Override
|
579
|
|
public void run() {
|
580
|
|
JfwAppContext.removeCachedObject(key);
|
581
|
|
}
|
582
|
|
}, this.timeLimitWithRegMobilePhone + 10000, TimeUnit.MILLISECONDS);
|
|
656
|
JfwAppContext.getScheduledExecutorService().schedule(
|
|
657
|
new Runnable() {
|
|
658
|
@Override
|
|
659
|
public void run() {
|
|
660
|
JfwAppContext.removeCachedObject(key);
|
|
661
|
}
|
|
662
|
}, this.timeLimitWithRegMobilePhone + 10000,
|
|
663
|
TimeUnit.MILLISECONDS);
|
583
|
664
|
} catch (Exception e) {
|
584
|
665
|
JfwAppContext.removeCachedObject(key);
|
585
|
|
throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
|
|
666
|
throw new JfwBaseException(10012, "send mobile phone message to "
|
|
667
|
+ mobilePhone + " error", e);
|
586
|
668
|
}
|
587
|
669
|
return key;
|
588
|
670
|
}
|
589
|
|
|
|
671
|
|
590
|
672
|
@Post
|
591
|
673
|
@Path("/bindMobilePhone")
|
592
|
|
public boolean bindMobilePhone(@JdbcConn(true) Connection con, String state, String userid, String mobilePhone, String validateCode) throws SQLException {
|
|
674
|
public boolean bindMobilePhone(@JdbcConn(true) Connection con,
|
|
675
|
String state, String userid, String mobilePhone, String validateCode)
|
|
676
|
throws SQLException {
|
593
|
677
|
@SuppressWarnings("unchecked")
|
594
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
|
|
678
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
679
|
.getCachedObject(state);
|
595
|
680
|
if (sc == null)
|
596
|
681
|
return false;
|
597
|
682
|
if (sc.getExpiredTime() < System.currentTimeMillis())
|
598
|
683
|
return false;
|
599
|
684
|
try {
|
600
|
|
if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(validateCode))
|
|
685
|
if (!sc.getKey().equals(mobilePhone)
|
|
686
|
|| !sc.getValue().equals(validateCode))
|
601
|
687
|
return false;
|
602
|
688
|
return this.userDao.updateMobilePhone(con, mobilePhone, userid) > 0;
|
603
|
689
|
} finally {
|
|
@ -607,12 +693,13 @@ public class SysService {
|
607
|
693
|
|
608
|
694
|
@Get
|
609
|
695
|
@Path("/vcWithRP")
|
610
|
|
public String rePassWordWithPhone(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
|
|
696
|
public String rePassWordWithPhone(@JdbcConn(false) Connection con,
|
|
697
|
String mobilePhone) throws JfwBaseException, SQLException {
|
611
|
698
|
|
612
|
699
|
User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
|
613
|
700
|
if (null == user)
|
614
|
701
|
return null;
|
615
|
|
|
|
702
|
|
616
|
703
|
StateCode<String, String> sc = new StateCode<String, String>();
|
617
|
704
|
final String key = JfwAppContext.cacheObjectAndGenKey(sc);
|
618
|
705
|
try {
|
|
@ -622,20 +709,25 @@ public class SysService {
|
622
|
709
|
String vc = String.format("%04d", vi);
|
623
|
710
|
sc.setKey(mobilePhone);
|
624
|
711
|
sc.setValue(vc);
|
625
|
|
this.mobilePhoneServcie.sendMessage(mobilePhone, this.phoneRetrievePasswordContentTemplate, this.phoneRetrievePasswordReplaceKey, vc);
|
|
712
|
this.mobilePhoneServcie.sendMessage(mobilePhone,
|
|
713
|
this.phoneRetrievePasswordContentTemplate,
|
|
714
|
this.phoneRetrievePasswordReplaceKey, vc);
|
626
|
715
|
long ct = System.currentTimeMillis();
|
627
|
716
|
long et = ct + this.timeLimitWithPhoneRetrievePassword + 5000;
|
628
|
717
|
sc.setBuildTime(ct);
|
629
|
718
|
sc.setExpiredTime(et);
|
630
|
|
JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
|
631
|
|
@Override
|
632
|
|
public void run() {
|
633
|
|
JfwAppContext.removeCachedObject(key);
|
634
|
|
}
|
635
|
|
}, this.timeLimitWithPhoneRetrievePassword + 10000, TimeUnit.MILLISECONDS);
|
|
719
|
JfwAppContext.getScheduledExecutorService().schedule(
|
|
720
|
new Runnable() {
|
|
721
|
@Override
|
|
722
|
public void run() {
|
|
723
|
JfwAppContext.removeCachedObject(key);
|
|
724
|
}
|
|
725
|
}, this.timeLimitWithPhoneRetrievePassword + 10000,
|
|
726
|
TimeUnit.MILLISECONDS);
|
636
|
727
|
} catch (Exception e) {
|
637
|
728
|
JfwAppContext.removeCachedObject(key);
|
638
|
|
throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
|
|
729
|
throw new JfwBaseException(10012, "send mobile phone message to "
|
|
730
|
+ mobilePhone + " error", e);
|
639
|
731
|
}
|
640
|
732
|
return key;
|
641
|
733
|
}
|
|
@ -644,11 +736,12 @@ public class SysService {
|
644
|
736
|
@Path("/validCode")
|
645
|
737
|
public boolean validCode(String state, String vc) {
|
646
|
738
|
@SuppressWarnings("unchecked")
|
647
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
|
648
|
|
if (sc == null){
|
|
739
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
740
|
.getCachedObject(state);
|
|
741
|
if (sc == null) {
|
649
|
742
|
return false;
|
650
|
743
|
}
|
651
|
|
if (sc.getExpiredTime() < System.currentTimeMillis()){
|
|
744
|
if (sc.getExpiredTime() < System.currentTimeMillis()) {
|
652
|
745
|
return false;
|
653
|
746
|
}
|
654
|
747
|
return sc.getValue().equals(vc);
|
|
@ -656,19 +749,22 @@ public class SysService {
|
656
|
749
|
|
657
|
750
|
@Post
|
658
|
751
|
@Path("/resetPasswordWithMobilePhone")
|
659
|
|
public boolean resetPassword(@JdbcConn(true) Connection con, String state, String mobilePhone, String pw, String vc) throws SQLException {
|
|
752
|
public boolean resetPassword(@JdbcConn(true) Connection con, String state,
|
|
753
|
String mobilePhone, String pw, String vc) throws SQLException {
|
660
|
754
|
@SuppressWarnings("unchecked")
|
661
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
|
662
|
|
if (sc == null){
|
|
755
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
756
|
.getCachedObject(state);
|
|
757
|
if (sc == null) {
|
663
|
758
|
return false;
|
664
|
759
|
}
|
665
|
|
if (sc.getExpiredTime() < System.currentTimeMillis()){
|
|
760
|
if (sc.getExpiredTime() < System.currentTimeMillis()) {
|
666
|
761
|
return false;
|
667
|
762
|
}
|
668
|
763
|
try {
|
669
|
764
|
if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(vc))
|
670
|
765
|
return false;
|
671
|
|
return this.userDao.updatePasswordWithMobileOrEmail(con, StringUtil.md5(pw), mobilePhone) > 0;
|
|
766
|
return this.userDao.updatePasswordWithMobileOrEmail(con,
|
|
767
|
StringUtil.md5(pw), mobilePhone) > 0;
|
672
|
768
|
} finally {
|
673
|
769
|
JfwAppContext.removeCachedObject(state);
|
674
|
770
|
}
|
|
@ -676,7 +772,8 @@ public class SysService {
|
676
|
772
|
|
677
|
773
|
@Get
|
678
|
774
|
@Path("/reqRpWithEmail")
|
679
|
|
public boolean reqRpWithEmail(@JdbcConn(false) Connection con, String mail) throws JfwBaseException, SQLException {
|
|
775
|
public boolean reqRpWithEmail(@JdbcConn(false) Connection con, String mail)
|
|
776
|
throws JfwBaseException, SQLException {
|
680
|
777
|
User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
|
681
|
778
|
if (user == null)
|
682
|
779
|
return false;
|
|
@ -687,20 +784,25 @@ public class SysService {
|
687
|
784
|
Map<String, String> map = new HashMap<String, String>();
|
688
|
785
|
map.put(this.mailRetrievePasswordReplaceKey, key);
|
689
|
786
|
try {
|
690
|
|
mailservice.sendSimpleMail(mail, this.mailRetrievePasswordContentTemplate, map, this.mailRetrievePasswordSubject);
|
|
787
|
mailservice.sendSimpleMail(mail,
|
|
788
|
this.mailRetrievePasswordContentTemplate, map,
|
|
789
|
this.mailRetrievePasswordSubject);
|
691
|
790
|
long ct = System.currentTimeMillis();
|
692
|
791
|
long et = ct + this.timeLimitWithMailRetrivePassword + 10000;
|
693
|
792
|
sc.setBuildTime(ct);
|
694
|
793
|
sc.setExpiredTime(et);
|
695
|
|
JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
|
696
|
|
@Override
|
697
|
|
public void run() {
|
698
|
|
JfwAppContext.removeCachedObject(key);
|
699
|
|
}
|
700
|
|
}, this.timeLimitWithMailRetrivePassword + 20000, TimeUnit.MILLISECONDS);
|
|
794
|
JfwAppContext.getScheduledExecutorService().schedule(
|
|
795
|
new Runnable() {
|
|
796
|
@Override
|
|
797
|
public void run() {
|
|
798
|
JfwAppContext.removeCachedObject(key);
|
|
799
|
}
|
|
800
|
}, this.timeLimitWithMailRetrivePassword + 20000,
|
|
801
|
TimeUnit.MILLISECONDS);
|
701
|
802
|
} catch (Exception e) {
|
702
|
803
|
JfwAppContext.removeCachedObject(key);
|
703
|
|
throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
|
|
804
|
throw new JfwBaseException(10011,
|
|
805
|
"send mail to " + mail + " error", e);
|
704
|
806
|
}
|
705
|
807
|
return true;
|
706
|
808
|
}
|
|
@ -709,7 +811,8 @@ public class SysService {
|
709
|
811
|
@Path("/validMailState")
|
710
|
812
|
public boolean validMailState(String state) {
|
711
|
813
|
@SuppressWarnings("unchecked")
|
712
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
|
|
814
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
815
|
.getCachedObject(state);
|
713
|
816
|
if (sc == null)
|
714
|
817
|
return false;
|
715
|
818
|
if (sc.getExpiredTime() < System.currentTimeMillis())
|
|
@ -719,9 +822,11 @@ public class SysService {
|
719
|
822
|
|
720
|
823
|
@Post
|
721
|
824
|
@Path("/resetPasswordWith")
|
722
|
|
public boolean resetPassword(@JdbcConn(true) Connection con, String state, String pw) throws SQLException {
|
|
825
|
public boolean resetPassword(@JdbcConn(true) Connection con, String state,
|
|
826
|
String pw) throws SQLException {
|
723
|
827
|
@SuppressWarnings("unchecked")
|
724
|
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
|
|
828
|
StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext
|
|
829
|
.getCachedObject(state);
|
725
|
830
|
if (sc == null)
|
726
|
831
|
return false;
|
727
|
832
|
if (sc.getExpiredTime() < System.currentTimeMillis())
|
|
@ -733,6 +838,7 @@ public class SysService {
|
733
|
838
|
JfwAppContext.removeCachedObject(state);
|
734
|
839
|
}
|
735
|
840
|
}
|
|
841
|
|
736
|
842
|
public static void main(String[] args) {
|
737
|
843
|
System.out.println(String.format("%04d", new Random().nextInt(10000)));
|
738
|
844
|
}
|