portal web service

SysService.java 64KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944
  1. package com.ekexiu.portal.service;
  2. import java.io.IOException;
  3. import java.sql.Connection;
  4. import java.sql.SQLException;
  5. import java.text.SimpleDateFormat;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.Map;
  9. import java.util.Random;
  10. import java.util.concurrent.TimeUnit;
  11. import javax.mail.MessagingException;
  12. import org.apache.log4j.Logger;
  13. import org.jfw.apt.annotation.Autowrie;
  14. import org.jfw.apt.annotation.Nullable;
  15. import org.jfw.apt.web.annotation.Path;
  16. import org.jfw.apt.web.annotation.method.SetCookie;
  17. import org.jfw.apt.web.annotation.operate.Get;
  18. import org.jfw.apt.web.annotation.operate.Post;
  19. import org.jfw.apt.web.annotation.param.JdbcConn;
  20. import org.jfw.apt.web.annotation.param.PathVar;
  21. import org.jfw.apt.web.annotation.param.SessionVal;
  22. import org.jfw.util.StringUtil;
  23. import org.jfw.util.context.JfwAppContext;
  24. import org.jfw.util.exception.JfwBaseException;
  25. import org.jfw.util.state.StateCode;
  26. import com.ekexiu.portal.dao.OrgDao;
  27. import com.ekexiu.portal.dao.OrgUserDao;
  28. import com.ekexiu.portal.dao.ProfessorDao;
  29. import com.ekexiu.portal.dao.UserDao;
  30. import com.ekexiu.portal.dao.UserOpenIdDao;
  31. import com.ekexiu.portal.mail.MailService;
  32. import com.ekexiu.portal.mobile.MobilePhoneService;
  33. import com.ekexiu.portal.oauth.OAuthService;
  34. import com.ekexiu.portal.oauth.OAuthUser;
  35. import com.ekexiu.portal.po.OrgUser;
  36. import com.ekexiu.portal.po.Organization;
  37. import com.ekexiu.portal.po.Professor;
  38. import com.ekexiu.portal.po.User;
  39. import com.ekexiu.portal.po.UserOpenId;
  40. import com.ekexiu.portal.pojo.SessionUser;
  41. @Path
  42. public class SysService {
  43. public static final String DEFAULT_PASS_WORD = "11111111111111111111111111111111";
  44. public static SimpleDateFormat DATE = new SimpleDateFormat("yyyyMMddHHmmss");
  45. private Logger logger = Logger.getLogger(SysService.class);
  46. @Autowrie
  47. private UserDao userDao;
  48. @Autowrie
  49. private OrgUserDao orgUserDao;
  50. @Autowrie
  51. private OrgDao orgDao;
  52. @Autowrie
  53. private OrgService orgService;
  54. @Autowrie
  55. private ProfessorDao professorDao;
  56. @Autowrie
  57. private ProfessorService professorService;
  58. @Autowrie
  59. private MailService mailservice;
  60. @Autowrie
  61. private MobilePhoneService mobilePhoneServcie;
  62. @Autowrie
  63. private GrowthLogService growthLogService;
  64. @Autowrie
  65. private GrowthRuleService rule;
  66. @Autowrie
  67. private OAuthService oauthService;
  68. @Autowrie
  69. private UserOpenIdDao userOpenIdDao;
  70. private String bindMailSubject;
  71. private String bindMailReplaceKey;
  72. private String bindMailReplaceContentTempalte;
  73. private long timeLimitWithBindMail = 10 * 60 * 1000;
  74. private String bindOrgMailReplaceKey;
  75. private String bindOrgMailSubject;
  76. private String bindOrgMailReplaceContentTempalte;
  77. private long timeLimitWithBindOrgMail = 10 * 60 * 1000;
  78. private String regMailSubject = "注册[科袖网]用户";
  79. private String regMailReplaceKey;
  80. private String regMailReplaceContentTempalte;
  81. private long timeLimitWithRegMail = 10 * 60 * 1000;
  82. private String orgRegMailSubject = "注册[科袖网]企业用户";
  83. private String orgRegMailReplaceKey;
  84. private String orgRegMailReplaceContentTempalte;
  85. private long timeLimitWithOrgRegMail = 10 * 60 * 1000;
  86. private String sendConsultMailSubject;
  87. private String sendConsultMailContentTemplate;
  88. private String sendConsultSMSContentTemplate;
  89. private String bindMobilePhoneReplaceKey;
  90. private String bindMobilePhoneContentTemplate;
  91. private long timeLimitWithBindMobilePhone = 3 * 60 * 1000;
  92. private String phoneRetrievePasswordReplaceKey;
  93. private String phoneRetrievePasswordContentTemplate;
  94. private long timeLimitWithPhoneRetrievePassword = 3 * 60 * 1000;
  95. private String mailRetrievePasswordContentTemplate;
  96. private String mailRetrievePasswordReplaceKey;
  97. private String mailRetrievePasswordSubject;
  98. private long timeLimitWithMailRetrivePassword = 10 * 60 * 1000;
  99. private String orgMailRetrievePasswordContentTemplate;
  100. private String orgMailRetrievePasswordReplaceKey;
  101. private String orgMailRetrievePasswordSubject;
  102. private long timeLimitWithOrgMailRetrivePassword = 10 * 60 * 1000;
  103. private String regMobilePhoneReplaceKey;
  104. private String regMobilePhoneContentTemplate;
  105. private long timeLimitWithRegMobilePhone = 3 * 60 * 1000;
  106. private String loginMobilePhoneReplaceKey;
  107. private String loginMobilePhoneContentTemplate;
  108. private long timeLimitWithLoginMobilePhone = 3 * 60 * 1000;
  109. private String phoneContentTemplate;
  110. private String phoneReplaceKey = "mobileCode";
  111. private String inviteReplacePhone = "phoneKey";
  112. private String inviteReplaceEmail = "mailKey";
  113. private String inviteReplaceCode = "invitCodeKey";
  114. private String inviteMailSubject = "[ 科袖网 ]特邀科研专家邀请函";
  115. private String inviteMailContentTempalte;
  116. private String inviteStaffReplaceKey = "stateCode";
  117. private String inviteStaffMailTempalte;
  118. private String inviteStaffOrgKey = "orgKey";
  119. private String inviteStaffSubject = "[ 科袖网 ]企业员工邀请函";
  120. private String retrieveOrgSuccessTempalte;
  121. private String retrieveOrgSuccessSubject;
  122. private String retrieveOrgFailTempalte;
  123. private String retrieveOrgFailSubject;
  124. public String getRegMailReplaceKey() {
  125. return regMailReplaceKey;
  126. }
  127. public void setRegMailReplaceKey(String regMailReplaceKey) {
  128. this.regMailReplaceKey = regMailReplaceKey;
  129. }
  130. public String getRegMailReplaceContentTempalte() {
  131. return regMailReplaceContentTempalte;
  132. }
  133. public void setRegMailReplaceContentTempalte(String regMailReplaceContentTempalte) {
  134. this.regMailReplaceContentTempalte = regMailReplaceContentTempalte;
  135. }
  136. public long getTimeLimitWithRegMail() {
  137. return timeLimitWithRegMail;
  138. }
  139. public void setTimeLimitWithRegMail(long timeLimitWithRegMail) {
  140. this.timeLimitWithRegMail = timeLimitWithRegMail;
  141. }
  142. public String getRegMobilePhoneReplaceKey() {
  143. return regMobilePhoneReplaceKey;
  144. }
  145. public void setRegMobilePhoneReplaceKey(String regMobilePhoneReplaceKey) {
  146. this.regMobilePhoneReplaceKey = regMobilePhoneReplaceKey;
  147. }
  148. public String getRegMobilePhoneContentTemplate() {
  149. return regMobilePhoneContentTemplate;
  150. }
  151. public void setRegMobilePhoneContentTemplate(String regMobilePhoneContentTemplate) {
  152. this.regMobilePhoneContentTemplate = regMobilePhoneContentTemplate;
  153. }
  154. public long getTimeLimitWithRegMobilePhone() {
  155. return timeLimitWithRegMobilePhone;
  156. }
  157. public void setTimeLimitWithRegMobilePhone(long timeLimitWithRegMobilePhone) {
  158. this.timeLimitWithRegMobilePhone = timeLimitWithRegMobilePhone;
  159. }
  160. public String getLoginMobilePhoneReplaceKey() {
  161. return loginMobilePhoneReplaceKey;
  162. }
  163. public void setLoginMobilePhoneReplaceKey(String loginMobilePhoneReplaceKey) {
  164. this.loginMobilePhoneReplaceKey = loginMobilePhoneReplaceKey;
  165. }
  166. public String getLoginMobilePhoneContentTemplate() {
  167. return loginMobilePhoneContentTemplate;
  168. }
  169. public void setLoginMobilePhoneContentTemplate(String loginMobilePhoneContentTemplate) {
  170. this.loginMobilePhoneContentTemplate = loginMobilePhoneContentTemplate;
  171. }
  172. public long getTimeLimitWithLoginMobilePhone() {
  173. return timeLimitWithLoginMobilePhone;
  174. }
  175. public void setTimeLimitWithLoginMobilePhone(long timeLimitWithLoginMobilePhone) {
  176. this.timeLimitWithLoginMobilePhone = timeLimitWithLoginMobilePhone;
  177. }
  178. public String getMailRetrievePasswordSubject() {
  179. return mailRetrievePasswordSubject;
  180. }
  181. public void setMailRetrievePasswordSubject(String mailRetrievePasswordSubject) {
  182. this.mailRetrievePasswordSubject = mailRetrievePasswordSubject;
  183. }
  184. public MobilePhoneService getMobilePhoneServcie() {
  185. return mobilePhoneServcie;
  186. }
  187. public void setMobilePhoneServcie(MobilePhoneService mobilePhoneServcie) {
  188. this.mobilePhoneServcie = mobilePhoneServcie;
  189. }
  190. public GrowthLogService getGrowthLogService() {
  191. return growthLogService;
  192. }
  193. public void setGrowthLogService(GrowthLogService growthLogService) {
  194. this.growthLogService = growthLogService;
  195. }
  196. public GrowthRuleService getRule() {
  197. return rule;
  198. }
  199. public void setRule(GrowthRuleService rule) {
  200. this.rule = rule;
  201. }
  202. public String getPhoneRetrievePasswordReplaceKey() {
  203. return phoneRetrievePasswordReplaceKey;
  204. }
  205. public void setPhoneRetrievePasswordReplaceKey(String phoneRetrievePasswordReplaceKey) {
  206. this.phoneRetrievePasswordReplaceKey = phoneRetrievePasswordReplaceKey;
  207. }
  208. public String getPhoneRetrievePasswordContentTemplate() {
  209. return phoneRetrievePasswordContentTemplate;
  210. }
  211. public void setPhoneRetrievePasswordContentTemplate(String phoneRetrievePasswordContentTemplate) {
  212. this.phoneRetrievePasswordContentTemplate = phoneRetrievePasswordContentTemplate;
  213. }
  214. public long getTimeLimitWithPhoneRetrievePassword() {
  215. return timeLimitWithPhoneRetrievePassword;
  216. }
  217. public void setTimeLimitWithPhoneRetrievePassword(long timeLimitWithPhoneRetrievePassword) {
  218. this.timeLimitWithPhoneRetrievePassword = timeLimitWithPhoneRetrievePassword;
  219. }
  220. public long getTimeLimitWithMailRetrivePassword() {
  221. return timeLimitWithMailRetrivePassword;
  222. }
  223. public void setTimeLimitWithMailRetrivePassword(long timeLimitWithMailRetrivePassword) {
  224. this.timeLimitWithMailRetrivePassword = timeLimitWithMailRetrivePassword;
  225. }
  226. public String getOrgMailRetrievePasswordContentTemplate() {
  227. return orgMailRetrievePasswordContentTemplate;
  228. }
  229. public void setOrgMailRetrievePasswordContentTemplate(String orgMailRetrievePasswordContentTemplate) {
  230. this.orgMailRetrievePasswordContentTemplate = orgMailRetrievePasswordContentTemplate;
  231. }
  232. public String getOrgMailRetrievePasswordReplaceKey() {
  233. return orgMailRetrievePasswordReplaceKey;
  234. }
  235. public void setOrgMailRetrievePasswordReplaceKey(String orgMailRetrievePasswordReplaceKey) {
  236. this.orgMailRetrievePasswordReplaceKey = orgMailRetrievePasswordReplaceKey;
  237. }
  238. public String getOrgMailRetrievePasswordSubject() {
  239. return orgMailRetrievePasswordSubject;
  240. }
  241. public void setOrgMailRetrievePasswordSubject(String orgMailRetrievePasswordSubject) {
  242. this.orgMailRetrievePasswordSubject = orgMailRetrievePasswordSubject;
  243. }
  244. public long getTimeLimitWithOrgMailRetrivePassword() {
  245. return timeLimitWithOrgMailRetrivePassword;
  246. }
  247. public void setTimeLimitWithOrgMailRetrivePassword(long timeLimitWithOrgMailRetrivePassword) {
  248. this.timeLimitWithOrgMailRetrivePassword = timeLimitWithOrgMailRetrivePassword;
  249. }
  250. public String getBindMobilePhoneReplaceKey() {
  251. return bindMobilePhoneReplaceKey;
  252. }
  253. public void setBindMobilePhoneReplaceKey(String bindMobilePhoneReplaceKey) {
  254. this.bindMobilePhoneReplaceKey = bindMobilePhoneReplaceKey;
  255. }
  256. public String getSendConsultMailSubject() {
  257. return sendConsultMailSubject;
  258. }
  259. public void setSendConsultMailSubject(String sendConsultMailSubject) {
  260. this.sendConsultMailSubject = sendConsultMailSubject;
  261. }
  262. public String getSendConsultMailContentTemplate() {
  263. return sendConsultMailContentTemplate;
  264. }
  265. public void setSendConsultMailContentTemplate(String sendConsultMailContentTemplate) {
  266. this.sendConsultMailContentTemplate = sendConsultMailContentTemplate;
  267. }
  268. public String getSendConsultSMSContentTemplate() {
  269. return sendConsultSMSContentTemplate;
  270. }
  271. public void setSendConsultSMSContentTemplate(String sendConsultSMSContentTemplate) {
  272. this.sendConsultSMSContentTemplate = sendConsultSMSContentTemplate;
  273. }
  274. public String getBindMobilePhoneContentTemplate() {
  275. return bindMobilePhoneContentTemplate;
  276. }
  277. public void setBindMobilePhoneContentTemplate(String bindMobilePhoneContentTemplate) {
  278. this.bindMobilePhoneContentTemplate = bindMobilePhoneContentTemplate;
  279. }
  280. public long getTimeLimitWithBindMobilePhone() {
  281. return timeLimitWithBindMobilePhone;
  282. }
  283. public void setTimeLimitWithBindMobilePhone(long timeLimitWithBindMobilePhone) {
  284. this.timeLimitWithBindMobilePhone = timeLimitWithBindMobilePhone;
  285. }
  286. public void setMailRetrievePasswordContentTemplate(String retrievePasswordContentTemplate) {
  287. this.mailRetrievePasswordContentTemplate = retrievePasswordContentTemplate;
  288. }
  289. public String getBindMailSubject() {
  290. return bindMailSubject;
  291. }
  292. public void setBindMailSubject(String bindMailSubject) {
  293. this.bindMailSubject = bindMailSubject;
  294. }
  295. public long getTimeLimitWithBindMail() {
  296. return timeLimitWithBindMail;
  297. }
  298. public void setTimeLimitWithBindMail(long timeLimitWithBindMail) {
  299. this.timeLimitWithBindMail = timeLimitWithBindMail;
  300. }
  301. public String getMailRetrievePasswordReplaceKey() {
  302. return mailRetrievePasswordReplaceKey;
  303. }
  304. public void setMailRetrievePasswordReplaceKey(String retrievePasswordReplaceKey) {
  305. this.mailRetrievePasswordReplaceKey = retrievePasswordReplaceKey;
  306. }
  307. public String getBindMailReplaceKey() {
  308. return bindMailReplaceKey;
  309. }
  310. public void setBindMailReplaceKey(String bindMailReplaceKey) {
  311. this.bindMailReplaceKey = bindMailReplaceKey;
  312. }
  313. public String getBindOrgMailReplaceKey() {
  314. return bindOrgMailReplaceKey;
  315. }
  316. public void setBindOrgMailReplaceKey(String bindOrgMailReplaceKey) {
  317. this.bindOrgMailReplaceKey = bindOrgMailReplaceKey;
  318. }
  319. public String getBindOrgMailSubject() {
  320. return bindOrgMailSubject;
  321. }
  322. public void setBindOrgMailSubject(String bindOrgMailSubject) {
  323. this.bindOrgMailSubject = bindOrgMailSubject;
  324. }
  325. public String getBindOrgMailReplaceContentTempalte() {
  326. return bindOrgMailReplaceContentTempalte;
  327. }
  328. public void setBindOrgMailReplaceContentTempalte(String bindOrgMailReplaceContentTempalte) {
  329. this.bindOrgMailReplaceContentTempalte = bindOrgMailReplaceContentTempalte;
  330. }
  331. public long getTimeLimitWithBindOrgMail() {
  332. return timeLimitWithBindOrgMail;
  333. }
  334. public void setTimeLimitWithBindOrgMail(long timeLimitWithBindOrgMail) {
  335. this.timeLimitWithBindOrgMail = timeLimitWithBindOrgMail;
  336. }
  337. public String getMailRetrievePasswordContentTemplate() {
  338. return mailRetrievePasswordContentTemplate;
  339. }
  340. public String getBindMailReplaceContentTempalte() {
  341. return bindMailReplaceContentTempalte;
  342. }
  343. public void setBindMailReplaceContentTempalte(String bindMailReplaceContentTempalte) {
  344. this.bindMailReplaceContentTempalte = bindMailReplaceContentTempalte;
  345. }
  346. public String getPhoneContentTemplate() {
  347. return phoneContentTemplate;
  348. }
  349. public void setPhoneContentTemplate(String phoneContentTemplate) {
  350. this.phoneContentTemplate = phoneContentTemplate;
  351. }
  352. public String getPhoneReplaceKey() {
  353. return phoneReplaceKey;
  354. }
  355. public void setPhoneReplaceKey(String phoneReplaceKey) {
  356. this.phoneReplaceKey = phoneReplaceKey;
  357. }
  358. public String getInviteReplacePhone() {
  359. return inviteReplacePhone;
  360. }
  361. public void setInviteReplacePhone(String inviteReplacePhone) {
  362. this.inviteReplacePhone = inviteReplacePhone;
  363. }
  364. public String getInviteReplaceEmail() {
  365. return inviteReplaceEmail;
  366. }
  367. public void setInviteReplaceEmail(String inviteReplaceEmail) {
  368. this.inviteReplaceEmail = inviteReplaceEmail;
  369. }
  370. public String getInviteReplaceCode() {
  371. return inviteReplaceCode;
  372. }
  373. public void setInviteReplaceCode(String inviteReplaceCode) {
  374. this.inviteReplaceCode = inviteReplaceCode;
  375. }
  376. public String getInviteMailSubject() {
  377. return inviteMailSubject;
  378. }
  379. public void setInviteMailSubject(String inviteMailSubject) {
  380. this.inviteMailSubject = inviteMailSubject;
  381. }
  382. public String getInviteMailContentTempalte() {
  383. return inviteMailContentTempalte;
  384. }
  385. public void setInviteMailContentTempalte(String inviteMailContentTempalte) {
  386. this.inviteMailContentTempalte = inviteMailContentTempalte;
  387. }
  388. public UserDao getUserDao() {
  389. return userDao;
  390. }
  391. public void setUserDao(UserDao userDao) {
  392. this.userDao = userDao;
  393. }
  394. public OrgUserDao getOrgUserDao() {
  395. return orgUserDao;
  396. }
  397. public void setOrgUserDao(OrgUserDao orgUserDao) {
  398. this.orgUserDao = orgUserDao;
  399. }
  400. public OrgDao getOrgDao() {
  401. return orgDao;
  402. }
  403. public void setOrgDao(OrgDao orgDao) {
  404. this.orgDao = orgDao;
  405. }
  406. public OrgService getOrgService() {
  407. return orgService;
  408. }
  409. public void setOrgService(OrgService orgService) {
  410. this.orgService = orgService;
  411. }
  412. public ProfessorDao getProfessorDao() {
  413. return professorDao;
  414. }
  415. public void setProfessorDao(ProfessorDao professorDao) {
  416. this.professorDao = professorDao;
  417. }
  418. public ProfessorService getProfessorService() {
  419. return professorService;
  420. }
  421. public void setProfessorService(ProfessorService professorService) {
  422. this.professorService = professorService;
  423. }
  424. public MailService getMailservice() {
  425. return mailservice;
  426. }
  427. public void setMailservice(MailService mailservice) {
  428. this.mailservice = mailservice;
  429. }
  430. public String getRegMailSubject() {
  431. return regMailSubject;
  432. }
  433. public void setRegMailSubject(String regMailSubject) {
  434. this.regMailSubject = regMailSubject;
  435. }
  436. public String getOrgRegMailSubject() {
  437. return orgRegMailSubject;
  438. }
  439. public void setOrgRegMailSubject(String orgRegMailSubject) {
  440. this.orgRegMailSubject = orgRegMailSubject;
  441. }
  442. public String getOrgRegMailReplaceKey() {
  443. return orgRegMailReplaceKey;
  444. }
  445. public void setOrgRegMailReplaceKey(String orgRegMailReplaceKey) {
  446. this.orgRegMailReplaceKey = orgRegMailReplaceKey;
  447. }
  448. public String getOrgRegMailReplaceContentTempalte() {
  449. return orgRegMailReplaceContentTempalte;
  450. }
  451. public void setOrgRegMailReplaceContentTempalte(String orgRegMailReplaceContentTempalte) {
  452. this.orgRegMailReplaceContentTempalte = orgRegMailReplaceContentTempalte;
  453. }
  454. public long getTimeLimitWithOrgRegMail() {
  455. return timeLimitWithOrgRegMail;
  456. }
  457. public void setTimeLimitWithOrgRegMail(long timeLimitWithOrgRegMail) {
  458. this.timeLimitWithOrgRegMail = timeLimitWithOrgRegMail;
  459. }
  460. public String getInviteStaffReplaceKey() {
  461. return inviteStaffReplaceKey;
  462. }
  463. public void setInviteStaffReplaceKey(String inviteStaffReplaceKey) {
  464. this.inviteStaffReplaceKey = inviteStaffReplaceKey;
  465. }
  466. public String getInviteStaffMailTempalte() {
  467. return inviteStaffMailTempalte;
  468. }
  469. public void setInviteStaffMailTempalte(String inviteStaffMailTempalte) {
  470. this.inviteStaffMailTempalte = inviteStaffMailTempalte;
  471. }
  472. public String getInviteStaffOrgKey() {
  473. return inviteStaffOrgKey;
  474. }
  475. public void setInviteStaffOrgKey(String inviteStaffOrgKey) {
  476. this.inviteStaffOrgKey = inviteStaffOrgKey;
  477. }
  478. public String getInviteStaffSubject() {
  479. return inviteStaffSubject;
  480. }
  481. public void setInviteStaffSubject(String inviteStaffSubject) {
  482. this.inviteStaffSubject = inviteStaffSubject;
  483. }
  484. public String getRetrieveOrgSuccessTempalte() {
  485. return retrieveOrgSuccessTempalte;
  486. }
  487. public void setRetrieveOrgSuccessTempalte(String retrieveOrgSuccessTempalte) {
  488. this.retrieveOrgSuccessTempalte = retrieveOrgSuccessTempalte;
  489. }
  490. public String getRetrieveOrgSuccessSubject() {
  491. return retrieveOrgSuccessSubject;
  492. }
  493. public void setRetrieveOrgSuccessSubject(String retrieveOrgSuccessSubject) {
  494. this.retrieveOrgSuccessSubject = retrieveOrgSuccessSubject;
  495. }
  496. public String getRetrieveOrgFailTempalte() {
  497. return retrieveOrgFailTempalte;
  498. }
  499. public void setRetrieveOrgFailTempalte(String retrieveOrgFailTempalte) {
  500. this.retrieveOrgFailTempalte = retrieveOrgFailTempalte;
  501. }
  502. public String getRetrieveOrgFailSubject() {
  503. return retrieveOrgFailSubject;
  504. }
  505. public void setRetrieveOrgFailSubject(String retrieveOrgFailSubject) {
  506. this.retrieveOrgFailSubject = retrieveOrgFailSubject;
  507. }
  508. public OAuthService getOauthService() {
  509. return oauthService;
  510. }
  511. public void setOauthService(OAuthService oauthService) {
  512. this.oauthService = oauthService;
  513. }
  514. public UserOpenIdDao getUserOpenIdDao() {
  515. return userOpenIdDao;
  516. }
  517. public void setUserOpenIdDao(UserOpenIdDao userOpenIdDao) {
  518. this.userOpenIdDao = userOpenIdDao;
  519. }
  520. /**
  521. * 验证注册时填写的手机号和邮箱是否已经注册过
  522. *
  523. * @param con
  524. * @param key
  525. * 手机号或邮箱
  526. * @return 如果该手机或邮箱已经注册过返回false, 否则返回true
  527. * @throws SQLException
  528. */
  529. @Get
  530. @Path("/isReg")
  531. public boolean isReg(@JdbcConn Connection con, String key) throws SQLException {
  532. User user = this.userDao.queryByEmailOrMobilePhone(con, key);
  533. if (null != user) {
  534. return false;
  535. } else {
  536. return true;
  537. }
  538. }
  539. @Get
  540. @Path("/isRegOrg")
  541. public boolean isRegOrg(@JdbcConn Connection con, String email) throws SQLException {
  542. OrgUser orgUser = this.orgUserDao.queryByEmail(con, email);
  543. if (null != orgUser) {
  544. return false;
  545. } else {
  546. return true;
  547. }
  548. }
  549. @Get
  550. @Path("/isOrgUser")
  551. public boolean isOrgUser(@JdbcConn Connection con, String orgName) throws SQLException, JfwBaseException {
  552. String orgId = this.orgDao.queryByName(con, orgName);
  553. if (orgId == null) {
  554. return true;
  555. } else {
  556. if (this.orgUserDao.queryOne(con, orgId) == null) {
  557. return true;
  558. } else {
  559. String authStatus = (this.orgDao.query(con, orgId)).getAuthStatus();
  560. if ("3".equals(authStatus)) {
  561. throw new JfwBaseException(3, "该企业为科袖认证企业");
  562. } else if ("2".equals(authStatus)) {
  563. throw new JfwBaseException(4, "该企业正在进行认证审核");
  564. } else {
  565. throw new JfwBaseException(2, "该企业已注册科袖账号");
  566. }
  567. }
  568. }
  569. }
  570. @Get
  571. @Path("/qaUser")
  572. public User queryUser(@JdbcConn Connection con, String id) throws SQLException {
  573. User user = this.userDao.query(con, id);
  574. User user2 = new User();
  575. user2.setId(user.getId());
  576. user2.setMobilePhone(user.getMobilePhone());
  577. user2.setEmail(user.getEmail());
  578. return user2;
  579. }
  580. /**
  581. * 手机验证注册
  582. *
  583. * @param con
  584. * @param state
  585. * 发送手机验证码的返回值
  586. * @param mobilePhone
  587. * 验证的手机号
  588. * @param validateCode
  589. * 手机验证码
  590. * @param password
  591. * 注册密码
  592. * @return
  593. * @throws SQLException
  594. * @throws JfwBaseException
  595. */
  596. @Post
  597. @Path("/regmobile")
  598. public String regMobile(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId) throws SQLException, JfwBaseException {
  599. @SuppressWarnings("unchecked")
  600. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  601. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
  602. throw new JfwBaseException(-1, "验证超时");
  603. try {
  604. if (!sc.getKey().equals(mobilePhone)) {
  605. throw new JfwBaseException(-2, "手机号与验证手机不匹配");
  606. }
  607. if (!sc.getValue().equals(validateCode)) {
  608. throw new JfwBaseException(-3, "验证码错误");
  609. }
  610. User user = new User();
  611. user.setId(StringUtil.buildUUID());
  612. String passwd = StringUtil.md5(password);
  613. user.setMobilePhone(mobilePhone);
  614. user.setPasswd(passwd);
  615. user.setUserType("0");
  616. user.setInviterId(inviterId);
  617. user.setActiveTime(DATE.format(new Date()));
  618. this.userDao.insert(con, user);
  619. if (inviterId != null) {
  620. this.growthLogService.invite(con, inviterId, user.getId());
  621. }
  622. return user.getId();
  623. } finally {
  624. JfwAppContext.removeCachedObject(state);
  625. }
  626. }
  627. private void associatedOpenId(Connection con, User user, String oauthType, String openid, String authCode) throws SQLException, JfwBaseException {
  628. if (oauthType != null) {
  629. if (oauthService.getHandlers().get(oauthType) == null) {
  630. throw new JfwBaseException(-4, "invalid oautyType");
  631. }
  632. if (openid != null) {
  633. UserOpenId uoi = new UserOpenId();
  634. uoi.setOauthType(oauthType);
  635. uoi.setOpenid(openid);
  636. uoi.setUserid(user.getId());
  637. try {
  638. userOpenIdDao.insert(con, uoi);
  639. } catch (SQLException e) {
  640. if ("23505".equals(e.getSQLState())) {
  641. throw new JfwBaseException(-6, "associated openid");
  642. }
  643. throw e;
  644. }
  645. } else {
  646. throw new JfwBaseException(-5, "关链第三方登录时,OPENID不可都为空");
  647. }
  648. } else if (null != authCode) {
  649. @SuppressWarnings("unchecked")
  650. StateCode<OAuthUser, UserOpenId> ac = (StateCode<OAuthUser, UserOpenId>) JfwAppContext.getCachedObject(authCode);
  651. if (ac == null || ac.getExpiredTime() < System.currentTimeMillis())
  652. throw new JfwBaseException(-7, "authCode is expired");
  653. OAuthUser ou = ac.getKey();
  654. openid = ou.getOpenId();
  655. oauthType = ou.getType();
  656. UserOpenId uoi = new UserOpenId();
  657. uoi.setOauthType(oauthType);
  658. uoi.setOpenid(openid);
  659. uoi.setUserid(user.getId());
  660. try {
  661. userOpenIdDao.insert(con, uoi);
  662. JfwAppContext.removeCachedObject(authCode);
  663. } catch (SQLException e) {
  664. if ("23505".equals(e.getSQLState())) {
  665. throw new JfwBaseException(-8, "associated openid");
  666. }
  667. throw e;
  668. }
  669. }
  670. }
  671. @Post
  672. @Path("/mobileReg")
  673. public String mobileReg(@JdbcConn(true) Connection con, String state, String mobilePhone, String validateCode, String password, @Nullable String inviterId,
  674. String name, @Nullable String oauthType, @Nullable String openid, @Nullable String authCode) throws SQLException, JfwBaseException, IOException {
  675. @SuppressWarnings("unchecked")
  676. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  677. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis())
  678. throw new JfwBaseException(-1, "验证超时");
  679. try {
  680. if (!sc.getKey().equals(mobilePhone)) {
  681. throw new JfwBaseException(-2, "手机号与验证手机不匹配");
  682. }
  683. if (!sc.getValue().equals(validateCode)) {
  684. throw new JfwBaseException(-3, "验证码错误");
  685. }
  686. User user = new User();
  687. user.setId(StringUtil.buildUUID());
  688. String passwd = StringUtil.md5(password);
  689. user.setMobilePhone(mobilePhone);
  690. user.setPasswd(passwd);
  691. user.setUserType("0");
  692. user.setInviterId(inviterId);
  693. user.setActiveTime(DATE.format(new Date()));
  694. this.userDao.insert(con, user);
  695. this.associatedOpenId(con, user, oauthType, openid, authCode);
  696. if (inviterId != null) {
  697. this.growthLogService.invite(con, inviterId, user.getId());
  698. }
  699. Professor professor = new Professor();
  700. professor.setId(user.getId());
  701. professor.setName(name);
  702. professor.setAuthentication(-1);
  703. this.professorService.insert(con, professor, null);
  704. return user.getId();
  705. } finally {
  706. JfwAppContext.removeCachedObject(state);
  707. }
  708. }
  709. /**
  710. * 邮箱验证并注册
  711. *
  712. * @param con
  713. * @param key
  714. * 发送邮箱验证的返回值
  715. *
  716. * @return 验证成功 用户登录并返回用户信息 验证失败返回null
  717. * @throws SQLException
  718. * @throws JfwBaseException
  719. */
  720. @Get
  721. @Path("/regmail/{key}")
  722. public void regeMail(@JdbcConn(false) Connection con, @PathVar String key) throws SQLException, JfwBaseException {
  723. @SuppressWarnings("unchecked")
  724. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  725. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
  726. throw new JfwBaseException(-1, "验证链接已失效");
  727. }
  728. try {
  729. User user = new User();
  730. user.setEmail(sc.getCode());
  731. user.setId(StringUtil.buildUUID());
  732. user.setSendMailStatus(0);
  733. user.setPasswd(StringUtil.md5(sc.getKey()));
  734. user.setUserType("0");
  735. user.setInviterId(sc.getValue());
  736. user.setActiveTime(DATE.format(new Date()));
  737. this.userDao.insert(con, user);
  738. con.commit();
  739. if (sc.getValue() != null) {
  740. this.growthLogService.invite(con, sc.getValue(), user.getId());
  741. }
  742. } catch (SQLException e) {
  743. try {
  744. con.rollback();
  745. } catch (Exception ee) {
  746. }
  747. if ("23505".equals(e.getSQLState())) {
  748. throw new JfwBaseException(-3, "邮箱[" + sc.getCode() + "]已被注册过了");
  749. }
  750. throw e;
  751. } finally {
  752. JfwAppContext.removeCachedObject(key);
  753. }
  754. }
  755. @Get
  756. @Path("/mailReg")
  757. public void emailReg(@JdbcConn(false) Connection con, String key) throws SQLException, JfwBaseException, IOException {
  758. @SuppressWarnings("unchecked")
  759. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  760. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
  761. throw new JfwBaseException(-1, "验证链接已失效");
  762. }
  763. try {
  764. User user = new User();
  765. user.setEmail(sc.getCode());
  766. user.setId(StringUtil.buildUUID());
  767. user.setSendMailStatus(0);
  768. user.setPasswd(StringUtil.md5(sc.getKey()));
  769. user.setUserType("0");
  770. user.setInviterId(sc.getValue());
  771. user.setActiveTime(DATE.format(new Date()));
  772. this.userDao.insert(con, user);
  773. if (sc.getValue() != null) {
  774. this.growthLogService.invite(con, sc.getValue(), user.getId());
  775. }
  776. Professor professor = new Professor();
  777. professor.setId(user.getId());
  778. professor.setName(sc.getDescp());
  779. professor.setAuthentication(-1);
  780. this.professorService.insert(con, professor, null);
  781. con.commit();
  782. } catch (SQLException e) {
  783. try {
  784. con.rollback();
  785. } catch (Exception ee) {
  786. }
  787. if ("23505".equals(e.getSQLState())) {
  788. throw new JfwBaseException(-3, "邮箱[" + sc.getCode() + "]已被注册过了");
  789. }
  790. throw e;
  791. } finally {
  792. JfwAppContext.removeCachedObject(key);
  793. }
  794. }
  795. /**
  796. * 发送邮箱注册验证邮件
  797. *
  798. * @param con
  799. * @param mail
  800. * 待验证的邮箱地址
  801. * @param password
  802. * 密码
  803. * @throws JfwBaseException
  804. * @throws SQLException
  805. */
  806. @Post
  807. @Path("/regmail")
  808. public void regMail(@JdbcConn(false) Connection con, String mail, String password, @Nullable String inviterId) throws JfwBaseException, SQLException {
  809. User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
  810. if (null != user) {
  811. throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
  812. } else {
  813. StateCode<String, String> sc = new StateCode<String, String>();
  814. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  815. Map<String, String> map = new HashMap<>();
  816. map.put(this.regMailReplaceKey, key);
  817. try {
  818. this.mailservice.sendSimpleMail(mail, this.regMailReplaceContentTempalte, map, this.regMailSubject);
  819. } catch (MessagingException e) {
  820. JfwAppContext.removeCachedObject(key);
  821. throw new JfwBaseException(-2, "给邮箱[" + mail + "]发邮件错误", e);
  822. }
  823. sc.setCode(mail);
  824. sc.setKey(password);
  825. sc.setValue(inviterId);
  826. sc.setBuildTime(System.currentTimeMillis());
  827. sc.setExpiredTime(sc.getBuildTime() + this.timeLimitWithRegMail);
  828. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  829. @Override
  830. public void run() {
  831. JfwAppContext.removeCachedObject(key);
  832. }
  833. }, this.timeLimitWithRegMail, TimeUnit.MILLISECONDS);
  834. }
  835. }
  836. @Post
  837. @Path("/emailReg")
  838. public void emailReg(@JdbcConn(false) Connection con, String mail, String password, @Nullable String inviterId, String name)
  839. throws JfwBaseException, SQLException {
  840. User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
  841. if (null != user) {
  842. throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
  843. } else {
  844. StateCode<String, String> sc = new StateCode<String, String>();
  845. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  846. Map<String, String> map = new HashMap<>();
  847. map.put(this.regMailReplaceKey, key);
  848. try {
  849. this.mailservice.sendSimpleMail(mail, this.regMailReplaceContentTempalte, map, this.regMailSubject);
  850. } catch (MessagingException e) {
  851. JfwAppContext.removeCachedObject(key);
  852. throw new JfwBaseException(-2, "给邮箱[" + mail + "]发邮件错误", e);
  853. }
  854. sc.setCode(mail);
  855. sc.setKey(password);
  856. sc.setValue(inviterId);
  857. sc.setDescp(name);
  858. sc.setBuildTime(System.currentTimeMillis());
  859. sc.setExpiredTime(sc.getBuildTime() + this.timeLimitWithRegMail);
  860. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  861. @Override
  862. public void run() {
  863. JfwAppContext.removeCachedObject(key);
  864. }
  865. }, this.timeLimitWithRegMail, TimeUnit.MILLISECONDS);
  866. }
  867. }
  868. /**
  869. * 验证企业邮箱并注册企业账号
  870. *
  871. * @param con
  872. * @param key
  873. * 邮箱验证的返回值
  874. * @throws SQLException
  875. * @throws JfwBaseException
  876. * @throws IOException
  877. */
  878. @Get
  879. @Path("/regOrgMail/{key}")
  880. public void regOrgMail(@JdbcConn(false) Connection con, @PathVar String key) throws SQLException, JfwBaseException, IOException {
  881. @SuppressWarnings("unchecked")
  882. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  883. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
  884. throw new JfwBaseException(-1, "验证链接已失效");
  885. }
  886. String orgId = this.orgDao.queryByName(con, sc.getValue());
  887. if ((orgId != null) && (this.orgUserDao.queryOne(con, orgId) != null)) {
  888. throw new JfwBaseException(2, "该企业已注册科袖账号");
  889. }
  890. try {
  891. OrgUser orgUser = new OrgUser();
  892. orgUser.setEmail(sc.getCode());
  893. if (orgId != null) {
  894. orgUser.setId(orgId);
  895. } else {
  896. orgUser.setId(this.orgService.createOrganization(con, sc.getValue()));
  897. }
  898. orgUser.setPasswd(StringUtil.md5(sc.getKey()));
  899. orgUser.setUserType("1");
  900. this.orgUserDao.insert(con, orgUser);
  901. this.orgDao.updateIsJoin(con, orgUser.getId(), "1");
  902. con.commit();
  903. } catch (SQLException e) {
  904. try {
  905. con.rollback();
  906. } catch (Exception ee) {
  907. }
  908. if ("23505".equals(e.getSQLState())) {
  909. throw new JfwBaseException(-3, "邮箱[" + sc.getCode() + "]已被注册过了");
  910. }
  911. throw e;
  912. } finally {
  913. JfwAppContext.removeCachedObject(key);
  914. }
  915. }
  916. /**
  917. * 给注册的企业邮箱发送验证邮件
  918. *
  919. * @param con
  920. * @param orgName
  921. * 企业名称
  922. * @param mail
  923. * 企业邮箱
  924. * @param password
  925. * 密码
  926. * @throws JfwBaseException
  927. * @throws SQLException
  928. */
  929. @Post
  930. @Path("/regOrgMail")
  931. public void regOrgMail(@JdbcConn(false) Connection con, String orgName, String mail, String password) throws JfwBaseException, SQLException {
  932. OrgUser orgUser = this.orgUserDao.queryByEmail(con, mail);
  933. if (null != orgUser) {
  934. throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
  935. } else {
  936. StateCode<String, String> sc = new StateCode<String, String>();
  937. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  938. Map<String, String> map = new HashMap<>();
  939. map.put(this.orgRegMailReplaceKey, key);
  940. try {
  941. this.mailservice.sendSimpleMail(mail, this.orgRegMailReplaceContentTempalte, map, this.orgRegMailSubject);
  942. } catch (MessagingException e) {
  943. JfwAppContext.removeCachedObject(key);
  944. throw new JfwBaseException(-2, "给邮箱[" + mail + "]发邮件错误", e);
  945. }
  946. sc.setCode(mail);
  947. sc.setKey(password);
  948. sc.setValue(orgName);
  949. sc.setBuildTime(System.currentTimeMillis());
  950. sc.setExpiredTime(sc.getBuildTime() + this.timeLimitWithOrgRegMail);
  951. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  952. @Override
  953. public void run() {
  954. JfwAppContext.removeCachedObject(key);
  955. }
  956. }, this.timeLimitWithOrgRegMail, TimeUnit.MILLISECONDS);
  957. }
  958. }
  959. @Get
  960. @Path("/sendMailInvite")
  961. public String sendMailInvite(@JdbcConn(false) Connection con, String id) throws SQLException, MessagingException, JfwBaseException {
  962. User user = this.userDao.query(con, id);
  963. if (user == null) {
  964. throw new JfwBaseException("系统没有此用户");
  965. }
  966. if (user.getEmail() == null) {
  967. throw new JfwBaseException("邮箱不能为空");
  968. }
  969. if (user.getInviteCode() == null) {
  970. throw new JfwBaseException("该用户没有邀请码");
  971. }
  972. String mailContent = this.inviteMailContentTempalte;
  973. mailContent = mailContent.replaceAll(this.inviteReplaceEmail, user.getEmail());
  974. mailContent = mailContent.replaceAll(this.inviteReplaceCode, user.getInviteCode());
  975. String phoneReplace = "";
  976. if (user.getMobilePhone() != null && user.getMobilePhone().trim().length() == 11) {
  977. String mobile = user.getMobilePhone().trim();
  978. mobile = mobile.substring(0, 3) + "****" + mobile.substring(7);
  979. phoneReplace = this.phoneContentTemplate.replaceAll(this.phoneReplaceKey, mobile);
  980. }
  981. mailContent = mailContent.replaceAll(this.inviteReplacePhone, phoneReplace);
  982. this.mailservice.sendSimpleMail(user.getEmail(), mailContent, null, this.inviteMailSubject);
  983. return "send success !";
  984. }
  985. @Post
  986. @Path("/inviteStaff/{key}")
  987. public Map<String, String> inviteStaff(@JdbcConn Connection con, @PathVar String key) throws SQLException, JfwBaseException {
  988. @SuppressWarnings("unchecked")
  989. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  990. if (sc == null) {
  991. throw new JfwBaseException(-1, "验证链接已失效");
  992. }
  993. Organization org = this.orgDao.query(con, sc.getKey());
  994. if (org == null) {
  995. throw new JfwBaseException(-2, "不存在的企业");
  996. }
  997. Map<String, String> map = new HashMap<String, String>();
  998. map.put("orgId", org.getId());
  999. map.put("orgName", org.getName());
  1000. map.put("email", sc.getValue());
  1001. return map;
  1002. }
  1003. @SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
  1004. "userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
  1005. "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
  1006. @Post
  1007. @Path("/regInviteStaff")
  1008. @SuppressWarnings("unchecked")
  1009. public SessionUser regInviteStaff(@JdbcConn(true) Connection con, String key, String state, String phone, String validateCode, String name, String passwd)
  1010. throws SQLException, JfwBaseException {
  1011. StateCode<String, String> stateCode = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  1012. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1013. if (stateCode == null) {
  1014. throw new JfwBaseException(-1, "邮箱验证链接已失效");
  1015. }
  1016. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
  1017. throw new JfwBaseException(-2, "短信验证超时");
  1018. }
  1019. if (!sc.getKey().equals(phone)) {
  1020. throw new JfwBaseException(-3, "手机号与验证手机不匹配");
  1021. }
  1022. if (!sc.getValue().equals(validateCode)) {
  1023. throw new JfwBaseException(-4, "手机验证码错误");
  1024. }
  1025. try {
  1026. String id = StringUtil.buildUUID();
  1027. User user = new User();
  1028. user.setId(id);
  1029. user.setMobilePhone(phone);
  1030. user.setEmail(stateCode.getValue());
  1031. user.setPasswd(StringUtil.md5(passwd));
  1032. user.setUserType("0");
  1033. user.setActiveTime(DATE.format(new Date()));
  1034. this.userDao.insert(con, user);
  1035. Professor professor = new Professor();
  1036. professor.setId(id);
  1037. professor.setName(name);
  1038. professor.setOrgId(stateCode.getKey());
  1039. professor.setOrgAuth("1");
  1040. professor.setPhone(user.getMobilePhone());
  1041. professor.setEmail(user.getEmail());
  1042. int value = 0;
  1043. if (user.getMobilePhone() != null && user.getMobilePhone().trim().length() == 11) {
  1044. professor.setPhone(user.getMobilePhone());
  1045. value = value + this.rule.getBindMobile();
  1046. this.growthLogService.firstBindMobile(con, professor.getId());
  1047. }
  1048. if (user.getEmail() != null && !"".equals(user.getEmail())) {
  1049. professor.setEmail(user.getEmail());
  1050. value = value + this.rule.getBindEmail();
  1051. this.growthLogService.firstBindEmail(con, professor.getId());
  1052. }
  1053. professor.setScoreValue(value);
  1054. professor.setGrowthValue(value);
  1055. this.professorDao.insert(con, professor);
  1056. SessionUser ret = new SessionUser();
  1057. ret.setMobilePhone(phone);
  1058. ret.setEmail(user.getEmail());
  1059. ret.setName(name);
  1060. ret.setId(id);
  1061. ret.setType(user.getUserType());
  1062. ret.setAuth(true);
  1063. return ret;
  1064. } finally {
  1065. JfwAppContext.removeCachedObject(key);
  1066. JfwAppContext.removeCachedObject(state);
  1067. }
  1068. }
  1069. @Get
  1070. @Path("/inviteStaffMail")
  1071. public boolean inviteStaffMail(@JdbcConn(false) Connection con, String orgId, String mail) throws SQLException, JfwBaseException {
  1072. Organization org = this.orgDao.query(con, orgId);
  1073. if (org == null) {
  1074. throw new JfwBaseException(-1, "系统没有该企业");
  1075. }
  1076. StateCode<String, String> sc = new StateCode<String, String>();
  1077. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1078. Map<String, String> map = new HashMap<>();
  1079. map.put(this.inviteStaffReplaceKey, key);
  1080. String mailContent = this.inviteStaffMailTempalte;
  1081. mailContent = mailContent.replaceAll(this.inviteStaffOrgKey, org.getName());
  1082. try {
  1083. this.mailservice.sendSimpleMail(mail, mailContent, map, this.inviteStaffSubject);
  1084. } catch (MessagingException e) {
  1085. JfwAppContext.removeCachedObject(key);
  1086. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1087. }
  1088. sc.setKey(orgId);
  1089. sc.setValue(mail);
  1090. sc.setCode(org.getName());
  1091. return true;
  1092. }
  1093. @Post
  1094. @Path("/retrieveOrgSuccess")
  1095. public boolean retrieveOrgUserSuccess(@JdbcConn(false) Connection con, String mail) throws SQLException, JfwBaseException {
  1096. try {
  1097. this.mailservice.sendSimpleMail(mail, this.retrieveOrgSuccessTempalte, null, this.retrieveOrgSuccessSubject);
  1098. } catch (MessagingException e) {
  1099. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1100. }
  1101. return true;
  1102. }
  1103. @Post
  1104. @Path("/retrieveOrgFail")
  1105. public boolean retrieveOrgUserFail(@JdbcConn(false) Connection con, String mail) throws SQLException, JfwBaseException {
  1106. try {
  1107. this.mailservice.sendSimpleMail(mail, this.retrieveOrgFailTempalte, null, this.retrieveOrgFailSubject);
  1108. } catch (MessagingException e) {
  1109. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1110. }
  1111. return true;
  1112. }
  1113. @SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
  1114. "userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
  1115. "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
  1116. @Post
  1117. @Path("/invitelogin")
  1118. public SessionUser inviteLogin(@JdbcConn Connection con, String key, String code) throws SQLException {
  1119. User user = userDao.queryByEmailOrMobilePhone(con, key);
  1120. if (null == user) {
  1121. return null;
  1122. }
  1123. if (!user.getInviteCode().equals(code)) {
  1124. return null;
  1125. }
  1126. Professor professor = this.professorDao.query(con, user.getId());
  1127. SessionUser ret = new SessionUser();
  1128. ret.setId(user.getId());
  1129. ret.setMobilePhone(user.getMobilePhone());
  1130. ret.setType(user.getUserType());
  1131. ret.setEmail(user.getEmail());
  1132. ret.setName(professor.getName());
  1133. ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
  1134. return ret;
  1135. }
  1136. @SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
  1137. "userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
  1138. "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
  1139. @Post
  1140. @Path("/slogin")
  1141. public SessionUser sLogin(@JdbcConn Connection con, String code, String mobile) throws SQLException {
  1142. User user = userDao.query(con, code);
  1143. if (null == user)
  1144. return null;
  1145. if (!mobile.equals(user.getMobilePhone()))
  1146. return null;
  1147. Professor professor = this.professorDao.query(con, code);
  1148. SessionUser ret = new SessionUser();
  1149. ret.setId(code);
  1150. ret.setMobilePhone(mobile);
  1151. ret.setType(user.getUserType());
  1152. ret.setEmail(user.getEmail());
  1153. ret.setName(professor.getName());
  1154. ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
  1155. return ret;
  1156. }
  1157. @SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
  1158. "userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
  1159. "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
  1160. @Post
  1161. @Path("/login")
  1162. public SessionUser login(@JdbcConn Connection con, String lk, String pw) throws SQLException, JfwBaseException {
  1163. User user = userDao.queryByEmailOrMobilePhone(con, lk);
  1164. if (null == user)
  1165. throw new JfwBaseException(-1, "该用户还未注册");
  1166. if (DEFAULT_PASS_WORD.equals(user.getPasswd()))
  1167. return null;
  1168. if (!StringUtil.md5(pw).equals(user.getPasswd()))
  1169. return null;
  1170. SessionUser ret = new SessionUser();
  1171. ret.setId(user.getId());
  1172. Professor pf = this.professorDao.query(con, user.getId());
  1173. if (null != pf) {
  1174. ret.setName(pf.getName());
  1175. }
  1176. ret.setMobilePhone(user.getMobilePhone());
  1177. ret.setType(user.getUserType());
  1178. ret.setEmail(user.getEmail());
  1179. ret.setAuth(true);
  1180. return ret;
  1181. }
  1182. @SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userMobilePhone=result.getMobilePhone()", "userType=result.getType()",
  1183. "userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
  1184. "userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
  1185. @Post
  1186. @Path("/mobileLogin")
  1187. public SessionUser mobileLogin(@JdbcConn Connection con, String state, String mobilePhone, String validateCode) throws SQLException, JfwBaseException {
  1188. @SuppressWarnings("unchecked")
  1189. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1190. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
  1191. throw new JfwBaseException(-1, "验证超时");
  1192. }
  1193. if (!sc.getKey().equals(mobilePhone)) {
  1194. throw new JfwBaseException(-2, "手机号与验证手机不匹配");
  1195. }
  1196. if (!sc.getValue().equals(validateCode)) {
  1197. throw new JfwBaseException(-3, "验证码错误");
  1198. }
  1199. User user = userDao.queryByEmailOrMobilePhone(con, mobilePhone);
  1200. if (null == user) {
  1201. throw new JfwBaseException(-4, "该用户还未注册");
  1202. }
  1203. try {
  1204. SessionUser ret = new SessionUser();
  1205. ret.setId(user.getId());
  1206. Professor professor = this.professorDao.query(con, user.getId());
  1207. if (null != professor) {
  1208. ret.setName(professor.getName());
  1209. }
  1210. ret.setMobilePhone(user.getMobilePhone());
  1211. ret.setType(user.getUserType());
  1212. ret.setEmail(user.getEmail());
  1213. ret.setAuth(!DEFAULT_PASS_WORD.equals(user.getPasswd()));
  1214. return ret;
  1215. } finally {
  1216. JfwAppContext.removeCachedObject(state);
  1217. }
  1218. }
  1219. @SetCookie(checkResultNull = true, path = "/", value = { "orgId=result.getId()", "orgType=result.getType()", "orgAuth=String.valueOf(result.isAuth())",
  1220. "orgEmail=result.getEmail()==null?\"\":result.getEmail()",
  1221. "orgName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
  1222. @Post
  1223. @Path("/orgLogin")
  1224. public SessionUser orgLogin(@JdbcConn Connection con, String lk, String pw) throws SQLException, JfwBaseException {
  1225. OrgUser orgUser = this.orgUserDao.queryByEmail(con, lk);
  1226. if (null == orgUser)
  1227. throw new JfwBaseException(-1, "该用户还未注册");
  1228. if (!StringUtil.md5(pw).equals(orgUser.getPasswd()))
  1229. return null;
  1230. SessionUser ret = new SessionUser();
  1231. ret.setId(orgUser.getId());
  1232. Organization org = this.orgDao.query(con, orgUser.getId());
  1233. if (org != null) {
  1234. ret.setName(org.getName());
  1235. }
  1236. ret.setType(orgUser.getUserType());
  1237. ret.setEmail(orgUser.getEmail());
  1238. ret.setAuth(true);
  1239. return ret;
  1240. }
  1241. @Post
  1242. @Path("/cp")
  1243. public boolean changePw(@JdbcConn(true) Connection con, String id, String npw, @Nullable String onw) throws SQLException {
  1244. if (onw == null) {
  1245. return this.userDao.updatePasswdAndActive(con, StringUtil.md5(npw), DATE.format(new Date()), id) > 0;
  1246. } else {
  1247. return this.userDao.updatePasswd(con, StringUtil.md5(npw), id, StringUtil.md5(onw)) > 0;
  1248. }
  1249. }
  1250. @Post
  1251. @Path("/cpOrg")
  1252. public boolean changeOrgPw(@JdbcConn(true) Connection con, String id, String npw, String onw) throws SQLException {
  1253. return this.orgUserDao.updatePw(con, id, StringUtil.md5(npw), StringUtil.md5(onw)) > 0;
  1254. }
  1255. @Get
  1256. @Path("/reqBindMail")
  1257. public boolean reqBindMail(@JdbcConn(false) Connection con, String userid, String mail) throws JfwBaseException, SQLException {
  1258. User user = this.userDao.query(con, userid);
  1259. if (null == user)
  1260. return false;
  1261. StateCode<String, String> sc = new StateCode<String, String>();
  1262. sc.setKey(userid);
  1263. sc.setValue(mail);
  1264. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1265. Map<String, String> map = new HashMap<String, String>();
  1266. map.put(this.bindMailReplaceKey, key);
  1267. try {
  1268. mailservice.sendSimpleMail(mail, this.bindMailReplaceContentTempalte, map, this.bindMailSubject);
  1269. long ct = System.currentTimeMillis();
  1270. long et = ct + this.timeLimitWithBindMail + 10000;
  1271. sc.setBuildTime(ct);
  1272. sc.setExpiredTime(et);
  1273. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1274. @Override
  1275. public void run() {
  1276. JfwAppContext.removeCachedObject(key);
  1277. }
  1278. }, this.timeLimitWithBindMail + 20000, TimeUnit.MILLISECONDS);
  1279. } catch (Exception e) {
  1280. JfwAppContext.removeCachedObject(key);
  1281. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1282. }
  1283. return true;
  1284. }
  1285. @Get
  1286. @Path("/bindMail/{key}")
  1287. public boolean bindMail(@JdbcConn(true) Connection con, @PathVar String key) throws SQLException, JfwBaseException {
  1288. @SuppressWarnings("unchecked")
  1289. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  1290. if (sc == null)
  1291. return false;
  1292. if (sc.getExpiredTime() < System.currentTimeMillis())
  1293. return false;
  1294. try {
  1295. Professor professor = this.professorDao.queryOne(con, sc.getKey());
  1296. if (professor.getPhone() == null || professor.getPhone().isEmpty()) {
  1297. this.professorDao.updateEmail(con, sc.getKey(), sc.getValue());
  1298. }
  1299. this.userDao.updateEmail(con, sc.getValue(), sc.getKey());
  1300. this.growthLogService.bindEmail(con, sc.getKey());
  1301. return true;
  1302. } finally {
  1303. JfwAppContext.removeCachedObject(key);
  1304. }
  1305. }
  1306. @Get
  1307. @Path("/reqBindOrgMail")
  1308. public boolean reqBindOrgMail(@JdbcConn(false) Connection con, String id, String mail) throws JfwBaseException, SQLException {
  1309. OrgUser orgUser = this.orgUserDao.queryOne(con, id);
  1310. if (null == orgUser)
  1311. return false;
  1312. StateCode<String, String> sc = new StateCode<String, String>();
  1313. sc.setKey(id);
  1314. sc.setValue(mail);
  1315. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1316. Map<String, String> map = new HashMap<String, String>();
  1317. map.put(this.bindOrgMailReplaceKey, key);
  1318. try {
  1319. mailservice.sendSimpleMail(mail, this.bindOrgMailReplaceContentTempalte, map, this.bindOrgMailSubject);
  1320. long ct = System.currentTimeMillis();
  1321. long et = ct + this.timeLimitWithBindOrgMail + 10000;
  1322. sc.setBuildTime(ct);
  1323. sc.setExpiredTime(et);
  1324. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1325. @Override
  1326. public void run() {
  1327. JfwAppContext.removeCachedObject(key);
  1328. }
  1329. }, this.timeLimitWithBindOrgMail + 20000, TimeUnit.MILLISECONDS);
  1330. } catch (Exception e) {
  1331. JfwAppContext.removeCachedObject(key);
  1332. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1333. }
  1334. return true;
  1335. }
  1336. @Get
  1337. @Path("/bindOrgMail/{key}")
  1338. public String bindOrgMail(@JdbcConn(true) Connection con, @PathVar String key) throws SQLException, JfwBaseException {
  1339. @SuppressWarnings("unchecked")
  1340. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(key);
  1341. if (sc == null || sc.getExpiredTime() < System.currentTimeMillis()) {
  1342. throw new JfwBaseException(-1, "验证链接已失效");
  1343. }
  1344. try {
  1345. this.orgUserDao.updateEmail(con, sc.getKey(), sc.getValue());
  1346. return sc.getValue();
  1347. } finally {
  1348. JfwAppContext.removeCachedObject(key);
  1349. }
  1350. }
  1351. @Get
  1352. @Path("/vcWithBind")
  1353. public String reqBindBindMobilePhone(@JdbcConn(false) Connection con, String userid, String mobilePhone) throws JfwBaseException, SQLException {
  1354. User user = this.userDao.query(con, userid);
  1355. if (null == user)
  1356. return null;
  1357. user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
  1358. if (null != user)
  1359. throw new JfwBaseException(-1, "该手机号已经绑定其他用户");
  1360. StateCode<String, String> sc = new StateCode<String, String>();
  1361. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1362. try {
  1363. Random rd = new Random();
  1364. int vi = rd.nextInt(10000);
  1365. String vc = String.format("%04d", vi);
  1366. sc.setKey(mobilePhone);
  1367. sc.setValue(vc);
  1368. this.mobilePhoneServcie.sendMessage(mobilePhone, this.bindMobilePhoneContentTemplate, this.bindMobilePhoneReplaceKey, vc);
  1369. long ct = System.currentTimeMillis();
  1370. long et = ct + this.timeLimitWithBindMobilePhone + 5000;
  1371. sc.setBuildTime(ct);
  1372. sc.setExpiredTime(et);
  1373. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1374. @Override
  1375. public void run() {
  1376. JfwAppContext.removeCachedObject(key);
  1377. }
  1378. }, this.timeLimitWithBindMobilePhone + 10000, TimeUnit.MILLISECONDS);
  1379. } catch (Exception e) {
  1380. JfwAppContext.removeCachedObject(key);
  1381. throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
  1382. }
  1383. return key;
  1384. }
  1385. /**
  1386. * 发送手机验证码
  1387. *
  1388. * @param con
  1389. * @param mobilePhone
  1390. * 验证的手机号
  1391. * @return
  1392. * @throws JfwBaseException
  1393. * @throws SQLException
  1394. */
  1395. @Get
  1396. @Path("/regmobilephone")
  1397. public String regMobilePhone(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
  1398. User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
  1399. if (null != user) {
  1400. return null;
  1401. }
  1402. StateCode<String, String> sc = new StateCode<String, String>();
  1403. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1404. try {
  1405. Random rd = new Random();
  1406. int vi = rd.nextInt(10000);
  1407. String vc = String.format("%04d", vi);
  1408. sc.setKey(mobilePhone);
  1409. sc.setValue(vc);
  1410. this.mobilePhoneServcie.sendMessage(mobilePhone, this.regMobilePhoneContentTemplate, this.regMobilePhoneReplaceKey, vc);
  1411. long ct = System.currentTimeMillis();
  1412. long et = ct + this.timeLimitWithRegMobilePhone + 5000;
  1413. sc.setBuildTime(ct);
  1414. sc.setExpiredTime(et);
  1415. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1416. @Override
  1417. public void run() {
  1418. JfwAppContext.removeCachedObject(key);
  1419. }
  1420. }, this.timeLimitWithRegMobilePhone + 10000, TimeUnit.MILLISECONDS);
  1421. } catch (Exception e) {
  1422. JfwAppContext.removeCachedObject(key);
  1423. throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
  1424. }
  1425. return key;
  1426. }
  1427. @Get
  1428. @Path("/sendMobileForLogin")
  1429. public String sendMobileForLogin(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
  1430. User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
  1431. if (null == user) {
  1432. return null;
  1433. }
  1434. StateCode<String, String> sc = new StateCode<String, String>();
  1435. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1436. try {
  1437. Random rd = new Random();
  1438. int vi = rd.nextInt(10000);
  1439. String vc = String.format("%04d", vi);
  1440. sc.setKey(mobilePhone);
  1441. sc.setValue(vc);
  1442. this.mobilePhoneServcie.sendMessage(mobilePhone, this.loginMobilePhoneContentTemplate, this.loginMobilePhoneReplaceKey, vc);
  1443. long ct = System.currentTimeMillis();
  1444. long et = ct + this.timeLimitWithLoginMobilePhone + 5000;
  1445. sc.setBuildTime(ct);
  1446. sc.setExpiredTime(et);
  1447. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1448. @Override
  1449. public void run() {
  1450. JfwAppContext.removeCachedObject(key);
  1451. }
  1452. }, this.timeLimitWithLoginMobilePhone + 10000, TimeUnit.MILLISECONDS);
  1453. } catch (Exception e) {
  1454. JfwAppContext.removeCachedObject(key);
  1455. throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
  1456. }
  1457. return key;
  1458. }
  1459. @Post
  1460. @Path("/bindMobilePhone")
  1461. public boolean bindMobilePhone(@JdbcConn(true) Connection con, String state, String userid, String mobilePhone, String validateCode)
  1462. throws SQLException, JfwBaseException {
  1463. @SuppressWarnings("unchecked")
  1464. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1465. if (sc == null)
  1466. return false;
  1467. if (sc.getExpiredTime() < System.currentTimeMillis())
  1468. return false;
  1469. try {
  1470. if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(validateCode))
  1471. return false;
  1472. Professor professor = this.professorDao.queryOne(con, userid);
  1473. if (professor.getPhone() == null || professor.getPhone().isEmpty()) {
  1474. this.professorDao.updatePhone(con, userid, mobilePhone);
  1475. }
  1476. this.userDao.updateMobilePhone(con, mobilePhone, userid);
  1477. this.growthLogService.bindMobile(con, userid);
  1478. return true;
  1479. } finally {
  1480. JfwAppContext.removeCachedObject(state);
  1481. }
  1482. }
  1483. @Get
  1484. @Path("/vcWithRP")
  1485. public String rePassWordWithPhone(@JdbcConn(false) Connection con, String mobilePhone) throws JfwBaseException, SQLException {
  1486. User user = this.userDao.queryByEmailOrMobilePhone(con, mobilePhone);
  1487. if (null == user)
  1488. throw new JfwBaseException(-1, "该手机号还未注册");
  1489. StateCode<String, String> sc = new StateCode<String, String>();
  1490. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1491. try {
  1492. Random rd = new Random();
  1493. int vi = rd.nextInt(10000);
  1494. String vc = String.format("%04d", vi);
  1495. sc.setKey(mobilePhone);
  1496. sc.setValue(vc);
  1497. this.mobilePhoneServcie.sendMessage(mobilePhone, this.phoneRetrievePasswordContentTemplate, this.phoneRetrievePasswordReplaceKey, vc);
  1498. long ct = System.currentTimeMillis();
  1499. long et = ct + this.timeLimitWithPhoneRetrievePassword + 5000;
  1500. sc.setBuildTime(ct);
  1501. sc.setExpiredTime(et);
  1502. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1503. @Override
  1504. public void run() {
  1505. JfwAppContext.removeCachedObject(key);
  1506. }
  1507. }, this.timeLimitWithPhoneRetrievePassword + 10000, TimeUnit.MILLISECONDS);
  1508. } catch (Exception e) {
  1509. JfwAppContext.removeCachedObject(key);
  1510. throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
  1511. }
  1512. return key;
  1513. }
  1514. @Post
  1515. @Path("/validCode")
  1516. public boolean validCode(String state, String vc) throws JfwBaseException {
  1517. @SuppressWarnings("unchecked")
  1518. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1519. if (sc == null) {
  1520. throw new JfwBaseException("验证超时");
  1521. }
  1522. if (sc.getExpiredTime() < System.currentTimeMillis()) {
  1523. throw new JfwBaseException("验证超时");
  1524. }
  1525. return sc.getValue().equals(vc);
  1526. }
  1527. @Post
  1528. @Path("/checkPicture")
  1529. public boolean checkPictureVC(@SessionVal(value = "verification", defaultvalue = "null", remove = true) String verification, String submitVerification)
  1530. throws JfwBaseException {
  1531. if (null == verification) {
  1532. throw new JfwBaseException("Picture is expire !");
  1533. }
  1534. return verification.equals(submitVerification);
  1535. }
  1536. @Post
  1537. @Path("/resetPasswordWithMobilePhone")
  1538. public boolean resetPassword(@JdbcConn(true) Connection con, String state, String mobilePhone, String pw, String vc) throws SQLException, JfwBaseException {
  1539. @SuppressWarnings("unchecked")
  1540. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1541. if (sc == null) {
  1542. throw new JfwBaseException("验证超时");
  1543. }
  1544. if (sc.getExpiredTime() < System.currentTimeMillis()) {
  1545. throw new JfwBaseException("验证超时");
  1546. }
  1547. try {
  1548. if (!sc.getKey().equals(mobilePhone) || !sc.getValue().equals(vc))
  1549. return false;
  1550. int ret = this.userDao.updatePasswdWithMobile(con, StringUtil.md5(pw), DATE.format(new Date()), mobilePhone);
  1551. if (ret == 0) {
  1552. return this.userDao.updatePasswordWithMobileOrEmail(con, StringUtil.md5(pw), mobilePhone) > 0;
  1553. }
  1554. return ret > 0;
  1555. } finally {
  1556. JfwAppContext.removeCachedObject(state);
  1557. }
  1558. }
  1559. @Get
  1560. @Path("/reqRpWithEmail")
  1561. public boolean reqRpWithEmail(@JdbcConn(false) Connection con, String mail) throws JfwBaseException, SQLException {
  1562. User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
  1563. if (user == null)
  1564. return false;
  1565. StateCode<String, String> sc = new StateCode<String, String>();
  1566. sc.setKey(user.getId());
  1567. sc.setValue(mail);
  1568. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1569. Map<String, String> map = new HashMap<String, String>();
  1570. map.put(this.mailRetrievePasswordReplaceKey, key);
  1571. try {
  1572. mailservice.sendSimpleMail(mail, this.mailRetrievePasswordContentTemplate, map, this.mailRetrievePasswordSubject);
  1573. long ct = System.currentTimeMillis();
  1574. long et = ct + this.timeLimitWithMailRetrivePassword + 10000;
  1575. sc.setBuildTime(ct);
  1576. sc.setExpiredTime(et);
  1577. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1578. @Override
  1579. public void run() {
  1580. JfwAppContext.removeCachedObject(key);
  1581. }
  1582. }, this.timeLimitWithMailRetrivePassword + 20000, TimeUnit.MILLISECONDS);
  1583. } catch (Exception e) {
  1584. JfwAppContext.removeCachedObject(key);
  1585. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1586. }
  1587. return true;
  1588. }
  1589. @Get
  1590. @Path("/validMailState")
  1591. public boolean validMailState(String state) {
  1592. @SuppressWarnings("unchecked")
  1593. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1594. if (sc == null)
  1595. return false;
  1596. if (sc.getExpiredTime() < System.currentTimeMillis())
  1597. return false;
  1598. return true;
  1599. }
  1600. @Post
  1601. @Path("/resetPasswordWith")
  1602. public boolean resetPassword(@JdbcConn(true) Connection con, String state, String pw) throws SQLException, JfwBaseException {
  1603. @SuppressWarnings("unchecked")
  1604. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1605. if (sc == null)
  1606. throw new JfwBaseException("验证超时");
  1607. if (sc.getExpiredTime() < System.currentTimeMillis())
  1608. throw new JfwBaseException("验证超时");
  1609. String key = sc.getKey();
  1610. try {
  1611. int ret = this.userDao.updatePasswdAndActive(con, StringUtil.md5(pw), DATE.format(new Date()), key);
  1612. if (ret == 0) {
  1613. return this.userDao.updatePassword(con, StringUtil.md5(pw), key) > 0;
  1614. }
  1615. return ret > 0;
  1616. } finally {
  1617. JfwAppContext.removeCachedObject(state);
  1618. }
  1619. }
  1620. @Get
  1621. @Path("/resetWithOrgEmail")
  1622. public boolean resetWithOrgEmail(@JdbcConn(false) Connection con, String mail) throws JfwBaseException, SQLException {
  1623. OrgUser orgUser = this.orgUserDao.queryByEmail(con, mail);
  1624. if (orgUser == null)
  1625. return false;
  1626. StateCode<String, String> sc = new StateCode<String, String>();
  1627. sc.setKey(orgUser.getId());
  1628. sc.setValue(mail);
  1629. final String key = JfwAppContext.cacheObjectAndGenKey(sc);
  1630. Map<String, String> map = new HashMap<String, String>();
  1631. map.put(this.orgMailRetrievePasswordReplaceKey, key);
  1632. try {
  1633. mailservice.sendSimpleMail(mail, this.orgMailRetrievePasswordContentTemplate, map, this.orgMailRetrievePasswordSubject);
  1634. long ct = System.currentTimeMillis();
  1635. long et = ct + this.timeLimitWithOrgMailRetrivePassword + 10000;
  1636. sc.setBuildTime(ct);
  1637. sc.setExpiredTime(et);
  1638. JfwAppContext.getScheduledExecutorService().schedule(new Runnable() {
  1639. @Override
  1640. public void run() {
  1641. JfwAppContext.removeCachedObject(key);
  1642. }
  1643. }, this.timeLimitWithOrgMailRetrivePassword + 20000, TimeUnit.MILLISECONDS);
  1644. } catch (Exception e) {
  1645. JfwAppContext.removeCachedObject(key);
  1646. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1647. }
  1648. return true;
  1649. }
  1650. @Post
  1651. @Path("/resetPwByOrgEmail")
  1652. public boolean resetPwByOrgEmail(@JdbcConn(true) Connection con, String state, String pw) throws SQLException, JfwBaseException {
  1653. @SuppressWarnings("unchecked")
  1654. StateCode<String, String> sc = (StateCode<String, String>) JfwAppContext.getCachedObject(state);
  1655. if (sc == null)
  1656. throw new JfwBaseException("验证超时");
  1657. if (sc.getExpiredTime() < System.currentTimeMillis())
  1658. throw new JfwBaseException("验证超时");
  1659. String key = sc.getKey();
  1660. try {
  1661. return this.orgUserDao.updatePasswd(con, key, StringUtil.md5(pw)) > 0;
  1662. } finally {
  1663. JfwAppContext.removeCachedObject(state);
  1664. }
  1665. }
  1666. /**
  1667. * 给指定邮箱发送邀请邮件
  1668. *
  1669. * @param con
  1670. * @param mobilePhones
  1671. * 手机号数组
  1672. * @param emails
  1673. * 邮箱
  1674. * @param inviteCodes
  1675. * 邀请码
  1676. * @throws SQLException
  1677. * @throws MessagingException
  1678. */
  1679. @Post
  1680. @Path("/sendmail")
  1681. public int sendmail(@JdbcConn Connection con, @Nullable String[] mobilePhones, String[] emails, String[] inviteCodes)
  1682. throws SQLException, MessagingException {
  1683. for (int i = 0; i < emails.length; i++) {
  1684. if (mobilePhones[i] == "") {
  1685. mobilePhones[i] = null;
  1686. }
  1687. this.sendInviteMail(con, emails[i], mobilePhones[i], inviteCodes[i]);
  1688. this.logger.info("成功发送邀请邮件:" + emails[i]);
  1689. }
  1690. return emails.length;
  1691. }
  1692. public void sendInviteMail(@JdbcConn Connection con, String email, @Nullable String mobilePhone, String inviteCode)
  1693. throws SQLException, MessagingException {
  1694. String mailContent = this.inviteMailContentTempalte;
  1695. mailContent = mailContent.replaceAll(this.inviteReplaceEmail, email);
  1696. mailContent = mailContent.replaceAll(this.inviteReplaceCode, inviteCode);
  1697. String phoneReplace = "";
  1698. if (mobilePhone != null && mobilePhone.trim().length() == 11) {
  1699. String mobile = mobilePhone.trim();
  1700. mobile = mobile.substring(0, 3) + "****" + mobile.substring(7);
  1701. phoneReplace = this.phoneContentTemplate.replaceAll(this.phoneReplaceKey, mobile);
  1702. }
  1703. mailContent = mailContent.replaceAll(this.inviteReplacePhone, phoneReplace);
  1704. this.mailservice.sendSimpleMail(email, mailContent, null, this.inviteMailSubject);
  1705. }
  1706. public void sendConsultMail(String mail) throws SQLException, JfwBaseException {
  1707. try {
  1708. mailservice.sendSimpleMail(mail, this.sendConsultMailContentTemplate, null, this.sendConsultMailSubject);
  1709. } catch (Exception e) {
  1710. throw new JfwBaseException(10011, "send mail to " + mail + " error", e);
  1711. }
  1712. }
  1713. public void sendConsultSMS(String mobilePhone) throws SQLException, JfwBaseException {
  1714. try {
  1715. this.mobilePhoneServcie.sendMarketMessage(mobilePhone, this.sendConsultSMSContentTemplate);
  1716. } catch (Exception e) {
  1717. throw new JfwBaseException(10012, "send mobile phone message to " + mobilePhone + " error", e);
  1718. }
  1719. }
  1720. public static void main(String[] args) {
  1721. System.out.println(String.format("%04d", new Random().nextInt(10000)));
  1722. }
  1723. }