jiapeng 8 anos atrás
pai
commit
8f6da65b31

+ 5 - 0
pom.xml

118
			<artifactId>slf4j-log4j12</artifactId>
118
			<artifactId>slf4j-log4j12</artifactId>
119
			<version>1.7.21</version>
119
			<version>1.7.21</version>
120
		</dependency>
120
		</dependency>
121
		<dependency>
122
			<groupId>com.googlecode.json-simple</groupId>
123
			<artifactId>json-simple</artifactId>
124
			<version>1.1.1</version>
125
		</dependency>
121
	</dependencies>
126
	</dependencies>
122
	<build>
127
	<build>
123
		<resources>
128
		<resources>

+ 5 - 1
src/main/java/com/ekexiu/portal/dao/UserOpenIdDao.java

30

30

31
    @SelectOne
31
    @SelectOne
32
    @Nullable
32
    @Nullable
33
    UserOpenId query(Connection con, String oauthType, String userid) throws SQLException;
33
    UserOpenId queryByUserid(Connection con, String oauthType, String userid) throws SQLException;
34
    
35
    @SelectOne
36
    @Nullable
37
    UserOpenId queryByOpenid(Connection con, String oauthType, String openid) throws SQLException;
34
}
38
}

+ 229 - 165
src/main/java/com/ekexiu/portal/oauth/OAuthService.java

22
import com.ekexiu.portal.po.User;
22
import com.ekexiu.portal.po.User;
23
import com.ekexiu.portal.po.UserOpenId;
23
import com.ekexiu.portal.po.UserOpenId;
24
import com.ekexiu.portal.pojo.SessionUser;
24
import com.ekexiu.portal.pojo.SessionUser;
25
import com.ekexiu.portal.service.SysService;
26

25

27
@Path("/oauth")
26
@Path("/oauth")
28
public class OAuthService {
27
public class OAuthService {
29

28

30
    private long expriesWithOpenId = 1000 * 60 * 10;
31

32
    @Autowrie
33
    private UserOpenIdDao userOpenIdDao;
34
    @Autowrie
35
    private UserDao userDao;
36
    @Autowrie
37
    private ProfessorDao professorDao;
38

39
    private Map<String, OAuthHandler> handlers;
40

41
    public Map<String, OAuthHandler> getHandlers() {
42
        return handlers;
43
    }
44

45
    public void setHandlers(Map<String, OAuthHandler> handlers) {
46
        this.handlers = handlers;
47
    }
48

49
    public UserOpenIdDao getUserOpenIdDao() {
50
        return userOpenIdDao;
51
    }
52

53
    public void setUserOpenIdDao(UserOpenIdDao userOpenIdDao) {
54
        this.userOpenIdDao = userOpenIdDao;
55
    }
56

57
    public UserDao getUserDao() {
58
        return userDao;
59
    }
60

61
    public void setUserDao(UserDao userDao) {
62
        this.userDao = userDao;
63
    }
64

65
    public long getExpriesWithOpenId() {
66
        return expriesWithOpenId;
67
    }
68

69
    public void setExpriesWithOpenId(long expriesWithOpenId) {
70
        this.expriesWithOpenId = expriesWithOpenId;
71
    }
72

73
    public ProfessorDao getProfessorDao() {
74
        return professorDao;
75
    }
76

77
    public void setProfessorDao(ProfessorDao professorDao) {
78
        this.professorDao = professorDao;
79
    }
80

81
    @Get
82
    @Path("/validCode")
83
    public AuthLoginResponse validCode(@JdbcConn Connection con, String code, String state) throws SQLException, JfwBaseException {
84
        OAuthHandler oah = this.handlers.get(state);
85
        if (oah == null)
86
            throw new IllegalArgumentException("非法的参数{state=" + state);
87
        OAuthUser ou = oah.login(code);
88
        UserOpenId uoi = this.userOpenIdDao.query(con, oah.getType(), ou.getOpenId());
89

90
        StateCode<OAuthUser, UserOpenId> sc = new StateCode<OAuthUser, UserOpenId>();
91
        final String key = JfwAppContext.cacheObjectAndGenKey(sc);
92
        sc.setKey(ou);
93
        sc.setValue(uoi);
94
        sc.setBuildTime(System.currentTimeMillis());
95
        sc.setExpiredTime(sc.getBuildTime() + this.expriesWithOpenId);
96
        JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
97
            @Override
98
            public void run() {
99
                JfwAppContext.removeCachedObject(key);
100
            }
101
        }, this.expriesWithOpenId, TimeUnit.MILLISECONDS);
102
        AuthLoginResponse alr = new AuthLoginResponse();
103
        alr.setAssociated(null != uoi);
104
        alr.setAuthCode(key);
105
        return alr;
106
    }
107

108
    @SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
109
            "userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
110
            "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
111
    @Post
112
    @Path("/login")
113
    public SessionUser login(@JdbcConn Connection con, String authCode) throws SQLException, JfwBaseException {
114
        @SuppressWarnings("unchecked")
115
        StateCode<OAuthUser, UserOpenId> sc = (StateCode<OAuthUser, UserOpenId>) JfwAppContext.getCachedObject(authCode);
116
        JfwAppContext.removeCachedObject(authCode);
117
        if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
118
            throw new JfwBaseException(-1, "authCode is expired");
119
        if (null == sc.getValue())
120
            throw new JfwBaseException(-2, "authCode is invalid openid not associate local user");
121

122
        User user = this.userDao.query(con, sc.getValue().getUserid());
123
        if (null == user)
124
            return null;
125
        SessionUser ret = new SessionUser();
126
        ret.setId(user.getId());
127
        if (null != this.professorDao.query(con, user.getId())) {
128
            ret.setName(this.professorDao.query(con, user.getId()).getName());
129
        }
130
        ret.setMobilePhone(user.getMobilePhone());
131
        ret.setType(user.getUserType());
132
        ret.setEmail(user.getEmail());
133
        ret.setAuth(!SysService.DEFAULT_PASS_WORD.equals(user.getPasswd()));
134
        return ret;
135
    }
136

137
    @Post
138
    @Path("/validOpenid")
139
    public AuthLoginResponse validOpenid(@JdbcConn Connection con, String authType, String openid) throws SQLException, JfwBaseException {
140
        OAuthUser ou = new OAuthUser();
141
        ou.setType(authType);
142
        ou.setOpenId(openid);
143
        UserOpenId uoi = this.userOpenIdDao.query(con, authType, openid);
144
        AuthLoginResponse alr = new AuthLoginResponse();
145
        StateCode<OAuthUser, UserOpenId> sc = new StateCode<OAuthUser, UserOpenId>();
146
        final String key = JfwAppContext.cacheObjectAndGenKey(sc);
147
        sc.setKey(ou);
148
        sc.setValue(uoi);
149
        sc.setBuildTime(System.currentTimeMillis());
150
        sc.setExpiredTime(sc.getBuildTime() + this.expriesWithOpenId);
151
        JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
152
            @Override
153
            public void run() {
154
                JfwAppContext.removeCachedObject(key);
155
            }
156
        }, this.expriesWithOpenId, TimeUnit.MILLISECONDS);
157
        alr.setAssociated(null != uoi);
158
        alr.setAuthCode(key);
159
        return alr;
160
    }
161

162
    
163

164
    @Get
165
    @Path("/redirectUris")
166
    public Map<String, String> getRedirectUris() {
167
        Map<String, String> ret = new HashMap<String, String>();
168
        for (Map.Entry<String, OAuthHandler> h : this.handlers.entrySet()) {
169
            ret.put(h.getKey(), h.getValue().getLoginUrl());
170
        }
171
        return ret;
172
    }
173

174
    public static class AuthLoginResponse {
175
        private boolean associated;
176
        private String authCode;
177

178
        public boolean isAssociated() {
179
            return associated;
180
        }
181

182
        public void setAssociated(boolean associated) {
183
            this.associated = associated;
184
        }
185

186
        public String getAuthCode() {
187
            return authCode;
188
        }
189

190
        public void setAuthCode(String authCode) {
191
            this.authCode = authCode;
192
        }
193
    }
29
	private long expriesWithOpenId = 1000 * 60 * 10;
30

31
	@Autowrie
32
	private UserOpenIdDao userOpenIdDao;
33
	@Autowrie
34
	private UserDao userDao;
35
	@Autowrie
36
	private ProfessorDao professorDao;
37

38
	private Map<String, OAuthHandler> handlers;
39

40
	public Map<String, OAuthHandler> getHandlers() {
41
		return handlers;
42
	}
43

44
	public void setHandlers(Map<String, OAuthHandler> handlers) {
45
		this.handlers = handlers;
46
	}
47

48
	public UserOpenIdDao getUserOpenIdDao() {
49
		return userOpenIdDao;
50
	}
51

52
	public void setUserOpenIdDao(UserOpenIdDao userOpenIdDao) {
53
		this.userOpenIdDao = userOpenIdDao;
54
	}
55

56
	public UserDao getUserDao() {
57
		return userDao;
58
	}
59

60
	public void setUserDao(UserDao userDao) {
61
		this.userDao = userDao;
62
	}
63

64
	public long getExpriesWithOpenId() {
65
		return expriesWithOpenId;
66
	}
67

68
	public void setExpriesWithOpenId(long expriesWithOpenId) {
69
		this.expriesWithOpenId = expriesWithOpenId;
70
	}
71

72
	public ProfessorDao getProfessorDao() {
73
		return professorDao;
74
	}
75

76
	public void setProfessorDao(ProfessorDao professorDao) {
77
		this.professorDao = professorDao;
78
	}
79

80
	@Get
81
	@Path("/validCode")
82
	public AuthLoginResponse validCode(@JdbcConn Connection con, String code, String state) throws SQLException, JfwBaseException {
83
		OAuthHandler oah = this.handlers.get(state);
84
		if (oah == null)
85
			throw new IllegalArgumentException("非法的参数{state=" + state);
86
		OAuthUser ou = oah.login(code);
87
		UserOpenId uoi = this.userOpenIdDao.queryByOpenid(con, oah.getType(), ou.getOpenId());
88

89
		StateCode<OAuthUser, UserOpenId> sc = new StateCode<OAuthUser, UserOpenId>();
90
		final String key = JfwAppContext.cacheObjectAndGenKey(sc);
91
		sc.setKey(ou);
92
		sc.setValue(uoi);
93
		sc.setBuildTime(System.currentTimeMillis());
94
		sc.setExpiredTime(sc.getBuildTime() + this.expriesWithOpenId);
95
		JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
96
			@Override
97
			public void run() {
98
				JfwAppContext.removeCachedObject(key);
99
			}
100
		}, this.expriesWithOpenId, TimeUnit.MILLISECONDS);
101
		AuthLoginResponse alr = new AuthLoginResponse();
102
		alr.setAssociated(null != uoi);
103
		alr.setAuthCode(key);
104
		return alr;
105
	}
106

107
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
108
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
109
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
110
	@Post
111
	@Path("/login")
112
	public SessionUser login(@JdbcConn Connection con, String authCode) throws SQLException, JfwBaseException {
113
		@SuppressWarnings("unchecked")
114
		StateCode<OAuthUser, UserOpenId> sc = (StateCode<OAuthUser, UserOpenId>) JfwAppContext.getCachedObject(authCode);
115

116
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
117
			throw new JfwBaseException(-1, "authCode is expired");
118
		if (null == sc.getValue())
119
			throw new JfwBaseException(-2, "authCode is invalid openid not associate local user");
120

121
		User user = this.userDao.query(con, sc.getValue().getUserid());
122
		if (null == user)
123
			return null;
124
		
125
		JfwAppContext.removeCachedObject(authCode);
126
		SessionUser ret = new SessionUser();
127
		ret.setId(user.getId());
128
		if (null != this.professorDao.query(con, user.getId())) {
129
			ret.setName(this.professorDao.query(con, user.getId()).getName());
130
		}
131
		ret.setMobilePhone(user.getMobilePhone());
132
		ret.setType(user.getUserType());
133
		ret.setEmail(user.getEmail());
134
		ret.setAuth(true);
135
		return ret;
136
	}
137

138
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
139
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
140
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
141
	@Post
142
	@Path("/openidLogin")
143
	public SessionUser openidLogin(@JdbcConn Connection con, String openid, String oauthType) throws SQLException, JfwBaseException {
144
		if (null == this.handlers.get(oauthType)) {
145
			throw new JfwBaseException(-1, "invalid oauthType");
146
		}
147
		UserOpenId uoi = this.userOpenIdDao.queryByOpenid(con, oauthType, openid);
148
		if (uoi != null) {
149
			User user = this.userDao.query(con, uoi.getUserid());
150
			if (user != null) {
151
				SessionUser ret = new SessionUser();
152
				ret.setId(user.getId());
153
				if (null != this.professorDao.query(con, user.getId())) {
154
					ret.setName(this.professorDao.query(con, user.getId()).getName());
155
				}
156
				ret.setMobilePhone(user.getMobilePhone());
157
				ret.setType(user.getUserType());
158
				ret.setEmail(user.getEmail());
159
				ret.setAuth(true);
160
				return ret;
161
			}
162
		}
163
		return null;
164
	}
165

166
	@Post
167
	@Path("/associate")
168
	public void associate(@JdbcConn(false) Connection con, String userid, String openid, String oauthType) throws SQLException, JfwBaseException {
169
		if (null == this.handlers.get(oauthType)) {
170
			throw new JfwBaseException(-1, "invalid oauthType");
171
		}
172
		UserOpenId uoi = new UserOpenId();
173
		uoi.setOauthType(oauthType);
174
		uoi.setUserid(userid);
175
		uoi.setOpenid(openid);
176
		try {
177
			userOpenIdDao.insert(con, uoi);
178
			con.commit();
179
		} catch (SQLException e) {
180
			if ("23505".equals(e.getSQLState())) {
181
				try {
182
					con.rollback();
183
				} catch (Throwable th) {
184
				}
185
				throw new JfwBaseException(-2, "duplicate associate");
186
			} else {
187
				throw e;
188
			}
189
		}
190
	}
191
	
192
	
193
	
194
	@Post
195
	@Path("/checkAssociated")
196
	public boolean associcated(@JdbcConn(false) Connection con,String userid,String oauthType)throws SQLException,JfwBaseException{
197
		if (null == this.handlers.get(oauthType)) {
198
			throw new JfwBaseException(-1, "invalid oauthType");
199
		}
200
		return userOpenIdDao.queryByUserid(con, oauthType, userid)!=null;
201
	}
202

203
	@Post
204
	@Path("/validOpenid")
205
	public AuthLoginResponse validOpenid(@JdbcConn Connection con, String authType, String openid) throws SQLException, JfwBaseException {
206
		OAuthUser ou = new OAuthUser();
207
		ou.setType(authType);
208
		ou.setOpenId(openid);
209
		UserOpenId uoi = this.userOpenIdDao.queryByOpenid(con, authType, openid);
210
		AuthLoginResponse alr = new AuthLoginResponse();
211
		StateCode<OAuthUser, UserOpenId> sc = new StateCode<OAuthUser, UserOpenId>();
212
		final String key = JfwAppContext.cacheObjectAndGenKey(sc);
213
		sc.setKey(ou);
214
		sc.setValue(uoi);
215
		sc.setBuildTime(System.currentTimeMillis());
216
		sc.setExpiredTime(sc.getBuildTime() + this.expriesWithOpenId);
217
		JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
218
			@Override
219
			public void run() {
220
				JfwAppContext.removeCachedObject(key);
221
			}
222
		}, this.expriesWithOpenId, TimeUnit.MILLISECONDS);
223
		alr.setAssociated(null != uoi);
224
		alr.setAuthCode(key);
225
		return alr;
226
	}
227

228
	@Get
229
	@Path("/redirectUris")
230
	public Map<String, String> getRedirectUris() {
231
		Map<String, String> ret = new HashMap<String, String>();
232
		for (Map.Entry<String, OAuthHandler> h : this.handlers.entrySet()) {
233
			ret.put(h.getKey(), h.getValue().getLoginUrl());
234
		}
235
		return ret;
236
	}
237

238
	public static class AuthLoginResponse {
239
		private boolean associated;
240
		private String authCode;
241

242
		public boolean isAssociated() {
243
			return associated;
244
		}
245

246
		public void setAssociated(boolean associated) {
247
			this.associated = associated;
248
		}
249

250
		public String getAuthCode() {
251
			return authCode;
252
		}
253

254
		public void setAuthCode(String authCode) {
255
			this.authCode = authCode;
256
		}
257
	}
194

258

195
}
259
}

+ 193 - 104
src/main/java/com/ekexiu/portal/service/SysService.java

31
import com.ekexiu.portal.dao.OrgUserDao;
31
import com.ekexiu.portal.dao.OrgUserDao;
32
import com.ekexiu.portal.dao.ProfessorDao;
32
import com.ekexiu.portal.dao.ProfessorDao;
33
import com.ekexiu.portal.dao.UserDao;
33
import com.ekexiu.portal.dao.UserDao;
34
import com.ekexiu.portal.dao.UserOpenIdDao;
34
import com.ekexiu.portal.mail.MailService;
35
import com.ekexiu.portal.mail.MailService;
35
import com.ekexiu.portal.mobile.MobilePhoneService;
36
import com.ekexiu.portal.mobile.MobilePhoneService;
37
import com.ekexiu.portal.oauth.OAuthService;
38
import com.ekexiu.portal.oauth.OAuthUser;
36
import com.ekexiu.portal.po.OrgUser;
39
import com.ekexiu.portal.po.OrgUser;
37
import com.ekexiu.portal.po.Organization;
40
import com.ekexiu.portal.po.Organization;
38
import com.ekexiu.portal.po.Professor;
41
import com.ekexiu.portal.po.Professor;
39
import com.ekexiu.portal.po.User;
42
import com.ekexiu.portal.po.User;
43
import com.ekexiu.portal.po.UserOpenId;
40
import com.ekexiu.portal.pojo.SessionUser;
44
import com.ekexiu.portal.pojo.SessionUser;
41
45
42
@Path
46
@Path
65
	private GrowthLogService growthLogService;
69
	private GrowthLogService growthLogService;
66
	@Autowrie
70
	@Autowrie
67
	private GrowthRuleService rule;
71
	private GrowthRuleService rule;
72
	@Autowrie
73
	private OAuthService oauthService;
74
	@Autowrie
75
	private UserOpenIdDao userOpenIdDao;
68
76
69
	private String bindMailSubject;
77
	private String bindMailSubject;
70
78
71
	private String bindMailReplaceKey;
79
	private String bindMailReplaceKey;
72
	private String bindMailReplaceContentTempalte;
80
	private String bindMailReplaceContentTempalte;
73
	private long timeLimitWithBindMail = 10 * 60 * 1000;
81
	private long timeLimitWithBindMail = 10 * 60 * 1000;
74
	
75
	private String bindOrgMailReplaceKey; 
76
	private String bindOrgMailSubject; 
82
83
	private String bindOrgMailReplaceKey;
84
	private String bindOrgMailSubject;
77
	private String bindOrgMailReplaceContentTempalte;
85
	private String bindOrgMailReplaceContentTempalte;
78
	private long timeLimitWithBindOrgMail = 10 * 60 * 1000;
86
	private long timeLimitWithBindOrgMail = 10 * 60 * 1000;
79
87
81
	private String regMailReplaceKey;
89
	private String regMailReplaceKey;
82
	private String regMailReplaceContentTempalte;
90
	private String regMailReplaceContentTempalte;
83
	private long timeLimitWithRegMail = 10 * 60 * 1000;
91
	private long timeLimitWithRegMail = 10 * 60 * 1000;
84
	
92
85
	private String orgRegMailSubject = "注册[科袖网]企业用户";
93
	private String orgRegMailSubject = "注册[科袖网]企业用户";
86
	private String orgRegMailReplaceKey;
94
	private String orgRegMailReplaceKey;
87
	private String orgRegMailReplaceContentTempalte;
95
	private String orgRegMailReplaceContentTempalte;
88
	private long timeLimitWithOrgRegMail = 10 * 60 * 1000;
96
	private long timeLimitWithOrgRegMail = 10 * 60 * 1000;
89
	
97
90
	private String sendConsultMailSubject;
98
	private String sendConsultMailSubject;
91
	private String sendConsultMailContentTemplate;
99
	private String sendConsultMailContentTemplate;
92
	private String sendConsultSMSContentTemplate;
100
	private String sendConsultSMSContentTemplate;
103
	private String mailRetrievePasswordReplaceKey;
111
	private String mailRetrievePasswordReplaceKey;
104
	private String mailRetrievePasswordSubject;
112
	private String mailRetrievePasswordSubject;
105
	private long timeLimitWithMailRetrivePassword = 10 * 60 * 1000;
113
	private long timeLimitWithMailRetrivePassword = 10 * 60 * 1000;
106
	
114
107
	private String orgMailRetrievePasswordContentTemplate;
115
	private String orgMailRetrievePasswordContentTemplate;
108
	private String orgMailRetrievePasswordReplaceKey;
116
	private String orgMailRetrievePasswordReplaceKey;
109
	private String orgMailRetrievePasswordSubject;
117
	private String orgMailRetrievePasswordSubject;
112
	private String regMobilePhoneReplaceKey;
120
	private String regMobilePhoneReplaceKey;
113
	private String regMobilePhoneContentTemplate;
121
	private String regMobilePhoneContentTemplate;
114
	private long timeLimitWithRegMobilePhone = 3 * 60 * 1000;
122
	private long timeLimitWithRegMobilePhone = 3 * 60 * 1000;
115
	
123
116
	private String loginMobilePhoneReplaceKey;
124
	private String loginMobilePhoneReplaceKey;
117
	private String loginMobilePhoneContentTemplate;
125
	private String loginMobilePhoneContentTemplate;
118
	private long timeLimitWithLoginMobilePhone = 3 * 60 * 1000;
126
	private long timeLimitWithLoginMobilePhone = 3 * 60 * 1000;
124
	private String inviteReplaceCode = "invitCodeKey";
132
	private String inviteReplaceCode = "invitCodeKey";
125
	private String inviteMailSubject = "[ 科袖网 ]特邀科研专家邀请函";
133
	private String inviteMailSubject = "[ 科袖网 ]特邀科研专家邀请函";
126
	private String inviteMailContentTempalte;
134
	private String inviteMailContentTempalte;
127
	
135
128
	private String inviteStaffReplaceKey = "stateCode";
136
	private String inviteStaffReplaceKey = "stateCode";
129
	private String inviteStaffMailTempalte;
137
	private String inviteStaffMailTempalte;
130
	private String inviteStaffOrgKey = "orgKey";
138
	private String inviteStaffOrgKey = "orgKey";
131
	private String inviteStaffSubject = "[ 科袖网 ]企业员工邀请函";
139
	private String inviteStaffSubject = "[ 科袖网 ]企业员工邀请函";
132
	
140
133
	private String retrieveOrgSuccessTempalte;
141
	private String retrieveOrgSuccessTempalte;
134
	private String retrieveOrgSuccessSubject;
142
	private String retrieveOrgSuccessSubject;
135
	private String retrieveOrgFailTempalte;
143
	private String retrieveOrgFailTempalte;
647
		this.retrieveOrgFailSubject = retrieveOrgFailSubject;
655
		this.retrieveOrgFailSubject = retrieveOrgFailSubject;
648
	}
656
	}
649
657
658
	public OAuthService getOauthService() {
659
		return oauthService;
660
	}
661
662
	public void setOauthService(OAuthService oauthService) {
663
		this.oauthService = oauthService;
664
	}
665
666
	public UserOpenIdDao getUserOpenIdDao() {
667
		return userOpenIdDao;
668
	}
669
670
	public void setUserOpenIdDao(UserOpenIdDao userOpenIdDao) {
671
		this.userOpenIdDao = userOpenIdDao;
672
	}
673
650
	/**
674
	/**
651
	 * 验证注册时填写的手机号和邮箱是否已经注册过
675
	 * 验证注册时填写的手机号和邮箱是否已经注册过
652
	 * 
676
	 * 
666
			return true;
690
			return true;
667
		}
691
		}
668
	}
692
	}
669
	
693
670
	@Get
694
	@Get
671
	@Path("/isRegOrg")
695
	@Path("/isRegOrg")
672
	public boolean isRegOrg(@JdbcConn Connection con,String email)throws SQLException{
696
	public boolean isRegOrg(@JdbcConn Connection con, String email) throws SQLException {
673
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, email);
697
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, email);
674
		if(null != orgUser){
698
		if (null != orgUser) {
675
			return false;
699
			return false;
676
		}else{
700
		} else {
677
			return true;
701
			return true;
678
		}
702
		}
679
	}
703
	}
680
	
704
681
	@Get
705
	@Get
682
	@Path("/isOrgUser")
706
	@Path("/isOrgUser")
683
	public boolean isOrgUser(@JdbcConn Connection con,String orgName)throws SQLException, JfwBaseException{
707
	public boolean isOrgUser(@JdbcConn Connection con, String orgName) throws SQLException, JfwBaseException {
684
		String orgId = this.orgDao.queryByName(con, orgName);
708
		String orgId = this.orgDao.queryByName(con, orgName);
685
		if(orgId == null){
709
		if (orgId == null) {
686
			return true;
710
			return true;
687
		}else{
688
			if(this.orgUserDao.queryOne(con, orgId) == null){
711
		} else {
712
			if (this.orgUserDao.queryOne(con, orgId) == null) {
689
				return true;
713
				return true;
690
			}else{
714
			} else {
691
				String authStatus = (this.orgDao.query(con, orgId)).getAuthStatus();
715
				String authStatus = (this.orgDao.query(con, orgId)).getAuthStatus();
692
				if("3".equals(authStatus)){
716
				if ("3".equals(authStatus)) {
693
					throw new JfwBaseException(3, "该企业为科袖认证企业");
717
					throw new JfwBaseException(3, "该企业为科袖认证企业");
694
				}else if("2".equals(authStatus)){
718
				} else if ("2".equals(authStatus)) {
695
					throw new JfwBaseException(4, "该企业正在进行认证审核");
719
					throw new JfwBaseException(4, "该企业正在进行认证审核");
696
				}else{
720
				} else {
697
					throw new JfwBaseException(2, "该企业已注册科袖账号");
721
					throw new JfwBaseException(2, "该企业已注册科袖账号");
698
				}
722
				}
699
			}
723
			}
729
	 */
753
	 */
730
	@Post
754
	@Post
731
	@Path("/regmobile")
755
	@Path("/regmobile")
732
	public String regMobile(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, 
733
			String password, @Nullable String inviterId)throws SQLException, JfwBaseException {
756
	public String regMobile(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId) throws SQLException, JfwBaseException {
734
		@SuppressWarnings("unchecked")
757
		@SuppressWarnings("unchecked")
735
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
758
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
736
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
759
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
748
			user.setMobilePhone(mobilePhone);
771
			user.setMobilePhone(mobilePhone);
749
			user.setPasswd(passwd);
772
			user.setPasswd(passwd);
750
			user.setUserType("0");
773
			user.setUserType("0");
751
	        user.setInviterId(inviterId);
752
	        user.setActiveTime(DATE.format(new Date()));
774
			user.setInviterId(inviterId);
775
			user.setActiveTime(DATE.format(new Date()));
753
			this.userDao.insert(con, user);
776
			this.userDao.insert(con, user);
754
			if(inviterId != null){
777
			if (inviterId != null) {
755
				this.growthLogService.invite(con, inviterId, user.getId());
778
				this.growthLogService.invite(con, inviterId, user.getId());
756
			}
779
			}
757
			return user.getId();
780
			return user.getId();
759
			JfwAppContext.removeCachedObject(state);
782
			JfwAppContext.removeCachedObject(state);
760
		}
783
		}
761
	}
784
	}
762
	
785
786
	private void associatedOpenId(Connection con, User user, String oauthType, String openid, String authCode) throws SQLException, JfwBaseException {
787
		if (oauthType != null) {
788
			if (oauthService.getHandlers().get(oauthType) == null) {
789
				throw new JfwBaseException(-4, "invalid oautyType");
790
			}
791
			if (openid != null) {
792
				UserOpenId uoi = new UserOpenId();
793
				uoi.setOauthType(oauthType);
794
				uoi.setOpenid(openid);
795
				uoi.setUserid(user.getId());
796
				try {
797
					userOpenIdDao.insert(con, uoi);
798
				} catch (SQLException e) {
799
					if ("23505".equals(e.getSQLState())) {
800
						throw new JfwBaseException(-6, "associated openid");
801
					}
802
					throw e;
803
				}
804
805
			} else {
806
				throw new JfwBaseException(-5, "关链第三方登录时,OPENID不可都为空");
807
			}
808
		} else if (null != authCode) {
809
			@SuppressWarnings("unchecked")
810
			StateCode<OAuthUser, UserOpenId> ac = (StateCode<OAuthUser, UserOpenId>) JfwAppContext.getCachedObject(authCode);
811
			if (ac == null || ac.getExpiredTime() < System.currentTimeMillis())
812
				throw new JfwBaseException(-7, "authCode is expired");
813
			OAuthUser ou = ac.getKey();
814
			openid = ou.getOpenId();
815
			oauthType = ou.getType();
816
			UserOpenId uoi = new UserOpenId();
817
			uoi.setOauthType(oauthType);
818
			uoi.setOpenid(openid);
819
			uoi.setUserid(user.getId());
820
			try {
821
				userOpenIdDao.insert(con, uoi);
822
				JfwAppContext.removeCachedObject(authCode);
823
			} catch (SQLException e) {
824
				if ("23505".equals(e.getSQLState())) {
825
					throw new JfwBaseException(-8, "associated openid");
826
				}
827
				throw e;
828
			}
829
830
		}
831
	}
832
763
	@Post
833
	@Post
764
	@Path("/mobileReg")
834
	@Path("/mobileReg")
765
	public String mobileReg(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, 
766
			String password, @Nullable String inviterId, String name)throws SQLException, JfwBaseException, IOException {
835
	public String mobileReg(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId,
836
			String name,	@Nullable String oauthType, @Nullable String openid, @Nullable String authCode) throws SQLException, JfwBaseException, IOException {
767
		@SuppressWarnings("unchecked")
837
		@SuppressWarnings("unchecked")
768
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
838
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
769
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
839
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
781
			user.setMobilePhone(mobilePhone);
851
			user.setMobilePhone(mobilePhone);
782
			user.setPasswd(passwd);
852
			user.setPasswd(passwd);
783
			user.setUserType("0");
853
			user.setUserType("0");
784
	        user.setInviterId(inviterId);
785
	        user.setActiveTime(DATE.format(new Date()));
854
			user.setInviterId(inviterId);
855
			user.setActiveTime(DATE.format(new Date()));
786
			this.userDao.insert(con, user);
856
			this.userDao.insert(con, user);
787
			if(inviterId != null){
857
			this.associatedOpenId(con, user, oauthType, openid, authCode);
858
			if (inviterId != null) {
788
				this.growthLogService.invite(con, inviterId, user.getId());
859
				this.growthLogService.invite(con, inviterId, user.getId());
789
			}
860
			}
790
			Professor professor = new Professor();
861
			Professor professor = new Professor();
791
			professor.setId(user.getId());
862
			professor.setId(user.getId());
792
			professor.setName(name);
863
			professor.setName(name);
864
			professor.setAuthentication(-1);
793
			this.professorService.insert(con, professor, null);
865
			this.professorService.insert(con, professor, null);
794
			return user.getId();
866
			return user.getId();
795
		} finally {
867
		} finally {
827
			user.setActiveTime(DATE.format(new Date()));
899
			user.setActiveTime(DATE.format(new Date()));
828
			this.userDao.insert(con, user);
900
			this.userDao.insert(con, user);
829
			con.commit();
901
			con.commit();
830
			if(sc.getValue() != null){
902
			if (sc.getValue() != null) {
831
				this.growthLogService.invite(con, sc.getValue(), user.getId());
903
				this.growthLogService.invite(con, sc.getValue(), user.getId());
832
			}
904
			}
833
		} catch (SQLException e) {
905
		} catch (SQLException e) {
843
			JfwAppContext.removeCachedObject(key);
915
			JfwAppContext.removeCachedObject(key);
844
		}
916
		}
845
	}
917
	}
846
	
918
847
	@Get
919
	@Get
848
	@Path("/mailReg")
920
	@Path("/mailReg")
849
	public void emailReg(@JdbcConn(false) Connection con, String key) throws SQLException, JfwBaseException, IOException {
921
	public void emailReg(@JdbcConn(false) Connection con, String key) throws SQLException, JfwBaseException, IOException {
862
			user.setInviterId(sc.getValue());
934
			user.setInviterId(sc.getValue());
863
			user.setActiveTime(DATE.format(new Date()));
935
			user.setActiveTime(DATE.format(new Date()));
864
			this.userDao.insert(con, user);
936
			this.userDao.insert(con, user);
865
			if(sc.getValue() != null){
937
			if (sc.getValue() != null) {
866
				this.growthLogService.invite(con, sc.getValue(), user.getId());
938
				this.growthLogService.invite(con, sc.getValue(), user.getId());
867
			}
939
			}
868
			Professor professor = new Professor();
940
			Professor professor = new Professor();
869
			professor.setId(user.getId());
941
			professor.setId(user.getId());
870
			professor.setName(sc.getDescp());
942
			professor.setName(sc.getDescp());
943
			professor.setAuthentication(-1);
871
			this.professorService.insert(con, professor, null);
944
			this.professorService.insert(con, professor, null);
872
			con.commit();
945
			con.commit();
873
		} catch (SQLException e) {
946
		} catch (SQLException e) {
897
	 */
970
	 */
898
	@Post
971
	@Post
899
	@Path("/regmail")
972
	@Path("/regmail")
900
	public void regMail(@JdbcConn(false) Connection con,String mail,String password,@Nullable String inviterId)throws JfwBaseException, SQLException {
973
	public void regMail(@JdbcConn(false) Connection con, String mail, String password, @Nullable String inviterId) throws JfwBaseException, SQLException {
901
		User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
974
		User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
902
		if (null != user) {
975
		if (null != user) {
903
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
976
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
926
			}, this.timeLimitWithRegMail, TimeUnit.MILLISECONDS);
999
			}, this.timeLimitWithRegMail, TimeUnit.MILLISECONDS);
927
		}
1000
		}
928
	}
1001
	}
929
	
1002
930
	@Post
1003
	@Post
931
	@Path("/emailReg")
1004
	@Path("/emailReg")
932
	public void emailReg(@JdbcConn(false) Connection con,String mail,String password,@Nullable String inviterId,String name)throws JfwBaseException, SQLException {
1005
	public void emailReg(@JdbcConn(false) Connection con, String mail, String password, @Nullable String inviterId, String name)
1006
			throws JfwBaseException, SQLException {
933
		User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
1007
		User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
934
		if (null != user) {
1008
		if (null != user) {
935
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
1009
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
959
			}, this.timeLimitWithRegMail, TimeUnit.MILLISECONDS);
1033
			}, this.timeLimitWithRegMail, TimeUnit.MILLISECONDS);
960
		}
1034
		}
961
	}
1035
	}
962
	
1036
963
	/**
1037
	/**
964
	 * 验证企业邮箱并注册企业账号
1038
	 * 验证企业邮箱并注册企业账号
1039
	 * 
965
	 * @param con
1040
	 * @param con
966
	 * @param key 邮箱验证的返回值
1041
	 * @param key
1042
	 *            邮箱验证的返回值
967
	 * @throws SQLException
1043
	 * @throws SQLException
968
	 * @throws JfwBaseException
1044
	 * @throws JfwBaseException
969
	 * @throws IOException
1045
	 * @throws IOException
977
			throw new JfwBaseException(-1, "验证链接已失效");
1053
			throw new JfwBaseException(-1, "验证链接已失效");
978
		}
1054
		}
979
		String orgId = this.orgDao.queryByName(con, sc.getValue());
1055
		String orgId = this.orgDao.queryByName(con, sc.getValue());
980
		if((orgId != null) && (this.orgUserDao.queryOne(con, orgId)!= null)){
1056
		if ((orgId != null) && (this.orgUserDao.queryOne(con, orgId) != null)) {
981
			throw new JfwBaseException(2, "该企业已注册科袖账号");
1057
			throw new JfwBaseException(2, "该企业已注册科袖账号");
982
		}
1058
		}
983
		try {
1059
		try {
984
			OrgUser orgUser = new OrgUser();
1060
			OrgUser orgUser = new OrgUser();
985
			orgUser.setEmail(sc.getCode());
1061
			orgUser.setEmail(sc.getCode());
986
			if(orgId != null){
1062
			if (orgId != null) {
987
				orgUser.setId(orgId);
1063
				orgUser.setId(orgId);
988
			}else{
1064
			} else {
989
				orgUser.setId(this.orgService.createOrganization(con, sc.getValue()));
1065
				orgUser.setId(this.orgService.createOrganization(con, sc.getValue()));
990
			}
1066
			}
991
			orgUser.setPasswd(StringUtil.md5(sc.getKey()));
1067
			orgUser.setPasswd(StringUtil.md5(sc.getKey()));
1006
			JfwAppContext.removeCachedObject(key);
1082
			JfwAppContext.removeCachedObject(key);
1007
		}
1083
		}
1008
	}
1084
	}
1009
	
1085
1010
	/**
1086
	/**
1011
	 * 给注册的企业邮箱发送验证邮件
1087
	 * 给注册的企业邮箱发送验证邮件
1088
	 * 
1012
	 * @param con
1089
	 * @param con
1013
	 * @param orgName 企业名称
1014
	 * @param mail 企业邮箱
1015
	 * @param password 密码
1090
	 * @param orgName
1091
	 *            企业名称
1092
	 * @param mail
1093
	 *            企业邮箱
1094
	 * @param password
1095
	 *            密码
1016
	 * @throws JfwBaseException
1096
	 * @throws JfwBaseException
1017
	 * @throws SQLException
1097
	 * @throws SQLException
1018
	 */
1098
	 */
1019
	@Post
1099
	@Post
1020
	@Path("/regOrgMail")
1100
	@Path("/regOrgMail")
1021
	public void regOrgMail(@JdbcConn(false) Connection con,String orgName,String mail,String password)throws JfwBaseException, SQLException {
1101
	public void regOrgMail(@JdbcConn(false) Connection con, String orgName, String mail, String password) throws JfwBaseException, SQLException {
1022
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, mail);
1102
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, mail);
1023
		if (null != orgUser) {
1103
		if (null != orgUser) {
1024
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
1104
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
1074
		this.mailservice.sendSimpleMail(user.getEmail(), mailContent, null, this.inviteMailSubject);
1154
		this.mailservice.sendSimpleMail(user.getEmail(), mailContent, null, this.inviteMailSubject);
1075
		return "send success !";
1155
		return "send success !";
1076
	}
1156
	}
1077
	
1157
1078
	@Post
1158
	@Post
1079
	@Path("/inviteStaff/{key}")
1159
	@Path("/inviteStaff/{key}")
1080
	public Map<String, String> inviteStaff(@JdbcConn Connection con,@PathVar String key)throws SQLException, JfwBaseException{
1160
	public Map<String, String> inviteStaff(@JdbcConn Connection con, @PathVar String key) throws SQLException, JfwBaseException {
1081
		@SuppressWarnings("unchecked")
1161
		@SuppressWarnings("unchecked")
1082
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
1162
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
1083
		if(sc == null){
1163
		if (sc == null) {
1084
			throw new JfwBaseException(-1, "验证链接已失效");
1164
			throw new JfwBaseException(-1, "验证链接已失效");
1085
		}
1165
		}
1086
		Organization org = this.orgDao.query(con, sc.getKey());
1166
		Organization org = this.orgDao.query(con, sc.getKey());
1087
		if(org == null){
1167
		if (org == null) {
1088
			throw new JfwBaseException(-2, "不存在的企业");
1168
			throw new JfwBaseException(-2, "不存在的企业");
1089
		}
1169
		}
1090
		Map<String, String> map = new HashMap<String, String>();
1170
		Map<String, String> map = new HashMap<String, String>();
1092
		map.put("orgName", org.getName());
1172
		map.put("orgName", org.getName());
1093
		map.put("email", sc.getValue());
1173
		map.put("email", sc.getValue());
1094
		return map;
1174
		return map;
1095
		
1175
1096
	}
1176
	}
1097
	
1177
1098
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1178
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1099
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
1179
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
1100
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1180
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1101
	@Post
1181
	@Post
1102
	@Path("/regInviteStaff")
1182
	@Path("/regInviteStaff")
1103
	@SuppressWarnings("unchecked")
1183
	@SuppressWarnings("unchecked")
1104
	public SessionUser regInviteStaff(@JdbcConn(true) Connection con,String key,String state,String phone,String validateCode,String name,String passwd)throws SQLException, JfwBaseException{
1184
	public SessionUser regInviteStaff(@JdbcConn(true) Connection con, String key, String state, String phone, String validateCode, String name, String passwd)
1185
			throws SQLException, JfwBaseException {
1105
		StateCode<String, String> stateCode = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
1186
		StateCode<String, String> stateCode = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
1106
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
1187
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
1107
		if (stateCode == null) {
1188
		if (stateCode == null) {
1124
			user.setEmail(stateCode.getValue());
1205
			user.setEmail(stateCode.getValue());
1125
			user.setPasswd(StringUtil.md5(passwd));
1206
			user.setPasswd(StringUtil.md5(passwd));
1126
			user.setUserType("0");
1207
			user.setUserType("0");
1127
	        user.setActiveTime(DATE.format(new Date()));
1128
	        this.userDao.insert(con, user);
1129
	        Professor professor = new Professor();
1130
	        professor.setId(id);
1131
	        professor.setName(name);
1132
	        professor.setOrgId(stateCode.getKey());
1133
	        professor.setOrgAuth("1");
1208
			user.setActiveTime(DATE.format(new Date()));
1209
			this.userDao.insert(con, user);
1210
			Professor professor = new Professor();
1211
			professor.setId(id);
1212
			professor.setName(name);
1213
			professor.setOrgId(stateCode.getKey());
1214
			professor.setOrgAuth("1");
1134
			professor.setPhone(user.getMobilePhone());
1215
			professor.setPhone(user.getMobilePhone());
1135
			professor.setEmail(user.getEmail());
1216
			professor.setEmail(user.getEmail());
1136
			int value = 0;
1217
			int value = 0;
1137
			if(user.getMobilePhone() != null && user.getMobilePhone().trim().length() == 11){
1218
			if (user.getMobilePhone() != null && user.getMobilePhone().trim().length() == 11) {
1138
				professor.setPhone(user.getMobilePhone());
1219
				professor.setPhone(user.getMobilePhone());
1139
				value = value + this.rule.getBindMobile();
1220
				value = value + this.rule.getBindMobile();
1140
				this.growthLogService.firstBindMobile(con, professor.getId());
1221
				this.growthLogService.firstBindMobile(con, professor.getId());
1141
			}
1222
			}
1142
			if(user.getEmail() != null && !"".equals(user.getEmail())){
1223
			if (user.getEmail() != null && !"".equals(user.getEmail())) {
1143
				professor.setEmail(user.getEmail());
1224
				professor.setEmail(user.getEmail());
1144
				value = value + this.rule.getBindEmail();
1225
				value = value + this.rule.getBindEmail();
1145
				this.growthLogService.firstBindEmail(con, professor.getId());
1226
				this.growthLogService.firstBindEmail(con, professor.getId());
1160
			JfwAppContext.removeCachedObject(state);
1241
			JfwAppContext.removeCachedObject(state);
1161
		}
1242
		}
1162
	}
1243
	}
1163
	
1244
1164
	@Get
1245
	@Get
1165
	@Path("/inviteStaffMail")
1246
	@Path("/inviteStaffMail")
1166
	public boolean inviteStaffMail(@JdbcConn(false) Connection con,String orgId,String mail) throws SQLException, JfwBaseException {
1247
	public boolean inviteStaffMail(@JdbcConn(false) Connection con, String orgId, String mail) throws SQLException, JfwBaseException {
1167
		Organization org = this.orgDao.query(con, orgId);
1248
		Organization org = this.orgDao.query(con, orgId);
1168
		if(org == null){
1249
		if (org == null) {
1169
			throw new JfwBaseException(-1, "系统没有该企业");
1250
			throw new JfwBaseException(-1, "系统没有该企业");
1170
		}
1251
		}
1171
		StateCode<String, String> sc = new StateCode<String, String>();
1252
		StateCode<String, String> sc = new StateCode<String, String>();
1185
		sc.setCode(org.getName());
1266
		sc.setCode(org.getName());
1186
		return true;
1267
		return true;
1187
	}
1268
	}
1188
	
1269
1189
	@Post
1270
	@Post
1190
	@Path("/retrieveOrgSuccess")
1271
	@Path("/retrieveOrgSuccess")
1191
	public boolean retrieveOrgUserSuccess(@JdbcConn(false) Connection con,String mail) throws SQLException, JfwBaseException {
1272
	public boolean retrieveOrgUserSuccess(@JdbcConn(false) Connection con, String mail) throws SQLException, JfwBaseException {
1192
		try {
1273
		try {
1193
			this.mailservice.sendSimpleMail(mail, this.retrieveOrgSuccessTempalte, null, this.retrieveOrgSuccessSubject);
1274
			this.mailservice.sendSimpleMail(mail, this.retrieveOrgSuccessTempalte, null, this.retrieveOrgSuccessSubject);
1194
		} catch (MessagingException e) {
1275
		} catch (MessagingException e) {
1196
		}
1277
		}
1197
		return true;
1278
		return true;
1198
	}
1279
	}
1199
	
1280
1200
	@Post
1281
	@Post
1201
	@Path("/retrieveOrgFail")
1282
	@Path("/retrieveOrgFail")
1202
	public boolean retrieveOrgUserFail(@JdbcConn(false) Connection con,String mail) throws SQLException, JfwBaseException {
1283
	public boolean retrieveOrgUserFail(@JdbcConn(false) Connection con, String mail) throws SQLException, JfwBaseException {
1203
		try {
1284
		try {
1204
			this.mailservice.sendSimpleMail(mail, this.retrieveOrgFailTempalte, null, this.retrieveOrgFailSubject);
1285
			this.mailservice.sendSimpleMail(mail, this.retrieveOrgFailTempalte, null, this.retrieveOrgFailSubject);
1205
		} catch (MessagingException e) {
1286
		} catch (MessagingException e) {
1280
		ret.setAuth(true);
1361
		ret.setAuth(true);
1281
		return ret;
1362
		return ret;
1282
	}
1363
	}
1283
	
1364
1284
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1365
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
1285
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
1366
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
1286
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1367
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1287
	@Post
1368
	@Post
1288
	@Path("/mobileLogin")
1369
	@Path("/mobileLogin")
1289
	public SessionUser mobileLogin(@JdbcConn Connection con,String state,String mobilePhone,String validateCode)throws SQLException, JfwBaseException {
1370
	public SessionUser mobileLogin(@JdbcConn Connection con, String state, String mobilePhone, String validateCode) throws SQLException, JfwBaseException {
1290
		@SuppressWarnings("unchecked")
1371
		@SuppressWarnings("unchecked")
1291
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
1372
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
1292
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()){
1373
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
1293
			throw new JfwBaseException(-1, "验证超时");
1374
			throw new JfwBaseException(-1, "验证超时");
1294
		}
1375
		}
1295
		if (!sc.getKey().equals(mobilePhone)) {
1376
		if (!sc.getKey().equals(mobilePhone)) {
1299
			throw new JfwBaseException(-3, "验证码错误");
1380
			throw new JfwBaseException(-3, "验证码错误");
1300
		}
1381
		}
1301
		User user = userDao.queryByEmailOrMobilePhone(con, mobilePhone);
1382
		User user = userDao.queryByEmailOrMobilePhone(con, mobilePhone);
1302
		if (null == user){
1383
		if (null == user) {
1303
			throw new JfwBaseException(-4, "该用户还未注册");
1384
			throw new JfwBaseException(-4, "该用户还未注册");
1304
		}
1385
		}
1305
		try {
1386
		try {
1318
			JfwAppContext.removeCachedObject(state);
1399
			JfwAppContext.removeCachedObject(state);
1319
		}
1400
		}
1320
	}
1401
	}
1321
	
1322
	@SetCookie(checkResultNull = true, path = "/", value = { "orgId=result.getId()", "orgType=result.getType()",
1323
			"orgAuth=String.valueOf(result.isAuth())", "orgEmail=result.getEmail()==null?\"\":result.getEmail()",
1402
1403
	@SetCookie(checkResultNull = true, path = "/", value = { "orgId=result.getId()", "orgType=result.getType()", "orgAuth=String.valueOf(result.isAuth())",
1404
			"orgEmail=result.getEmail()==null?\"\":result.getEmail()",
1324
			"orgName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1405
			"orgName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
1325
	@Post
1406
	@Post
1326
	@Path("/orgLogin")
1407
	@Path("/orgLogin")
1334
		SessionUser ret = new SessionUser();
1415
		SessionUser ret = new SessionUser();
1335
		ret.setId(orgUser.getId());
1416
		ret.setId(orgUser.getId());
1336
		Organization org = this.orgDao.query(con, orgUser.getId());
1417
		Organization org = this.orgDao.query(con, orgUser.getId());
1337
		if(org != null){
1418
		if (org != null) {
1338
			ret.setName(org.getName());
1419
			ret.setName(org.getName());
1339
		}
1420
		}
1340
		ret.setType(orgUser.getUserType());
1421
		ret.setType(orgUser.getUserType());
1342
		ret.setAuth(true);
1423
		ret.setAuth(true);
1343
		return ret;
1424
		return ret;
1344
	}
1425
	}
1345
	
1426
1346
	@Post
1427
	@Post
1347
	@Path("/cp")
1428
	@Path("/cp")
1348
	public boolean changePw(@JdbcConn(true) Connection con, String id, String npw, @Nullable String onw) throws SQLException {
1429
	public boolean changePw(@JdbcConn(true) Connection con, String id, String npw, @Nullable String onw) throws SQLException {
1352
			return this.userDao.updatePasswd(con, StringUtil.md5(npw), id, StringUtil.md5(onw)) > 0;
1433
			return this.userDao.updatePasswd(con, StringUtil.md5(npw), id, StringUtil.md5(onw)) > 0;
1353
		}
1434
		}
1354
	}
1435
	}
1355
	
1436
1356
	@Post
1437
	@Post
1357
	@Path("/cpOrg")
1438
	@Path("/cpOrg")
1358
	public boolean changeOrgPw(@JdbcConn(true) Connection con, String id, String npw, String onw) throws SQLException {
1439
	public boolean changeOrgPw(@JdbcConn(true) Connection con, String id, String npw, String onw) throws SQLException {
1413
			JfwAppContext.removeCachedObject(key);
1494
			JfwAppContext.removeCachedObject(key);
1414
		}
1495
		}
1415
	}
1496
	}
1416
	
1497
1417
	@Get
1498
	@Get
1418
	@Path("/reqBindOrgMail")
1499
	@Path("/reqBindOrgMail")
1419
	public boolean reqBindOrgMail(@JdbcConn(false) Connection con, String id, String mail) throws JfwBaseException, SQLException {
1500
	public boolean reqBindOrgMail(@JdbcConn(false) Connection con, String id, String mail) throws JfwBaseException, SQLException {
1446
		}
1527
		}
1447
		return true;
1528
		return true;
1448
	}
1529
	}
1449
	
1530
1450
	@Get
1531
	@Get
1451
	@Path("/bindOrgMail/{key}")
1532
	@Path("/bindOrgMail/{key}")
1452
	public String bindOrgMail(@JdbcConn(true) Connection con, @PathVar String key) throws SQLException, JfwBaseException {
1533
	public String bindOrgMail(@JdbcConn(true) Connection con, @PathVar String key) throws SQLException, JfwBaseException {
1453
		@SuppressWarnings("unchecked")
1534
		@SuppressWarnings("unchecked")
1454
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
1535
		StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
1455
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()){
1536
		if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
1456
			throw new JfwBaseException(-1, "验证链接已失效");
1537
			throw new JfwBaseException(-1, "验证链接已失效");
1457
		}
1538
		}
1458
		try {
1539
		try {
1462
			JfwAppContext.removeCachedObject(key);
1543
			JfwAppContext.removeCachedObject(key);
1463
		}
1544
		}
1464
	}
1545
	}
1465
	
1546
1466
	@Get
1547
	@Get
1467
	@Path("/vcWithBind")
1548
	@Path("/vcWithBind")
1468
	public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone) throws JfwBaseException, SQLException {
1549
	public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone) throws JfwBaseException, SQLException {
1504
1585
1505
	/**
1586
	/**
1506
	 * 发送手机验证码
1587
	 * 发送手机验证码
1588
	 * 
1507
	 * @param con
1589
	 * @param con
1508
	 * @param mobilePhone 验证的手机号
1590
	 * @param mobilePhone
1591
	 *            验证的手机号
1509
	 * @return
1592
	 * @return
1510
	 * @throws JfwBaseException
1593
	 * @throws JfwBaseException
1511
	 * @throws SQLException
1594
	 * @throws SQLException
1542
		}
1625
		}
1543
		return key;
1626
		return key;
1544
	}
1627
	}
1545
	
1628
1546
	@Get
1629
	@Get
1547
	@Path("/sendMobileForLogin")
1630
	@Path("/sendMobileForLogin")
1548
	public String sendMobileForLogin(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
1631
	public String sendMobileForLogin(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
1747
			JfwAppContext.removeCachedObject(state);
1830
			JfwAppContext.removeCachedObject(state);
1748
		}
1831
		}
1749
	}
1832
	}
1750
	
1833
1751
	@Get
1834
	@Get
1752
	@Path("/resetWithOrgEmail")
1835
	@Path("/resetWithOrgEmail")
1753
	public boolean resetWithOrgEmail(@JdbcConn(false) Connection con, String mail) throws JfwBaseException, SQLException {
1836
	public boolean resetWithOrgEmail(@JdbcConn(false) Connection con, String mail) throws JfwBaseException, SQLException {
1795
			JfwAppContext.removeCachedObject(state);
1878
			JfwAppContext.removeCachedObject(state);
1796
		}
1879
		}
1797
	}
1880
	}
1798
	
1881
1799
	/**
1882
	/**
1800
	 * 给指定邮箱发送邀请邮件
1883
	 * 给指定邮箱发送邀请邮件
1884
	 * 
1801
	 * @param con
1885
	 * @param con
1802
	 * @param mobilePhones 手机号数组
1803
	 * @param emails 邮箱
1804
	 * @param inviteCodes 邀请码
1886
	 * @param mobilePhones
1887
	 *            手机号数组
1888
	 * @param emails
1889
	 *            邮箱
1890
	 * @param inviteCodes
1891
	 *            邀请码
1805
	 * @throws SQLException
1892
	 * @throws SQLException
1806
	 * @throws MessagingException
1893
	 * @throws MessagingException
1807
	 */
1894
	 */
1808
	@Post
1895
	@Post
1809
	@Path("/sendmail")
1896
	@Path("/sendmail")
1810
	public int sendmail(@JdbcConn Connection con,@Nullable String[] mobilePhones,String[] emails,String[] inviteCodes) throws SQLException, MessagingException{
1811
		for (int i = 0; i < emails.length; i++){
1812
			if(mobilePhones[i] == ""){
1897
	public int sendmail(@JdbcConn Connection con, @Nullable String[] mobilePhones, String[] emails, String[] inviteCodes)
1898
			throws SQLException, MessagingException {
1899
		for (int i = 0; i < emails.length; i++) {
1900
			if (mobilePhones[i] == "") {
1813
				mobilePhones[i] = null;
1901
				mobilePhones[i] = null;
1814
			}
1902
			}
1815
			this.sendInviteMail(con, emails[i], mobilePhones[i], inviteCodes[i]);
1903
			this.sendInviteMail(con, emails[i], mobilePhones[i], inviteCodes[i]);
1816
			this.logger.info("成功发送邀请邮件:"+emails[i]);
1904
			this.logger.info("成功发送邀请邮件:" + emails[i]);
1817
		}
1905
		}
1818
		return emails.length;
1906
		return emails.length;
1819
	}
1907
	}
1820
	
1821
	public void sendInviteMail(@JdbcConn Connection con,String email,@Nullable String mobilePhone,String inviteCode)throws SQLException, MessagingException{
1908
1909
	public void sendInviteMail(@JdbcConn Connection con, String email, @Nullable String mobilePhone, String inviteCode)
1910
			throws SQLException, MessagingException {
1822
		String mailContent = this.inviteMailContentTempalte;
1911
		String mailContent = this.inviteMailContentTempalte;
1823
		mailContent = mailContent.replaceAll(this.inviteReplaceEmail, email);
1912
		mailContent = mailContent.replaceAll(this.inviteReplaceEmail, email);
1824
		mailContent = mailContent.replaceAll(this.inviteReplaceCode, inviteCode);
1913
		mailContent = mailContent.replaceAll(this.inviteReplaceCode, inviteCode);
1831
		mailContent = mailContent.replaceAll(this.inviteReplacePhone, phoneReplace);
1920
		mailContent = mailContent.replaceAll(this.inviteReplacePhone, phoneReplace);
1832
		this.mailservice.sendSimpleMail(email, mailContent, null, this.inviteMailSubject);
1921
		this.mailservice.sendSimpleMail(email, mailContent, null, this.inviteMailSubject);
1833
	}
1922
	}
1834
	
1835
	public void sendConsultMail(String mail) throws SQLException, JfwBaseException{
1923
1924
	public void sendConsultMail(String mail) throws SQLException, JfwBaseException {
1836
		try {
1925
		try {
1837
			mailservice.sendSimpleMail(mail, this.sendConsultMailContentTemplate, null, this.sendConsultMailSubject);
1926
			mailservice.sendSimpleMail(mail, this.sendConsultMailContentTemplate, null, this.sendConsultMailSubject);
1838
		} catch (Exception e) {
1927
		} catch (Exception e) {
1839
			throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
1928
			throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
1840
		}
1929
		}
1841
	}
1930
	}
1842
	
1843
	public void sendConsultSMS(String mobilePhone) throws SQLException, JfwBaseException{
1931
1932
	public void sendConsultSMS(String mobilePhone) throws SQLException, JfwBaseException {
1844
		try {
1933
		try {
1845
			this.mobilePhoneServcie.sendMarketMessage(mobilePhone, this.sendConsultSMSContentTemplate);
1934
			this.mobilePhoneServcie.sendMarketMessage(mobilePhone, this.sendConsultSMSContentTemplate);
1846
		} catch (Exception e) {
1935
		} catch (Exception e) {
1847
			throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
1936
			throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
1848
		}
1937
		}
1849
	}
1938
	}
1850
	
1939
1851
	public static void main(String[] args) {
1940
	public static void main(String[] args) {
1852
		System.out.println(String.format("%04d", new Random().nextInt(10000)));
1941
		System.out.println(String.format("%04d", new Random().nextInt(10000)));
1853
	}
1942
	}

+ 4 - 0
src/main/resources/project-test-dev.properties

266
com_ekexiu_portal_service_GrowthRuleService.signInFourDays::int=8
266
com_ekexiu_portal_service_GrowthRuleService.signInFourDays::int=8
267
com_ekexiu_portal_service_GrowthRuleService.signInFiveDays::int=9
267
com_ekexiu_portal_service_GrowthRuleService.signInFiveDays::int=9
268
com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
268
com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
269
com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
270
oauthService_handlers::map=java.util.HashMap
271
oauthService_handlers.map-key-1=weixin
272
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler

+ 4 - 0
src/main/resources/project-test.properties

266
com_ekexiu_portal_service_GrowthRuleService.signInFourDays::int=8
266
com_ekexiu_portal_service_GrowthRuleService.signInFourDays::int=8
267
com_ekexiu_portal_service_GrowthRuleService.signInFiveDays::int=9
267
com_ekexiu_portal_service_GrowthRuleService.signInFiveDays::int=9
268
com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
268
com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
269
com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
270
oauthService_handlers::map=java.util.HashMap
271
oauthService_handlers.map-key-1=weixin
272
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler

+ 5 - 0
src/main/resources/project.properties

264
com_ekexiu_portal_service_GrowthRuleService.signInFourDays::int=8
264
com_ekexiu_portal_service_GrowthRuleService.signInFourDays::int=8
265
com_ekexiu_portal_service_GrowthRuleService.signInFiveDays::int=9
265
com_ekexiu_portal_service_GrowthRuleService.signInFiveDays::int=9
266
com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
266
com_ekexiu_portal_service_GrowthRuleService.signInSixDays::int=10
267
com_ekexiu_portal_oauth_OAuthService.handlers-ref=oauthService_handlers
268
oauthService_handlers::map=java.util.HashMap
269
oauthService_handlers.map-key-1=weixin
270
oauthService_handlers.map-val-1-ref=com_ekexiu_portal_oauth_weixin_WeiXinHandler
271