| | |
| | | import com.xinquan.common.core.domain.R; |
| | | import com.xinquan.common.core.utils.JwtUtils; |
| | | import com.xinquan.common.core.utils.StringUtils; |
| | | import com.xinquan.common.redis.service.RedisService; |
| | | import com.xinquan.common.security.auth.AuthUtil; |
| | | import com.xinquan.common.security.service.TokenService; |
| | | import com.xinquan.common.security.utils.SecurityUtils; |
| | | import com.xinquan.system.api.domain.AppUser; |
| | | import com.xinquan.system.api.domain.SysMenu; |
| | | import com.xinquan.system.api.domain.SysRole; |
| | | import com.xinquan.system.api.domain.SysUser; |
| | | import com.xinquan.system.api.feignClient.SysUserClient; |
| | |
| | | import com.xinquan.system.api.model.AppVerifyCellPhoneBody; |
| | | import com.xinquan.system.api.model.AppWXLoginBody; |
| | | import com.xinquan.system.api.model.LoginUser; |
| | | import com.xinquan.user.api.feign.RemoteAppUserService; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | |
| | | private SysLoginService sysLoginService; |
| | | @Autowired |
| | | private SysUserClient userClient; |
| | | @Resource |
| | | private RemoteAppUserService remoteAppUserService; |
| | | |
| | | |
| | | /** |
| | | * 发送验证码 |
| | |
| | | @ApiOperation(value = "发送验证码",tags = {"APP端"}) |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "cellPhone", value = "手机号码", required = true, dataType = "String", paramType = "query"), |
| | | @ApiImplicitParam(name = "type", value = "类型 1=注册 2=验证码登录 3=找回密码 4=第三方登录后验证手机", required = true, dataType = "Integer", paramType = "query")}) |
| | | @ApiImplicitParam(name = "type", value = "类型 1=注册 2=验证码登录 3=找回密码 4=第三方登录后验证手机 5=切换手机号 6= 添加银行卡,7=管理后台修改密码", required = true, dataType = "Integer", paramType = "query")}) |
| | | public R<?> sendCaptchaCode( |
| | | @RequestParam(value = "cellPhone", required = true) String cellPhone, |
| | | @RequestParam("type") Integer type) { |
| | | |
| | | if(type==5){ |
| | | AppUser data = remoteAppUserService.getUserByPhone(cellPhone).getData(); |
| | | if (data!=null){ |
| | | return R.fail("当前手机号已被绑定"); |
| | | } |
| | | } |
| | | if(type==4){ |
| | | AppUser data = remoteAppUserService.getUserByPhone(cellPhone).getData(); |
| | | if (data!=null && (data.getWxOpenId()!=null||data.getAppleId()!=null)){ |
| | | return R.fail("当前手机号已被绑定"); |
| | | } |
| | | } |
| | | if(type==1){ |
| | | AppUser data = remoteAppUserService.getUserByPhone(cellPhone).getData(); |
| | | if (data!=null){ |
| | | return R.fail("当前手机号已注册"); |
| | | } |
| | | } |
| | | if(type==3){ |
| | | AppUser data = remoteAppUserService.getUserByPhone(cellPhone).getData(); |
| | | if (data==null){ |
| | | return R.fail("当前手机号未注册"); |
| | | } |
| | | } |
| | | sysLoginService.sendCaptchaCode(cellPhone, type); |
| | | return R.ok(); |
| | | } |
| | |
| | | */ |
| | | @ApiOperation(value = "注册账户",tags = {"APP端"}) |
| | | @PostMapping("/app/register") |
| | | public R<AppLoginUser> appRegister(@Validated @RequestBody AppRegisterBody appRegisterBody) |
| | | public R<AppLoginUser> appRegister(@RequestBody AppRegisterBody appRegisterBody) |
| | | { |
| | | // 用户注册 |
| | | AppLoginUser appLoginUser = sysLoginService.appRegister(appRegisterBody); |
| | |
| | | @PostMapping("/app/login") |
| | | public R<AppLoginUser> appLogin(@Validated @RequestBody AppLoginBody body) { |
| | | AppLoginUser appLoginUser = sysLoginService.appLogin(body); |
| | | Long appUserId = appLoginUser.getAppUserId(); |
| | | AppUser data = remoteAppUserService.getAppUserById(appUserId + "").getData(); |
| | | if (data.getUserStatus() == 2){ |
| | | return R.fail("您的账号已被冻结"); |
| | | } |
| | | return R.ok(tokenService.createToken4AppLoginUser(appLoginUser)); |
| | | } |
| | | |
| | |
| | | @PostMapping("/app/captchaLogin") |
| | | public R<AppLoginUser> appCaptchaLogin(@Validated @RequestBody AppCaptchaBody body) { |
| | | AppLoginUser appLoginUser = sysLoginService.appCaptchaLogin(body); |
| | | Long appUserId = appLoginUser.getAppUserId(); |
| | | AppUser data = remoteAppUserService.getAppUserById(appUserId + "").getData(); |
| | | if (data.getUserStatus() == 2){ |
| | | return R.fail("您的账号已被冻结"); |
| | | } |
| | | return R.ok(tokenService.createToken4AppLoginUser(appLoginUser)); |
| | | } |
| | | |
| | |
| | | @PostMapping("/app/wxLogin") |
| | | public R<AppLoginUser> thirdLogin(@Validated @RequestBody AppWXLoginBody body) { |
| | | AppLoginUser appLoginUser = sysLoginService.wxLogin(body); |
| | | Long appUserId = appLoginUser.getAppUserId(); |
| | | AppUser data = remoteAppUserService.getAppUserById(appUserId + "").getData(); |
| | | if (data.getUserStatus() == 2){ |
| | | return R.fail("您的账号已被冻结"); |
| | | } |
| | | return R.ok(tokenService.createToken4AppLoginUser(appLoginUser)); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "苹果登录", tags = {"APP端"}) |
| | | @PostMapping("/app/appleLogin") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "appleId", value = "苹果ID", required = true, dataType = "String", paramType = "query")}) |
| | | @ApiImplicitParam(name = "appleId", value = "苹果ID", required = true, dataType = "String", paramType = "query") |
| | | // @ApiImplicitParam(name = "device", value = "设备码", required = false, dataType = "String", paramType = "query"), |
| | | } |
| | | ) |
| | | public R<AppLoginUser> appleLogin( |
| | | @RequestParam(value = "appleId", required = true) String appleId) { |
| | | AppLoginUser appLoginUser = sysLoginService.appleLogin(appleId); |
| | | @RequestParam(value = "appleId", required = true) String appleId, |
| | | @RequestParam(value = "device", required = false) String device |
| | | ) { |
| | | |
| | | AppLoginUser appLoginUser = sysLoginService.appleLogin(appleId, org.springframework.util.StringUtils.hasLength(device)?device:""); |
| | | Long appUserId = appLoginUser.getAppUserId(); |
| | | AppUser data = remoteAppUserService.getAppUserById(appUserId + "").getData(); |
| | | if (data.getUserStatus() == 2){ |
| | | return R.fail("您的账号已被冻结"); |
| | | } |
| | | return R.ok(tokenService.createToken4AppLoginUser(appLoginUser)); |
| | | } |
| | | |
| | |
| | | @ApiOperation(value = "微信苹果登录-验证手机号", tags = {"APP端"}) |
| | | @PostMapping("/app/verifyCellPhone") |
| | | public R<?> verifyCellPhone(@Validated @RequestBody AppVerifyCellPhoneBody body) { |
| | | AppLoginUser appLoginUser = sysLoginService.verifyCellPhone(body); |
| | | |
| | | return R.ok(tokenService.createToken4AppLoginUser( |
| | | sysLoginService.verifyCellPhone(body))); |
| | | appLoginUser)); |
| | | } |
| | | |
| | | /** |
| | |
| | | LoginUser userInfo = sysLoginService.login(form.getUsername(), form.getPassword()); |
| | | HashMap<String, Object> map = new HashMap<>(); |
| | | map.put("token",tokenService.createToken(userInfo)); |
| | | List<SysRole> roles = userInfo.getSysUser().getRoles(); |
| | | Set<String> roles = userInfo.getRoles(); |
| | | |
| | | if(CollectionUtils.isEmpty(roles)){ |
| | | return R.fail("请关联角色!"); |
| | | } |
| | | |
| | | map.put("roleName",roles.get(0).getRoleName()); |
| | | map.put("roleName",roles.stream().findFirst().get()); |
| | | map.put("info",userInfo); |
| | | List<SysMenu> data = userClient.roleInfoFromUserId(userInfo.getUserid()).getData(); |
| | | map.put("menus",data); |
| | | // 修改用户最后登录时间 |
| | | SysUser sysUser = new SysUser(); |
| | | sysUser.setUserId(userInfo.getSysUser().getUserId()); |
| | | sysUser.setLoginDate(LocalDateTime.now()); |
| | | System.out.println("修改用户登录时间"+sysUser); |
| | | userClient.updateSysUser(sysUser); |
| | | // 获取登录token |
| | | return R.ok(map); |
| | | } |