Browse Source

--add resetPassword() and changePw().

zzy.zhiyuan.foxmail 8 years ago
parent
commit
fba2b7e0ec

+ 1 - 1
src/main/java/com/ekexiu/portal/service/InitUserService.java

91
			this.professorDao.updateEmail(con, user.getId(), user.getEmail());
91
			this.professorDao.updateEmail(con, user.getId(), user.getEmail());
92
		}
92
		}
93
	}
93
	}
94
94
	
95
}
95
}

+ 16 - 12
src/main/java/com/ekexiu/portal/service/SysService.java

2
2
3
import java.sql.Connection;
3
import java.sql.Connection;
4
import java.sql.SQLException;
4
import java.sql.SQLException;
5
import java.text.SimpleDateFormat;
6
import java.util.Date;
5
import java.util.HashMap;
7
import java.util.HashMap;
6
import java.util.Map;
8
import java.util.Map;
7
import java.util.Random;
9
import java.util.Random;
34
@Path
36
@Path
35
public class SysService {
37
public class SysService {
36
	public static final String DEFAULT_PASS_WORD = "11111111111111111111111111111111";
38
	public static final String DEFAULT_PASS_WORD = "11111111111111111111111111111111";
39
	public static SimpleDateFormat DATE = new SimpleDateFormat("yyyyMMddHHmmss");
37
40
38
	@Autowrie
41
	@Autowrie
39
	private UserDao userDao;
42
	private UserDao userDao;
601
		ret.setAuth(true);
604
		ret.setAuth(true);
602
		return ret;
605
		return ret;
603
	}
606
	}
604
607
	
605
	@Post
608
	@Post
606
	@Path("/cp")
609
	@Path("/cp")
607
	public boolean changePw(@JdbcConn(true) Connection con, String id, String npw, @Nullable String onw) throws SQLException {
610
	public boolean changePw(@JdbcConn(true) Connection con, String id, String npw, @Nullable String onw) throws SQLException {
608
		User user = this.userDao.query(con, id);
609
		if (user == null)
610
			return false;
611
		if (onw == null) {
611
		if (onw == null) {
612
			if (!DEFAULT_PASS_WORD.equals(user.getPasswd()))
613
				return false;
612
			return this.userDao.updatePasswdAndActive(con, StringUtil.md5(npw), DATE.format(new Date()), id) > 0;
614
		} else {
613
		} else {
615
			if (!StringUtil.md5(onw).equals(user.getPasswd()))
616
				return false;
614
			return this.userDao.updatePasswd(con, StringUtil.md5(npw), id, StringUtil.md5(onw)) > 0;
617
		}
615
		}
618
		this.userDao.updatePassword(con, StringUtil.md5(npw), id);
619
		return true;
620
	}
616
	}
621
617
622
	@Get
618
	@Get
854
		try {
850
		try {
855
			if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(vc))
851
			if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(vc))
856
				return false;
852
				return false;
857
			return this.userDao.updatePasswordWithMobileOrEmail(con, StringUtil.md5(pw), mobilePhone) > 0;
853
			int ret = this.userDao.updatePasswdWithMobile(con, StringUtil.md5(pw), DATE.format(new Date()), mobilePhone);
854
			if (ret == 0) {
855
				return this.userDao.updatePasswordWithMobileOrEmail(con, StringUtil.md5(pw), mobilePhone) > 0;
856
			}
857
			return ret > 0;
858
		} finally {
858
		} finally {
859
			JfwAppContext.removeCachedObject(state);
859
			JfwAppContext.removeCachedObject(state);
860
		}
860
		}
914
			throw new JfwBaseException("验证超时");
914
			throw new JfwBaseException("验证超时");
915
		String key = sc.getKey();
915
		String key = sc.getKey();
916
		try {
916
		try {
917
			return this.userDao.updatePassword(con, StringUtil.md5(pw), .format(new Date()), key) > 0;
917
			int ret = this.userDao.updatePasswdAndActive(con, StringUtil.md5(pw), DATE.format(new Date()), .format(new Date()), key);
918
			if (ret == 0) {
919
				return this.userDao.updatePassword(con, StringUtil.md5(pw), key) > 0;
920
			}
921
			return ret > 0;
918
		} finally {
922
		} finally {
919
			JfwAppContext.removeCachedObject(state);
923
			JfwAppContext.removeCachedObject(state);
920
		}
924
		}