Browse Source

--add isRegOrg();update orgLogin();

zzy.zhiyuan.foxmail 8 years ago
parent
commit
54d0bf8724
1 changed files with 45 additions and 25 deletions
  1. 45 25
      src/main/java/com/ekexiu/portal/service/SysService.java

+ 45 - 25
src/main/java/com/ekexiu/portal/service/SysService.java

@ -28,10 +28,12 @@ import org.jfw.util.exception.JfwBaseException;
28 28
import org.jfw.util.state.StateCode;
29 29
30 30
import com.ekexiu.portal.dao.OrgDao;
31
import com.ekexiu.portal.dao.OrgUserDao;
31 32
import com.ekexiu.portal.dao.ProfessorDao;
32 33
import com.ekexiu.portal.dao.UserDao;
33 34
import com.ekexiu.portal.mail.MailService;
34 35
import com.ekexiu.portal.mobile.MobilePhoneService;
36
import com.ekexiu.portal.po.OrgUser;
35 37
import com.ekexiu.portal.po.Organization;
36 38
import com.ekexiu.portal.po.Professor;
37 39
import com.ekexiu.portal.po.User;
@ -46,6 +48,8 @@ public class SysService {
46 48
	@Autowrie
47 49
	private UserDao userDao;
48 50
	@Autowrie
51
	private OrgUserDao orgUserDao;
52
	@Autowrie
49 53
	private OrgDao orgDao;
50 54
	@Autowrie
51 55
	private OrgService orgService;
@ -329,6 +333,14 @@ public class SysService {
329 333
		this.userDao = userDao;
330 334
	}
331 335
336
	public OrgUserDao getOrgUserDao() {
337
		return orgUserDao;
338
	}
339
340
	public void setOrgUserDao(OrgUserDao orgUserDao) {
341
		this.orgUserDao = orgUserDao;
342
	}
343
332 344
	public OrgDao getOrgDao() {
333 345
		return orgDao;
334 346
	}
@ -421,6 +433,17 @@ public class SysService {
421 433
		}
422 434
	}
423 435
	
436
	@Get
437
	@Path("/isRegOrg")
438
	public boolean isRegOrg(@JdbcConn Connection con,String email)throws SQLException{
439
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, email);
440
		if(null != orgUser){
441
			return false;
442
		}else{
443
			return true;
444
		}
445
	}
446
	
424 447
	@Get
425 448
	@Path("/isOrgUser")
426 449
	public boolean isOrgUser(@JdbcConn Connection con,String orgName)throws SQLException, JfwBaseException{
@ -428,7 +451,7 @@ public class SysService {
428 451
		if(orgId == null){
429 452
			return true;
430 453
		}else{
431
			if(this.userDao.query(con, orgId) == null){
454
			if(this.orgUserDao.queryOne(con, orgId) == null){
432 455
				return true;
433 456
			}else{
434 457
				if("3".equals(this.orgDao.query(con, orgId).getAuthStatus())){
@ -603,23 +626,21 @@ public class SysService {
603 626
			throw new JfwBaseException(-1, "验证链接已失效");
604 627
		}
605 628
		String orgId = this.orgDao.queryByName(con, sc.getValue());
606
		if((orgId != null) && (this.userDao.query(con, orgId) != null)){
629
		if((orgId != null) && (this.orgUserDao.queryOne(con, orgId)!= null)){
607 630
			throw new JfwBaseException(2, "该企业已注册科袖账号");
608 631
		}
609 632
		try {
610
			User user = new User();
611
			user.setEmail(sc.getCode());
633
			OrgUser orgUser = new OrgUser();
634
			orgUser.setEmail(sc.getCode());
612 635
			if(orgId != null){
613
				user.setId(orgId);
636
				orgUser.setId(orgId);
614 637
			}else{
615
				user.setId(this.orgService.createOrganization(con, sc.getValue()));
638
				orgUser.setId(this.orgService.createOrganization(con, sc.getValue()));
616 639
			}
617
			user.setSendMailStatus(0);
618
			user.setPasswd(StringUtil.md5(sc.getKey()));
619
			user.setUserType("1");
620
			user.setActiveTime(DATE.format(new Date()));
621
			this.userDao.insert(con, user);
622
			this.orgDao.updateIsJoin(con, user.getId(), "1");
640
			orgUser.setPasswd(StringUtil.md5(sc.getKey()));
641
			orgUser.setUserType("1");
642
			this.orgUserDao.insert(con, orgUser);
643
			this.orgDao.updateIsJoin(con, orgUser.getId(), "1");
623 644
			con.commit();
624 645
		} catch (SQLException e) {
625 646
			try {
@ -647,8 +668,8 @@ public class SysService {
647 668
	@Post
648 669
	@Path("/regOrgMail")
649 670
	public void regOrgMail(@JdbcConn(false) Connection con,String orgName,String mail,String password)throws JfwBaseException, SQLException {
650
		User user = this.userDao.queryByEmailOrMobilePhone(con, mail);
651
		if (null != user) {
671
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, mail);
672
		if (null != orgUser) {
652 673
			throw new JfwBaseException(-1, "邮箱[" + mail + "]已被注册过了");
653 674
		} else {
654 675
@ -776,27 +797,26 @@ public class SysService {
776 797
		return ret;
777 798
	}
778 799
	
779
	@SetCookie(checkResultNull = true, path = "/", value = { "userid=result.getId()", "userType=result.getType()",
780
			"userAuth=String.valueOf(result.isAuth())", "userEmail=result.getEmail()==null?\"\":result.getEmail()",
781
			"userName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")","userAuthStatus=result.getAuthStatus()"})
800
	@SetCookie(checkResultNull = true, path = "/", value = { "orgId=result.getId()", "orgType=result.getType()",
801
			"orgAuth=String.valueOf(result.isAuth())", "orgEmail=result.getEmail()==null?\"\":result.getEmail()",
802
			"orgName=result.getName()==null?\"\":java.net.URLEncoder.encode(result.getName(),\"utf-8\")" })
782 803
	@Post
783 804
	@Path("/orgLogin")
784 805
	public SessionUser orgLogin(@JdbcConn Connection con, String lk, String pw) throws SQLException, JfwBaseException {
785
		User user = userDao.queryByEmailOrMobilePhone(con, lk);
786
		if (null == user)
806
		OrgUser orgUser = this.orgUserDao.queryByEmail(con, lk);
807
		if (null == orgUser)
787 808
			throw new JfwBaseException(-1, "该用户还未注册");
788
		if (!StringUtil.md5(pw).equals(user.getPasswd()))
809
		if (!StringUtil.md5(pw).equals(orgUser.getPasswd()))
789 810
			return null;
790 811
791 812
		SessionUser ret = new SessionUser();
792
		ret.setId(user.getId());
793
		Organization org = this.orgDao.query(con, user.getId());
813
		ret.setId(orgUser.getId());
814
		Organization org = this.orgDao.query(con, orgUser.getId());
794 815
		if(org != null){
795 816
			ret.setName(org.getName());
796 817
		}
797
		ret.setAuthStatus(org.getAuthStatus());
798
		ret.setType(user.getUserType());
799
		ret.setEmail(user.getEmail());
818
		ret.setType(orgUser.getUserType());
819
		ret.setEmail(orgUser.getEmail());
800 820
		ret.setAuth(true);
801 821
		return ret;
802 822
	}