| | |
| | | package com.ruoyi.web.controller.system; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.entity.SysMenu; |
| | |
| | | import com.ruoyi.common.core.domain.model.LoginUser; |
| | | import com.ruoyi.common.core.redis.RedisCache; |
| | | import com.ruoyi.common.utils.SecurityUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.framework.web.service.SysLoginService; |
| | | import com.ruoyi.framework.web.service.SysPermissionService; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.domain.TbDept; |
| | | import com.ruoyi.system.service.ISysMenuService; |
| | | import com.ruoyi.system.service.ISysRoleService; |
| | | import com.ruoyi.system.service.TbDeptService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.TimeUnit; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.CollectionUtils; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | /** |
| | | * 登录验证 |
| | | * |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Api(tags = "登录") |
| | | @RestController |
| | | public class SysLoginController |
| | | { |
| | | public class SysLoginController { |
| | | |
| | | @Autowired |
| | | private SysLoginService loginService; |
| | | |
| | |
| | | private ISysRoleService roleService; |
| | | @Autowired |
| | | private TbDeptService tbDeptService; |
| | | |
| | | /** |
| | | * 账号密码登录 |
| | | * |
| | | * |
| | | * @param loginBody 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @ApiOperation(value = "账号密码登录",notes = "账号密码登录") |
| | | @PostMapping("/login") |
| | | public AjaxResult login(@RequestBody LoginBody loginBody) |
| | | { |
| | | // @ApiOperation(value = "账号密码登录", notes = "账号密码登录") |
| | | @PostMapping("/login") |
| | | public AjaxResult login(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | LoginUser loginUser = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), |
| | | LoginUser loginUser = loginService.login(loginBody.getUsername(), loginBody.getPassword(), |
| | | loginBody.getCode(), |
| | | loginBody.getUuid()); |
| | | ajax.put(Constants.TOKEN, tokenService.createToken(loginUser)); |
| | | List<SysRole> roles = loginUser.getUser().getRoles(); |
| | | if(CollectionUtils.isEmpty(roles)){ |
| | | if (CollectionUtils.isEmpty(roles)) { |
| | | return AjaxResult.error("请关联角色!"); |
| | | } |
| | | |
| | | List<SysMenu> menus = roleService.roleInfoFromUserId(loginUser.getUserId()); |
| | | |
| | | ajax.put("menus",menus); |
| | | ajax.put("roleName",roles.get(0).getRoleName()); |
| | | ajax.put("userInfo",loginUser); |
| | | ajax.put("menus", menus); |
| | | ajax.put("roleName", roles.get(0).getRoleName()); |
| | | ajax.put("userInfo", loginUser); |
| | | return ajax; |
| | | } |
| | | |
| | |
| | | * @param loginBody 登录信息 |
| | | * @return 结果 |
| | | */ |
| | | @ApiOperation(value = "短信登录",notes = "短信登录") |
| | | // @ApiOperation(value = "短信登录", notes = "短信登录") |
| | | @PostMapping("/loginCode") |
| | | public AjaxResult loginCode(@RequestBody LoginBody loginBody) |
| | | { |
| | | public AjaxResult loginCode(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | LoginUser loginUser = loginService.loginCode(loginBody.getUsername(), loginBody.getCode()); |
| | | ajax.put(Constants.TOKEN, tokenService.createToken(loginUser)); |
| | | List<SysRole> roles = loginUser.getUser().getRoles(); |
| | | if(CollectionUtils.isEmpty(roles)){ |
| | | if (CollectionUtils.isEmpty(roles)) { |
| | | return AjaxResult.error("请关联角色!"); |
| | | } |
| | | List<SysMenu> menus = roleService.roleInfoFromUserId(loginUser.getUserId()); |
| | | |
| | | ajax.put("menus",menus); |
| | | ajax.put("roleName",roles.get(0).getRoleName()); |
| | | ajax.put("userInfo",loginUser); |
| | | ajax.put("menus", menus); |
| | | ajax.put("roleName", roles.get(0).getRoleName()); |
| | | ajax.put("userInfo", loginUser); |
| | | return ajax; |
| | | } |
| | | |
| | | @ApiOperation(value = "初始化账号",notes = "初始化账号") |
| | | @PostMapping("/genAccount") |
| | | public AjaxResult genAccount(String account,String password) |
| | | { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | TbDept dept = tbDeptService.getOne(Wrappers.<TbDept>lambdaQuery().eq(TbDept::getAccount, account)); |
| | | if (StringUtils.isNotNull(dept)) { |
| | | String pwd = SecurityUtils.encryptPassword(password); |
| | | dept.setPassword(pwd); |
| | | ajax.put("password",pwd ); |
| | | tbDeptService.updateById(dept); |
| | | } |
| | | return ajax; |
| | | } |
| | | /** |
| | | * 账号密码登录 |
| | | * |
| | | * @param loginBody 部门管理后台登录 |
| | | * @return 结果 |
| | | */ |
| | | @ApiOperation(value = "部门管理后台登录",notes = "部门管理后台登录") |
| | | @ApiOperation(value = "部门管理后台登录", notes = "部门管理后台登录") |
| | | @PostMapping("/loginPwd") |
| | | public AjaxResult loginPwd(@RequestBody LoginBody loginBody) |
| | | { |
| | | public AjaxResult loginPwd(@RequestBody LoginBody loginBody) { |
| | | AjaxResult ajax = AjaxResult.success(); |
| | | // 生成令牌 |
| | | LoginUser loginUser = loginService.loginPwd(loginBody.getUsername(), loginBody.getPassword(),loginBody.getCode(),loginBody.getUuid()); |
| | | LoginUser loginUser = loginService.loginPwd(loginBody.getUsername(), |
| | | loginBody.getPassword(), loginBody.getCode(), loginBody.getUuid()); |
| | | ajax.put(Constants.TOKEN, tokenService.createToken(loginUser)); |
| | | //List<SysRole> roles = loginUser.getUser().getRoles(); |
| | | //if(CollectionUtils.isEmpty(roles)){ |
| | |
| | | |
| | | //ajax.put("menus",menus); |
| | | //ajax.put("roleName",roles.get(0).getRoleName()); |
| | | ajax.put("userInfo",loginUser); |
| | | ajax.put("userInfo", loginUser); |
| | | return ajax; |
| | | } |
| | | |
| | | /** |
| | | * 获取验证码 |
| | | * |
| | | * @param phone 手机号 |
| | | * @return 结果 |
| | | */ |
| | | @ApiOperation(value = "获取验证码",notes = "获取验证码") |
| | | // @ApiOperation(value = "获取验证码",notes = "获取验证码") |
| | | @GetMapping("/getCode") |
| | | public AjaxResult getCode(@RequestParam String phone) |
| | | { |
| | | redisCache.setCacheObject(phone,"123456",5, TimeUnit.MINUTES); |
| | | public AjaxResult getCode(@RequestParam String phone) { |
| | | redisCache.setCacheObject(phone, "123456", 5, TimeUnit.MINUTES); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 获取用户信息 |
| | | * |
| | | * |
| | | * @return 用户信息 |
| | | */ |
| | | @GetMapping("getInfo") |
| | | public AjaxResult getInfo() |
| | | { |
| | | public AjaxResult getInfo() { |
| | | SysUser user = SecurityUtils.getLoginUser().getUser(); |
| | | // 角色集合 |
| | | Set<String> roles = permissionService.getRolePermission(user); |
| | |
| | | |
| | | /** |
| | | * 获取路由信息 |
| | | * |
| | | * |
| | | * @return 路由信息 |
| | | */ |
| | | @GetMapping("getRouters") |
| | | public AjaxResult getRouters() |
| | | { |
| | | public AjaxResult getRouters() { |
| | | Long userId = SecurityUtils.getUserId(); |
| | | List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); |
| | | return AjaxResult.success(menuService.buildMenus(menus)); |