| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import cn.dev33.satoken.exception.NotLoginException; |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import com.ruoyi.common.annotation.Anonymous; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.core.domain.model.LoginBody; |
| | | import com.ruoyi.common.core.domain.model.SmsLoginBody; |
| | | import com.ruoyi.common.helper.LoginHelper; |
| | | import com.ruoyi.system.domain.vo.RouterVo; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | * @param loginBody 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @Anonymous |
| | | @ApiOperation("登录方法") |
| | | @PostMapping("/login") |
| | | public R<Map<String, Object>> login(@Validated @RequestBody LoginBody loginBody) { |
| | |
| | | return R.ok(ajax); |
| | | } |
| | | |
| | | /** |
| | | * 短信登录(示例) |
| | | * |
| | | * @param smsLoginBody 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @Anonymous |
| | | @ApiOperation("短信登录(示例)") |
| | | @PostMapping("/smsLogin") |
| | | public R<Map<String, Object>> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) { |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | // 生成令牌 |
| | | String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode()); |
| | | ajax.put(Constants.TOKEN, token); |
| | | return R.ok(ajax); |
| | | } |
| | | |
| | | /** |
| | | * 小程序登录(示例) |
| | | * |
| | | * @param xcxCode 小程序code |
| | | * @return 结果 |
| | | */ |
| | | @Anonymous |
| | | @ApiOperation("小程序登录(示例)") |
| | | @PostMapping("/xcxLogin") |
| | | public R<Map<String, Object>> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) { |
| | | Map<String, Object> ajax = new HashMap<>(); |
| | | // 生成令牌 |
| | | String token = loginService.xcxLogin(xcxCode); |
| | | ajax.put(Constants.TOKEN, token); |
| | | return R.ok(ajax); |
| | | } |
| | | |
| | | @Anonymous |
| | | @ApiOperation("登出方法") |
| | | @PostMapping("/logout") |
| | | public R<Void> logout() { |
| | | try { |
| | | StpUtil.logout(); |
| | | } catch (NotLoginException e) { |
| | | } |
| | | loginService.logout(); |
| | | return R.ok("退出成功"); |
| | | } |
| | | |