科大,职站 服务端,学生端登录接口修改

master
jiakun.lin 4 years ago
parent 032cee85a1
commit df29a46e60
  1. 52
      src/main/java/com/yipin/liuwanr/controller/UserInfoController.java
  2. 25
      src/main/java/com/yipin/liuwanr/mapper/UserInfoMapper.java
  3. 88
      src/main/java/com/yipin/liuwanr/service/UserInfoService.java

@ -305,10 +305,9 @@ public class UserInfoController {
* 登陆查询学校/电子科大 * 登陆查询学校/电子科大
*/ */
@GetMapping("/loginSchoolClient") @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(); Response resp = new Response();
UserInfo userInfo = new UserInfo();
userInfo.setSchoolId(schoolId);//暂定学校id
if (account == null || account=="") { if (account == null || account=="") {
resp.setStatus(300); resp.setStatus(300);
resp.setErrmessage("用户账号为空,登录失败!"); resp.setErrmessage("用户账号为空,登录失败!");
@ -316,9 +315,7 @@ public class UserInfoController {
resp.setStatus(300); resp.setStatus(300);
resp.setErrmessage("用户密码为空,登录失败!"); resp.setErrmessage("用户密码为空,登录失败!");
}else{ }else{
userInfo.setAccount(account); HashMap<String, Object> ret = userInfoService.loginSchoolClient(account,password,schoolId,source);
userInfo.setPassword(password);
HashMap<String, Object> ret = userInfoService.loginSchoolClient(userInfo);
int status = (int) ret.get("retcode"); int status = (int) ret.get("retcode");
if (200 == status) { if (200 == status) {
resp.setStatus(status); resp.setStatus(status);
@ -331,43 +328,20 @@ public class UserInfoController {
return resp; 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<String, Object> 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") @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(); Response resp = new Response();
UserInfo userInfo = new UserInfo();
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
if (account == null) { if (account == null) {
resp.setStatus(300); resp.setStatus(300);
@ -376,9 +350,7 @@ public class UserInfoController {
resp.setStatus(300); resp.setStatus(300);
resp.setErrmessage("用户密码为空,登录失败!"); resp.setErrmessage("用户密码为空,登录失败!");
} else{ } else{
userInfo.setAccount(account); HashMap<String, Object> ret = userInfoService.adminLogins(account,password,source);
userInfo.setPassword(password);
HashMap<String, Object> ret = userInfoService.adminLogins(userInfo);
int status = (int) ret.get("retcode"); int status = (int) ret.get("retcode");
if (200 == status) { if (200 == status) {

@ -129,11 +129,23 @@ public interface UserInfoMapper {
UserInfo logins(UserInfo userInfo); 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({"<script> " +
"SELECT token,userId,userName,roleId,userAvatars,password from hr_user_info where isdel=0" +
"<if test='account!=null'>and account = #{account} </if>" +
"<if test='phone!=null'>and phone = #{phone} </if>" +
"<if test='email!=null'>and email = #{email} </if>" +
"and password = #{password}" +
"</script>"})
UserInfo adminLogins(UserInfo userInfo); 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({"<script> " +
"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 " +
"<if test='account!=null'>and account = #{account} </if>" +
"<if test='phone!=null'>and phone = #{phone} </if>" +
"<if test='email!=null'>and email = #{email} </if>" +
"and password = #{password} " +
"</script>"})
UserInfo loginsAP(UserInfo userInfo); UserInfo loginsAP(UserInfo userInfo);
//查询用户角色 //查询用户角色
@ -338,7 +350,14 @@ public interface UserInfoMapper {
"</script>"}) "</script>"})
void deleteOrganizationRelationship(Integer userId); 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({"<script> " +
"SELECT disableAccount FROM hr_user_info u LEFT JOIN student s ON u.userId = s.userId " +
"WHERE s.schoolId = #{schoolId} " +
"<if test='account!=null'> AND account = #{account} </if> " +
"<if test='phone!=null'> AND phone = #{phone} </if>" +
"<if test='email!=null'> AND email = #{email} </if>" +
"AND u.isdel = 0 AND s.isdel = 0" +
"</script>"})
Integer queryDisableAccount(UserInfo userInfo); Integer queryDisableAccount(UserInfo userInfo);
@Select("select roleId from hr_user_info where userId = #{userId}") @Select("select roleId from hr_user_info where userId = #{userId}")

@ -28,6 +28,8 @@ import javax.annotation.Resource;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Service @Service
@ -392,10 +394,28 @@ public class UserInfoService {
return resp; return resp;
} }
//登陆获取学校/电子科大 //登陆获取学校/电子科大
public HashMap<String, Object> loginSchoolClient(UserInfo userInfo){ public HashMap<String, Object> loginSchoolClient(String account,String password,Integer schoolId,Integer source){
HashMap<String, Object> resp = new HashMap<String, Object>(); HashMap<String, Object> resp = new HashMap<String, Object>();
HashMap<String, Object> obj = new HashMap<String, Object>(); HashMap<String, Object> obj = new HashMap<String, Object>();
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); Integer state = userInfoMapper.queryDisableAccount(userInfo);
if (state==null){ if (state==null){
resp.put("retcode",300); resp.put("retcode",300);
@ -406,7 +426,7 @@ public class UserInfoService {
//区分密码大小写 //区分密码大小写
boolean num = false; boolean num = false;
if (user != null){ if (user != null){
num = userInfo.getPassword().equals(user.getPassword()); num = password.equals(user.getPassword());
} }
if(user!=null && num == true) { if(user!=null && num == true) {
@ -475,14 +495,31 @@ public class UserInfoService {
} }
//登陆 //登陆
public HashMap<String, Object> adminLogins(UserInfo userInfo){ public HashMap<String, Object> adminLogins(String account,String password,Integer source){
HashMap<String, Object> resp = new HashMap<String, Object>(); HashMap<String, Object> resp = new HashMap<String, Object>();
UserInfo user = new UserInfo();
user.setPassword(password);
try { 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; boolean num = false;
if (user != null){ if (user != null){
num = userInfo.getPassword().equals(user.getPassword()); num = password.equals(user.getPassword());
user.setPassword(null); user.setPassword(null);
} }
if(user != null){ if(user != null){
@ -504,8 +541,8 @@ public class UserInfoService {
userInfoMapper.updateLogInNumber(user); userInfoMapper.updateLogInNumber(user);
String token = user.getToken(); String token = user.getToken();
ValueOperations<String, String> redis = stringRedisTemplate.opsForValue(); ValueOperations<String, String> redis = stringRedisTemplate.opsForValue();
redis.set(token,lastLoginTime, 24, TimeUnit.HOURS); //redis.set(token,lastLoginTime, 24, TimeUnit.HOURS);
user.setDataTime(lastLoginTime); //user.setDataTime(lastLoginTime);
resp.put("retvalue",user); resp.put("retvalue",user);
resp.put("retcode", 200); resp.put("retcode", 200);
} }
@ -827,4 +864,39 @@ public class UserInfoService {
} }
return resp; 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;
}
} }

Loading…
Cancel
Save