| | |
| | | import com.ruoyi.common.security.auth.AuthUtil; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.company.api.RemoteCompanyService; |
| | | import com.ruoyi.company.api.RemoteCompanyUserService; |
| | | import com.ruoyi.company.api.domain.Company; |
| | | import com.ruoyi.company.api.domain.User; |
| | | import com.ruoyi.company.api.domain.dto.MgtCompanyDTO; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import com.ruoyi.system.api.model.AppUser; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.validation.Valid; |
| | | import java.time.LocalDateTime; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | /** |
| | |
| | | |
| | | @Resource |
| | | private RemoteCompanyUserService remoteCompanyUserService; |
| | | @Resource |
| | | private RemoteCompanyService remoteCompanyService; |
| | | |
| | | @Operation(summary = "管理端-登录") |
| | | @PostMapping("login") |
| | | public R<?> login(@RequestBody LoginBody form) |
| | |
| | | |
| | | @PostMapping("companyRegister") |
| | | @Operation(summary = "用户注册接口",description = "用户注册接口") |
| | | public R<?> companyRegister(@RequestBody RegisterUser registerUser) |
| | | public R<?> companyRegister(@RequestBody MgtCompanyDTO registerUser) |
| | | { |
| | | // 用户注册 |
| | | sysLoginService.companyRegister(registerUser); |
| | |
| | | { |
| | | // 验证码生成 |
| | | String code = String.valueOf(Math.random()).substring(2, 6); |
| | | // 发送验证码 |
| | | String result = SmsUtils.sendSms(registerUser.getPhone(), code); |
| | | code += ":"+System.currentTimeMillis(); |
| | | |
| | | // 缓存验证码 |
| | | String verifyKey = CacheConstants.PHONE_CODE_KEY + registerUser.getPhone(); |
| | | redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); |
| | | // 发送验证码 |
| | | String result = SmsUtils.sendSms(registerUser.getPhone(), code); |
| | | |
| | | if (!"OK".equals(result)) |
| | | { |
| | | return R.fail("验证码发送失败"); |
| | |
| | | @PostMapping("smsLogin") |
| | | @Operation(summary = "验证码登录",description = "验证码登录") |
| | | public R<Map<String, Object>> smsLogin(@RequestBody RegisterUser registerUser){ |
| | | String smsCode = registerUser.getSmsCode(); |
| | | String smsCode = registerUser.getCode(); |
| | | if (!"999999".equals(smsCode)) { |
| | | String verifyKey = CacheConstants.PHONE_CODE_KEY + StringUtils.nvl(registerUser.getPhone(), ""); |
| | | String captcha = redisService.getCacheObject(verifyKey); |
| | | if (captcha == null) { |
| | | if (captcha == null){ |
| | | throw new CaptchaException("验证码错误"); |
| | | } |
| | | String[] split = captcha.split(":"); |
| | | long l = Long.parseLong(split[1]); |
| | | long l1 = System.currentTimeMillis(); |
| | | // 判断是否大于两分钟 |
| | | if (l1 - l > 2 * 60 * 1000) { |
| | | throw new CaptchaException("验证码已失效"); |
| | | } |
| | | redisService.deleteObject(verifyKey); |
| | | if (!smsCode.equalsIgnoreCase(captcha)) { |
| | | throw new CaptchaException("验证码错误"); |
| | | } |
| | |
| | | return "login_tokens:" + token; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 公司校验 |
| | | */ |
| | | @PostMapping("check") |
| | | @Operation(summary = "公司校验",description = "公司校验") |
| | | public R<?> check(@RequestBody RegisterUser registerUser) |
| | | { |
| | | User check = sysLoginService.check(registerUser); |
| | | if (check == null) { |
| | | return R.fail("账号不存在!"); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 重置密码 |
| | | */ |