修改了绑定网站账号的接口,添加重复绑定的判断

This commit is contained in:
DESKTOP-G8BCEP0\HP 2021-09-15 09:40:32 +08:00
parent c7318dcc2a
commit 29a8c526f8
3 changed files with 17 additions and 5 deletions

View File

@ -17,6 +17,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -247,9 +248,9 @@ public class SysUserController {
* @return
*/
@PostMapping("/findUserByOpenId")
public String findUserByOpenId(@RequestBody Map map){
public String findUserByOpenId(@RequestBody Map map, HttpServletResponse response){
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){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"输入错误或未注册,请检查注册!",locale);
}
SysUserEntity byOpenId = sysUserDao.findByOpenId(openId);
if(byOpenId != null){
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"您已绑定网站账号,请勿重复绑定!",locale);
}
sysUserDao.updateOpenIdByPhone(phone,openId);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"绑定成功!",locale);
}

View File

@ -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)
@Modifying(clearAutomatically=true)
void updateOpenIdByPhone(String userName,String openId);
/**
* 根据openId和手机号查询信息
* @param openId
* @param userName
* @return
*/
SysUserEntity findByOpenIdAndUserName(String openId,String userName);
}

View File

@ -246,13 +246,13 @@ public class SysUserServiceImpl implements SysUserService {
* @return
*/
@Override
public String findUserByOpenId(String openId) {
public String findUserByOpenId(String openId,HttpServletResponse response) {
Locale locale = LocaleContextHolder.getLocale();
Map map = new HashMap(3);
SysUserEntity byOpenId = sysUserDao.findByOpenId(openId);
if(byOpenId == null){
map.put("type","0");
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,map,locale);
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,map,locale);
}else {
// 设置权限列表
ArrayList<GrantedAuthority> permissions = new ArrayList<>();
@ -263,7 +263,6 @@ public class SysUserServiceImpl implements SysUserService {
}
// 生成令牌
Authentication authToken = new UsernamePasswordAuthenticationToken(byOpenId.getUserName(), byOpenId.getPassword(), permissions);
HttpServletResponse response = null;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Credentials", "false");
response.setContentType("application/json");