package com.dreamer.controller;
import cn.hutool.core.util.RandomUtil;
import com.dreamer.dto.LoginFormDTO;
import com.dreamer.pojo.Manager;
import com.dreamer.pojo.data.Info;
import com.dreamer.service.ManagerService.ManagerService;
import com.dreamer.util.GetToken;
import com.dreamer.util.MD5;
import com.dreamer.util.RegexUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import static com.dreamer.util.RedisConstants.LOGIN_CODE_KEY;
import static com.dreamer.util.RedisConstants.LOGIN_CODE_TTL;
@RestController
@Slf4j
public class LoginController {
@Autowired
private ManagerService managerService;
@Resource
private StringRedisTemplate stringRedisTemplate;
@PostMapping("/loginWithPwd")
public Info loginWithPwd(@RequestBody Map<String, String> managerInfo) throws SQLException {
String account = managerInfo.get("account");
String password = managerInfo.get("password");
Manager loginManager = managerService.queryByAccountAndPwd(account, new MD5().getMD5Str(password));
Info info = null;
if (loginManager != null) {
String token = new GetToken(stringRedisTemplate).getToken(loginManager);
if(token==null){
info = new Info(406,"页面出错,请联系工作人员",null);
}else {
ArrayList<Object> data = new ArrayList<>();
data.add(loginManager.getName());
data.add(token);
info = Info.ok(200, "登录成功", data);
}
} else {
info = new Info(406, "账号或密码错误", null);
}
return info;
}
@GetMapping("/sendCode")
public Info sendCode(@RequestParam("phone") String phone){
if(RegexUtils.isPhoneInvalid(phone)){
return new Info(406,"手机号格式有误",null);
}
String code = RandomUtil.randomNumbers(6);
// session.setAttribute("code",code);
// code存储到redis中
stringRedisTemplate.opsForValue().set(LOGIN_CODE_KEY+phone,code,LOGIN_CODE_TTL, TimeUnit.MINUTES);
log.info("发送验证码成功,验证码:{}",code);
return new Info(200,"获取成功",code);
}
@PostMapping("/loginWithPhone")
public Info loginWithPhone(@RequestBody LoginFormDTO loginForm) {
//验证手机号
String phone = loginForm.getPhone();
log.info("登录信息为{}", loginForm);
if (RegexUtils.isPhoneInvalid(phone)) {
return new Info(406, "手机号格式有误", null);
}
//验证验证码
// Object realCode = session.getAttribute("code");
//从redis中获取code
String code = loginForm.getCode();
String realCode = stringRedisTemplate.opsForValue().get(LOGIN_CODE_KEY + phone);
// log.debug("验证码为{}",code);
// log.debug("缓存验证码为{}",realCode);
if (null == realCode || !code.equals(realCode)) {
return new Info(406, "验证码错误", null);
}
//判断用户是否存在
Manager manager = managerService.query().eq("phone", phone).one();
if (manager == null) {
return new Info(404, "用户不存在", null);
}
String token = new GetToken(stringRedisTemplate).getToken(manager);
System.out.println("token为"+token);
if(token==null){
return new Info(406,"页面出错,请联系工作人员",null);
}
ArrayList<Object> data = new ArrayList<>();
data.add(manager.getName());
data.add(token);
// session.setAttribute("user", userDTO);
return new Info(200, "登录成功", data);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
java基于springcloud+vue实现的学生信息管理系统源码.zip
共558个文件
xml:278个
class:113个
java:113个
需积分: 13 5 下载量 76 浏览量
2022-10-30
12:08:15
上传
评论
收藏 29.62MB ZIP 举报
温馨提示
后端技术架构 基础框架:spring-cloud-dependencies2021.0.1,springboot2.6.3 持久层框架:Mybatis-plus_3.3.2 安全框架:Apache Shiro 1.4.0,Jwt_3.7.0 数据库连接池:阿里巴巴Druid 1.2.7
资源推荐
资源详情
资源评论
收起资源包目录
java基于springcloud+vue实现的学生信息管理系统源码.zip (558个子文件)
.browserslistrc 30B
LoginFilter.class 6KB
LoginController.class 6KB
LoginController.class 6KB
Lesson.class 4KB
Lesson.class 4KB
StudentController.class 4KB
StudentController.class 4KB
TokenInterceptor.class 4KB
GetToken.class 4KB
GetToken.class 4KB
Student.class 3KB
Student.class 3KB
Manager.class 3KB
Manager.class 3KB
Info.class 3KB
Info.class 3KB
Info.class 3KB
Info.class 3KB
ManagerController.class 3KB
StudentServiceApplication.class 2KB
ManagerController.class 2KB
ManagerImpl.class 2KB
ManagerImpl.class 2KB
Profession.class 2KB
Profession.class 2KB
Profession.class 2KB
Teacher.class 2KB
Teacher.class 2KB
FormDataController.class 2KB
LoginFormDTO.class 2KB
Department.class 2KB
Department.class 2KB
Department.class 2KB
LoginFormDTO.class 2KB
LoginFormDTO.class 2KB
StudentImpl.class 2KB
StudentImpl.class 2KB
RibbonConfig.class 2KB
DataSourceConfig.class 2KB
DataSourceConfig.class 2KB
UserDTO.class 2KB
UserDTO.class 2KB
UserDTO.class 2KB
MyConfig.class 2KB
DividePageImpl.class 2KB
DividePageImpl.class 2KB
FormDataController.class 2KB
MyLocaleResolver.class 2KB
MyLocaleResolver.class 2KB
ProfessionController.class 1KB
DepartmentController.class 1KB
MD5.class 1KB
MD5.class 1KB
MD5.class 1KB
RegexUtils.class 1KB
ManagerMapper.class 1KB
ManagerMapper.class 1KB
RegexUtils.class 1KB
RegexUtils.class 1KB
ManagerService.class 1KB
ManagerService.class 1KB
UserHolder.class 1011B
DepartmentServiceClientCallBack.class 998B
UserHolder.class 955B
UserHolder.class 955B
EurekaProviderAnotherApplication.class 928B
portController.class 921B
portController.class 921B
MybatisPlusConfig.class 883B
MybatisPlusConfig.class 883B
StudentMapper.class 865B
StudentMapper.class 865B
ProfessionServiceApplication.class 848B
ProfessionImpl.class 845B
DepartmentImpl.class 845B
DepartmentImpl.class 845B
ProfessionImpl.class 845B
EurekaServerAnotherApplication.class 843B
DepartmentApplication.class 827B
EurekaServerApplication.class 822B
DividePageMapper.class 802B
DividePageMapper.class 802B
ProfessionServiceClientCallBack.class 788B
GatewayServerApplication.class 766B
StudentService.class 752B
StudentService.class 752B
RedisConstants.class 687B
RedisConstants.class 680B
RedisConstants.class 680B
FeignConfig.class 678B
RegexPatterns.class 638B
RegexPatterns.class 622B
RegexPatterns.class 622B
DepartmentService.class 575B
EurekaProviderAnotherApplicationTests.class 572B
EurekaServerAnotherApplicationTests.class 566B
ProfessionServiceApplicationTests.class 560B
EurekaProviderApplicationTests.class 551B
EurekaServerApplicationTests.class 545B
共 558 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6732
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功