修改后台登录
This commit is contained in:
parent
40224177e5
commit
2d6808e63c
@ -17,4 +17,11 @@
|
|||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- redis -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
@ -1,13 +1,11 @@
|
|||||||
package com.yovinchen.xlcs.acl.controller;
|
package com.yovinchen.xlcs.acl.controller;
|
||||||
|
|
||||||
|
import com.yovinchen.xlcs.acl.service.AdminService;
|
||||||
import com.yovinchen.xlcs.common.result.Result;
|
import com.yovinchen.xlcs.common.result.Result;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,13 +21,18 @@ import java.util.Map;
|
|||||||
@RequestMapping("/admin/acl/index")
|
@RequestMapping("/admin/acl/index")
|
||||||
public class IndexController {
|
public class IndexController {
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AdminService adminService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 1、请求登陆的login
|
* 1、请求登陆的login
|
||||||
*/
|
*/
|
||||||
@PostMapping("login")
|
@PostMapping("login")
|
||||||
public Result login() {
|
public Result login(@RequestBody Map<String, String> loginRequest) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
String username = loginRequest.get("username");
|
||||||
map.put("token", "admin-token");
|
String password = loginRequest.get("password");
|
||||||
|
Map<String, Object> map = adminService.loginAdmin(username, password);
|
||||||
return Result.ok(map);
|
return Result.ok(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,10 +40,8 @@ public class IndexController {
|
|||||||
* 2 获取用户信息
|
* 2 获取用户信息
|
||||||
*/
|
*/
|
||||||
@GetMapping("info")
|
@GetMapping("info")
|
||||||
public Result info() {
|
public Result info(String token) {
|
||||||
Map<String, Object> map = new HashMap<>();
|
Map<String, Object> map = adminService.getInfo(token);
|
||||||
map.put("name", "yovinchen");
|
|
||||||
map.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
|
|
||||||
return Result.ok(map);
|
return Result.ok(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,6 +6,8 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
import com.yovinchen.xlcs.model.acl.Admin;
|
import com.yovinchen.xlcs.model.acl.Admin;
|
||||||
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassName: AdminService
|
* ClassName: AdminService
|
||||||
* Package: com.yovinchen.xlcs.acl.service
|
* Package: com.yovinchen.xlcs.acl.service
|
||||||
@ -25,4 +27,19 @@ public interface AdminService extends IService<Admin> {
|
|||||||
*/
|
*/
|
||||||
IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo);
|
IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台登录
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String, Object> loginAdmin(String username, String password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户信息
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Map<String, Object> getInfo(String token);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.yovinchen.xlcs.acl.service.impl;
|
package com.yovinchen.xlcs.acl.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.UUID;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
@ -11,9 +12,14 @@ import com.yovinchen.xlcs.model.acl.Admin;
|
|||||||
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
import com.yovinchen.xlcs.vo.acl.AdminQueryVo;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ClassName: AdminServiceImpl
|
* ClassName: AdminServiceImpl
|
||||||
* Package: com.yovinchen.xlcs.acl.service.impl
|
* Package: com.yovinchen.xlcs.acl.service.impl
|
||||||
@ -32,6 +38,16 @@ public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RoleService roleService;
|
private RoleService roleService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询用户
|
||||||
|
*
|
||||||
|
* @param pageParam
|
||||||
|
* @param userQueryVo
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo) {
|
public IPage<Admin> selectPage(Page<Admin> pageParam, AdminQueryVo userQueryVo) {
|
||||||
log.info("获取管理用户分页列表入参{}", pageParam.toString() + userQueryVo.toString());
|
log.info("获取管理用户分页列表入参{}", pageParam.toString() + userQueryVo.toString());
|
||||||
@ -47,4 +63,42 @@ public class AdminServiceImpl extends ServiceImpl<AdminMapper, Admin> implements
|
|||||||
IPage<Admin> pageModel = baseMapper.selectPage(pageParam, wrapper);
|
IPage<Admin> pageModel = baseMapper.selectPage(pageParam, wrapper);
|
||||||
return pageModel;
|
return pageModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后台登录
|
||||||
|
*
|
||||||
|
* @param username
|
||||||
|
* @param password
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> loginAdmin(String username, String password) {
|
||||||
|
|
||||||
|
Integer i = baseMapper.selectCount(new LambdaQueryWrapper<Admin>().eq(Admin::getUsername, username)
|
||||||
|
.eq(Admin::getPassword, password));
|
||||||
|
if (i != 0) {
|
||||||
|
// 验证通过,生成随机token
|
||||||
|
String token = UUID.randomUUID()
|
||||||
|
.toString();
|
||||||
|
redisTemplate.opsForValue()
|
||||||
|
.set(token, username);
|
||||||
|
redisTemplate.expire(token, 5, TimeUnit.MINUTES); // 设置过期时间为五分钟
|
||||||
|
// 返回包含token的结果
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("token", token);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getInfo(String token) {
|
||||||
|
String username = (String) redisTemplate.opsForValue()
|
||||||
|
.get(token);
|
||||||
|
Admin admin = baseMapper.selectOne(new LambdaQueryWrapper<Admin>().eq(Admin::getUsername, username));
|
||||||
|
Map<String, Object> map = new HashMap<>();
|
||||||
|
map.put("name", admin.getName());
|
||||||
|
map.put("avatar", "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
|
||||||
|
return map;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user