diff --git a/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java b/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java index 660542a..9568ee5 100644 --- a/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java +++ b/src/main/java/com/yipin/liuwanr/controller/UserInfoController.java @@ -305,10 +305,9 @@ public class UserInfoController { * 登陆查询学校/电子科大 */ @GetMapping("/loginSchoolClient") - Response loginSchoolClient(@RequestParam("account") String account, @RequestParam("password") String password, @RequestParam("schoolId") Integer schoolId , HttpServletRequest req, HttpServletResponse res) { + Response loginSchoolClient(@RequestParam("account") String account, @RequestParam("password") String password, @RequestParam("schoolId") Integer schoolId , + @RequestParam("source") Integer source, HttpServletRequest req, HttpServletResponse res) { Response resp = new Response(); - UserInfo userInfo = new UserInfo(); - userInfo.setSchoolId(schoolId);//暂定学校id if (account == null || account=="") { resp.setStatus(300); resp.setErrmessage("用户账号为空,登录失败!"); @@ -316,9 +315,7 @@ public class UserInfoController { resp.setStatus(300); resp.setErrmessage("用户密码为空,登录失败!"); }else{ - userInfo.setAccount(account); - userInfo.setPassword(password); - HashMap ret = userInfoService.loginSchoolClient(userInfo); + HashMap ret = userInfoService.loginSchoolClient(account,password,schoolId,source); int status = (int) ret.get("retcode"); if (200 == status) { resp.setStatus(status); @@ -331,54 +328,29 @@ public class UserInfoController { return resp; } - /** - * 登陆查询学校/职战 - */ - @GetMapping("/zzLoginSchoolClient") - Response zzLoginSchoolClient(@RequestParam("account") String account, @RequestParam("password") String password , HttpServletRequest req, HttpServletResponse res) { - Response resp = new Response(); - UserInfo userInfo = new UserInfo(); - userInfo.setSchoolId(2105);//暂定学校id - if (account == null || account=="") { - resp.setStatus(300); - resp.setErrmessage("用户账号为空,登录失败!"); - }else if(password ==null || password=="") { - resp.setStatus(300); - resp.setErrmessage("用户密码为空,登录失败!"); - }else{ - userInfo.setAccount(account); - userInfo.setPassword(password); - HashMap ret = userInfoService.loginSchoolClient(userInfo); - int status = (int) ret.get("retcode"); - if (200 == status) { - resp.setStatus(status); - resp.setMessage(ret.get("retvalue")); - } else { - resp.setStatus(status); - resp.setErrmessage(ret.get("retvalue").toString()); - } - } - return resp; - } + /** * 服务端登陆 + * + * @param account source是0就是用户账号、1则是手机号或邮箱 + * @param password 密码 + * @param source 来源区分 */ @GetMapping("/adminLogins") - Response adminLogins(@RequestParam("account") String account, @RequestParam("password") String password,HttpServletRequest req, HttpServletResponse res) { + Response adminLogins(@RequestParam("account") String account, @RequestParam("password") String password, + @RequestParam("source") Integer source, HttpServletRequest req, HttpServletResponse res) { Response resp = new Response(); - UserInfo userInfo = new UserInfo(); + HashMap map = new HashMap<>(); if (account == null) { resp.setStatus(300); resp.setErrmessage("用户账号为空,登录失败!"); - }else if(password ==null) { + }else if(password == null) { resp.setStatus(300); resp.setErrmessage("用户密码为空,登录失败!"); } else{ - userInfo.setAccount(account); - userInfo.setPassword(password); - HashMap ret = userInfoService.adminLogins(userInfo); + HashMap ret = userInfoService.adminLogins(account,password,source); int status = (int) ret.get("retcode"); if (200 == status) { diff --git a/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java b/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java index e2b0e7b..c5564f8 100644 --- a/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java +++ b/src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java @@ -129,11 +129,23 @@ public interface UserInfoMapper { UserInfo logins(UserInfo userInfo); //登陆 - @Select("SELECT token,userId,userName,roleId,userAvatars,password from hr_user_info where isdel=0 and (account = #{account} or phone = #{account}) and password = #{password}") + @Select({""}) UserInfo adminLogins(UserInfo userInfo); //登陆账号密码 - @Select("SELECT hui.schoolId,hui.account,hui.cityId,hui.countries,hui.creationTime,hui.dateBirth,hui.documentType,hui.educationDegree,hui.email,hui.iDNumber,hui.logInNumber,hui.phone,hui.provinceId,hui.sex,hui.uniqueIdentificationAccount,hui.userAvatars,hui.userId,hui.userName,hui.weChatID,hui.password from hr_user_info hui where hui.isdel=0 and (hui.account = #{account} or hui.phone = #{account}) and password = #{password} ") + @Select({""}) UserInfo loginsAP(UserInfo userInfo); //查询用户角色 @@ -338,7 +350,14 @@ public interface UserInfoMapper { ""}) void deleteOrganizationRelationship(Integer userId); - @Select("SELECT disableAccount FROM hr_user_info u LEFT JOIN student s ON u.userId = s.userId WHERE s.schoolId = #{schoolId} AND (account = #{account} OR phone = #{account}) AND u.isdel = 0 AND s.isdel = 0") + @Select({""}) Integer queryDisableAccount(UserInfo userInfo); @Select("select roleId from hr_user_info where userId = #{userId}") diff --git a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java index 1d6c499..0df73e2 100644 --- a/src/main/java/com/yipin/liuwanr/service/UserInfoService.java +++ b/src/main/java/com/yipin/liuwanr/service/UserInfoService.java @@ -28,6 +28,8 @@ import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Service @@ -392,10 +394,28 @@ public class UserInfoService { return resp; } //登陆获取学校/电子科大 - public HashMap loginSchoolClient(UserInfo userInfo){ + public HashMap loginSchoolClient(String account,String password,Integer schoolId,Integer source){ HashMap resp = new HashMap(); HashMap obj = new HashMap(); - Integer schoolId = userInfo.getSchoolId(); + UserInfo userInfo = new UserInfo(); + userInfo.setPassword(password); + userInfo.setSchoolId(schoolId); + if (source == 0){ + //账号 + userInfo.setAccount(account); + }else if(source == 1){ + if (checkPhone(account)){ + //手机号 + userInfo.setPhone(account); + }else if (checkEmail(account)){ + //邮箱 + userInfo.setEmail(account); + }else { + //防止邮箱,手机号格式错误 sql能正确执行 + userInfo.setAccount("!@#$%^&*()_+"); + } + } + Integer state = userInfoMapper.queryDisableAccount(userInfo); if (state==null){ resp.put("retcode",300); @@ -406,7 +426,7 @@ public class UserInfoService { //区分密码大小写 boolean num = false; if (user != null){ - num = userInfo.getPassword().equals(user.getPassword()); + num = password.equals(user.getPassword()); } if(user!=null && num == true) { @@ -475,14 +495,31 @@ public class UserInfoService { } //登陆 - public HashMap adminLogins(UserInfo userInfo){ + public HashMap adminLogins(String account,String password,Integer source){ HashMap resp = new HashMap(); + UserInfo user = new UserInfo(); + user.setPassword(password); try { - UserInfo user=userInfoMapper.adminLogins(userInfo); + if (source == 0){ + user.setAccount(account); + }else if (source == 1){ + if (checkPhone(account)){ + //手机号 + user.setPhone(account); + }else if (checkEmail(account)){ + //邮箱 + user.setEmail(account); + }else { + //防止邮箱,手机号格式错误 sql能正确执行 + user.setAccount("!@#$%^&*()_+"); + } + } + user = userInfoMapper.adminLogins(user); + //区分密码大小写 boolean num = false; if (user != null){ - num = userInfo.getPassword().equals(user.getPassword()); + num = password.equals(user.getPassword()); user.setPassword(null); } if(user != null){ @@ -504,8 +541,8 @@ public class UserInfoService { userInfoMapper.updateLogInNumber(user); String token = user.getToken(); ValueOperations redis = stringRedisTemplate.opsForValue(); - redis.set(token,lastLoginTime, 24, TimeUnit.HOURS); - user.setDataTime(lastLoginTime); + //redis.set(token,lastLoginTime, 24, TimeUnit.HOURS); + //user.setDataTime(lastLoginTime); resp.put("retvalue",user); resp.put("retcode", 200); } @@ -827,4 +864,39 @@ public class UserInfoService { } return resp; } + + /** + * 验证邮箱 + * @param email + * @return + */ + public boolean checkEmail(String email){ + boolean flag = false; + try{ + Pattern regex = Pattern.compile("^([a-zA-Z]|[0-9])(\\w|\\-)+@[a-zA-Z0-9]+\\.([a-zA-Z]{2,4})$"); + Matcher matcher = regex.matcher(email); + flag = matcher.matches(); + }catch(Exception e){ + flag = false; + } + return flag; + } + + /** + * 验证手机号码 + * @param phone + * @return + */ + public boolean checkPhone(String phone){ + boolean flag = false; + try{ + Pattern regex = Pattern.compile("^1[3456789]\\d{9}$"); + Matcher matcher = regex.matcher(phone); + flag = matcher.matches(); + }catch(Exception e){ + flag = false; + } + return flag; + } + }