| | |
| | | package com.ruoyi.auth.controller; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.ruoyi.common.core.constant.CacheConstants; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | import com.ruoyi.company.api.model.RegisterUser; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | |
| | | import com.ruoyi.common.security.utils.SecurityUtils; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * token 控制 |
| | | * |
| | |
| | | |
| | | @Autowired |
| | | private SysLoginService sysLoginService; |
| | | |
| | | |
| | | @Autowired |
| | | private RedisService redisService; |
| | | |
| | | @PostMapping("login") |
| | | public R<?> login(@RequestBody LoginBody form) |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | @PostMapping("register") |
| | | public R<?> register(@RequestBody RegisterBody registerBody) |
| | | |
| | | |
| | | @PostMapping("companyRegister") |
| | | @Operation(summary = "用户注册接口",description = "用户注册接口") |
| | | public R<?> companyRegister(@RequestBody RegisterUser registerUser) |
| | | { |
| | | // 用户注册 |
| | | sysLoginService.register(registerBody.getUsername(), registerBody.getPassword()); |
| | | sysLoginService.companyRegister(registerUser); |
| | | return R.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 发送短信验证码 |
| | | */ |
| | | @PostMapping("sendSms") |
| | | public R<?> sendSms(@RequestBody RegisterUser registerUser) |
| | | { |
| | | // 验证码生成 |
| | | String code = String.valueOf(Math.random()).substring(2, 6); |
| | | // 缓存验证码 |
| | | String verifyKey = CacheConstants.CAPTCHA_CODE_KEY + registerUser.getPhone(); |
| | | redisService.setCacheObject(verifyKey, code, Constants.CAPTCHA_EXPIRATION, TimeUnit.MINUTES); |
| | | // 发送验证码 TODO |
| | | |
| | | return R.ok(code); |
| | | } |
| | | |
| | | @PostMapping("companyLogin") |
| | | public R<?> companyLogin(@RequestBody RegisterUser registerUser) |
| | | { |
| | | // 用户登录 |
| | | LoginUser userInfo = sysLoginService.login(registerUser.getPhone(), registerUser.getSmsCode()); |
| | | // 获取登录token |
| | | return R.ok(tokenService.createToken(userInfo)); |
| | | } |
| | | } |