package per.kirito.pack.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import per.kirito.pack.myEnum.Status;
import per.kirito.pack.pojo.User;
import per.kirito.pack.service.inter.UserService;
import per.kirito.pack.util.TypeConversion;
import java.util.HashMap;
import java.util.Map;
/**
* @author kirito
* @version 1.0
* @date 2020/12/4 21:04
* @description:
*/
@RestController
@RequestMapping(value = "/user")
public class UserController {
@Autowired
private UserService userService;
@Autowired
private StringRedisTemplate stringRedisTemplate;
private static final int LOGIN_CODE = Status.LOGIN_SUCCESS.getCode();
private static final int EXIT_CODE = Status.EXIT_SUCCESS.getCode();
private static final int INFO_CODE = Status.INFO_SUCCESS.getCode();
private static final int REGISTER_CODE = Status.REGISTER_SUCCESS.getCode();
private static final int EXIST_CODE = Status.IS_EXIST.getCode();
private static final int PWD_CODE = Status.PWD_SUCCESS.getCode();
private static final String LOGIN_SUCCESS = Status.LOGIN_SUCCESS.getMsg();
private static final String LOGIN_FAIL = Status.LOGIN_FAIL.getMsg();
private static final String EXIT_SUCCESS = Status.EXIT_SUCCESS.getMsg();
private static final String EXIT_FAIL = Status.EXIT_FAIL.getMsg();
private static final String INFO_SUCCESS = Status.INFO_SUCCESS.getMsg();
private static final String INFO_FAIL = Status.INFO_FAIL.getMsg();
private static final String REGISTER_SUCCESS = Status.REGISTER_SUCCESS.getMsg();
private static final String REGISTER_FAIL = Status.REGISTER_FAIL.getMsg();
private static final String IS_EXIST = Status.IS_EXIST.getMsg();
private static final String NOT_EXIST = Status.NOT_EXIST.getMsg();
private static final String PWD_SUCCESS = Status.PWD_SUCCESS.getMsg();
private static final String PWD_FAIL = Status.PWD_FAIL.getMsg();
@CrossOrigin
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(@RequestParam(value = "card") String card,
@RequestParam(value = "password") String password) {
String encrypt = TypeConversion.base64Encode(password.getBytes());
User user = new User();
user.setCard(card);
user.setPassword(encrypt);
int flag = userService.findUserByCardAndPwd(user);
if (flag == LOGIN_CODE) {
stringRedisTemplate.opsForValue().set("card", card);
return LOGIN_SUCCESS;
} else {
return LOGIN_FAIL;
}
}
@CrossOrigin
@RequestMapping(value = "/exit", method = RequestMethod.POST)
public String userExit() {
stringRedisTemplate.delete("card");
return stringRedisTemplate.hasKey("card") ? EXIT_FAIL : EXIT_SUCCESS;
}
@CrossOrigin
@RequestMapping(value = "/getInfo", method = RequestMethod.POST)
public Map<String, Object> getUserInfo() {
String card = stringRedisTemplate.opsForValue().get("card");
Map<String, Object> map = new HashMap<>();
if (card == null || card == "") {
map.put("result", INFO_FAIL);
} else {
User user = userService.getUser(card);
map.put("user", user);
}
return map;
}
@CrossOrigin
@RequestMapping(value = "/addUser")
public String addUser(@RequestBody User user) {
String pwd = user.getPassword();
String encrypt = TypeConversion.base64Encode(pwd.getBytes());
user.setPassword(encrypt);
int flag = userService.addUser(user);
if (flag == REGISTER_CODE) {
String card = user.getCard();
stringRedisTemplate.opsForValue().set("card", card);
return REGISTER_SUCCESS;
} else {
return REGISTER_FAIL;
}
}
@CrossOrigin
@RequestMapping(value = "/forgetPwd")
public Map<String, String> forgetPwd(@RequestParam(value = "card") String card,
@RequestParam(value = "phone") String phone,
@RequestParam(value = "password") String password) {
System.out.println("card: " + card);
System.out.println("phone: " + phone);
System.out.println("password: " + password);
User user = new User();
user.setCard(card);
user.setPhone(phone);
int ifExit = userService.findUserByCardAndPhone(user);
Map<String, String> map = new HashMap<>();
if (ifExit == EXIST_CODE) {
String encrypt = TypeConversion.base64Encode(password.getBytes());
user = userService.getUser(card);
user.setPassword(encrypt);
int flag = userService.updateUser(user);
if (flag == PWD_CODE) {
map.put("flag", PWD_SUCCESS);
stringRedisTemplate.opsForValue().set("card", card);
} else {
map.put("flag", PWD_FAIL);
}
} else {
map.put("flag", NOT_EXIST);
}
return map;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
基于SpringBoot的校园快递管理系统.zip (36个子文件)
pack-java-master
src
test
java
per
kirito
pack
PackApplicationTests.java 329B
main
resources
conf
mybatis-config.xml 1KB
application.yml 1KB
mapper
AdminMapper.xml 877B
CodeMapper.xml 583B
UserMapper.xml 1KB
PackMapper.xml 1KB
java
per
kirito
pack
ServletInitializer.java 403B
pojo
Admin.java 604B
User.java 654B
Pack.java 1KB
Code.java 555B
Message.java 940B
Send.java 732B
myEnum
Status.java 2KB
Express.java 746B
mapper
UserMapper.java 409B
AdminMapper.java 353B
CodeMapper.java 314B
PackMapper.java 344B
controller
UserController.java 5KB
AdminController.java 3KB
PackController.java 4KB
PackApplication.java 524B
service
inter
AdminService.java 299B
UserService.java 355B
PackService.java 290B
CodeService.java 260B
impl
UserServiceImpl.java 949B
CodeServiceImpl.java 656B
PackServiceImpl.java 744B
AdminServiceImpl.java 777B
util
PackUtil.java 4KB
UUIDUtil.java 3KB
TypeConversion.java 2KB
PickCodeUtil.java 2KB
共 36 条
- 1
我慢慢地也过来了
- 粉丝: 1w+
- 资源: 4083
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于51单片机开发板设计的六位密码锁
- course_s5_linux应用程序开发篇.pdf
- course_s4_ALINX_ZYNQ_MPSoC开发平台Linux驱动教程V1.04.pdf
- course_s0_Xilinx开发环境安装教程.pdf
- 多边形框架物体检测20-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- course_s1_ALINX_ZYNQ_MPSoC开发平台FPGA教程V1.01.pdf
- course_s3_ALINX_ZYNQ_MPSoC开发平台Linux基础教程V1.05.pdf
- rwer456456567567
- AXU2CGB-E开发板用户手册.pdf
- 数据库设计与关系理论-C.J.+Date.epub
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
前往页