修改了绑定网站账号的接口,添加重复绑定的判断
This commit is contained in:
parent
c7318dcc2a
commit
29a8c526f8
@ -17,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -247,9 +248,9 @@ public class SysUserController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/findUserByOpenId")
|
@PostMapping("/findUserByOpenId")
|
||||||
public String findUserByOpenId(@RequestBody Map map){
|
public String findUserByOpenId(@RequestBody Map map, HttpServletResponse response){
|
||||||
String openId = (String) map.get("openId");
|
String openId = (String) map.get("openId");
|
||||||
return sysUserService.findUserByOpenId(openId);
|
return sysUserService.findUserByOpenId(openId,response);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -267,6 +268,10 @@ public class SysUserController {
|
|||||||
if(byUserName == null){
|
if(byUserName == null){
|
||||||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"输入错误或未注册,请检查注册!",locale);
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"输入错误或未注册,请检查注册!",locale);
|
||||||
}
|
}
|
||||||
|
SysUserEntity byOpenId = sysUserDao.findByOpenId(openId);
|
||||||
|
if(byOpenId != null){
|
||||||
|
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"您已绑定网站账号,请勿重复绑定!",locale);
|
||||||
|
}
|
||||||
sysUserDao.updateOpenIdByPhone(phone,openId);
|
sysUserDao.updateOpenIdByPhone(phone,openId);
|
||||||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale);
|
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale);
|
||||||
}
|
}
|
||||||
|
@ -144,4 +144,12 @@ public interface SysUserDao extends JpaRepository<SysUserEntity,Integer> {
|
|||||||
@Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true)
|
@Query(value = "update sys_user set open_id = ?2 where user_name = ?1",nativeQuery = true)
|
||||||
@Modifying(clearAutomatically=true)
|
@Modifying(clearAutomatically=true)
|
||||||
void updateOpenIdByPhone(String userName,String openId);
|
void updateOpenIdByPhone(String userName,String openId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据openId和手机号查询信息
|
||||||
|
* @param openId
|
||||||
|
* @param userName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
SysUserEntity findByOpenIdAndUserName(String openId,String userName);
|
||||||
}
|
}
|
||||||
|
@ -246,13 +246,13 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String findUserByOpenId(String openId) {
|
public String findUserByOpenId(String openId,HttpServletResponse response) {
|
||||||
Locale locale = LocaleContextHolder.getLocale();
|
Locale locale = LocaleContextHolder.getLocale();
|
||||||
Map map = new HashMap(3);
|
Map map = new HashMap(3);
|
||||||
SysUserEntity byOpenId = sysUserDao.findByOpenId(openId);
|
SysUserEntity byOpenId = sysUserDao.findByOpenId(openId);
|
||||||
if(byOpenId == null){
|
if(byOpenId == null){
|
||||||
map.put("type","0");
|
map.put("type","0");
|
||||||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,map,locale);
|
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,map,locale);
|
||||||
}else {
|
}else {
|
||||||
// 设置权限列表
|
// 设置权限列表
|
||||||
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
|
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
|
||||||
@ -263,7 +263,6 @@ public class SysUserServiceImpl implements SysUserService {
|
|||||||
}
|
}
|
||||||
// 生成令牌
|
// 生成令牌
|
||||||
Authentication authToken = new UsernamePasswordAuthenticationToken(byOpenId.getUserName(), byOpenId.getPassword(), permissions);
|
Authentication authToken = new UsernamePasswordAuthenticationToken(byOpenId.getUserName(), byOpenId.getPassword(), permissions);
|
||||||
HttpServletResponse response = null;
|
|
||||||
response.setHeader("Access-Control-Allow-Origin", "*");
|
response.setHeader("Access-Control-Allow-Origin", "*");
|
||||||
response.setHeader("Access-Control-Allow-Credentials", "false");
|
response.setHeader("Access-Control-Allow-Credentials", "false");
|
||||||
response.setContentType("application/json");
|
response.setContentType("application/json");
|
||||||
|
Loading…
Reference in New Issue
Block a user