package org.csu.mypetstore.controller;
import org.csu.mypetstore.domain.Account;
import org.csu.mypetstore.service.AccountService;
import org.csu.mypetstore.service.AdminService;
import org.csu.mypetstore.service.InventoryService;
import org.csu.mypetstore.service.VerificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.support.SessionStatus;
import javax.servlet.http.HttpSession;
@Controller
@RequestMapping("/account")
@SessionAttributes({"username","account", "admin"})
public class AccountController {
@Autowired
AccountService accountService;
@Autowired
VerificationService verificationService;
@Autowired
AdminService adminService;
@Autowired
InventoryService inventoryService;
//登录或修改用户信息的验证码
@GetMapping("/getVerification")
@ResponseBody
public String getVerification(Account account, Model model){
if(accountService.getAccount(account.getUsername())==null){
String message_ver = "用户名不存在";
model.addAttribute("message_ver",message_ver);
return message_ver;
}else{
verificationService.creatVerificationCodeByUsername(account.getUsername());
String email = accountService.getAccount(account.getUsername()).getEmail();
email = email.replace(email.substring(2,email.indexOf('@')-2),"*******");
String message_ver = "已向 "+email+" 发送验证码";
model.addAttribute("message_ver",message_ver);
return message_ver;
}
}
//注册时的验证码
@PostMapping("/getVerificationSignOn")
@ResponseBody
public String getVerificationSignOn(Account account,Model model){
if(account.getUsername().equals("")||account.getUsername()==null||account.getEmail().equals("")||account.getEmail()==null){
String message_ver_sign = "缺少必要信息,请将注册信息填写完整";
model.addAttribute("message_ver_sign",message_ver_sign);
return message_ver_sign;
}else{
verificationService.creatVerificationCode(account);
String email = account.getEmail();
email = email.replace(email.substring(2,email.indexOf('@')-1),"*******");
String message_ver_sign = "已向 "+email+" 发送验证码";
model.addAttribute("message_ver_sign",message_ver_sign);
return message_ver_sign;
}
}
@GetMapping("/signon")
@ResponseBody
public String signon(Account account,String verification,String Fruit, Model model) {
if(Fruit.equals("User")){
if(verificationService.getVerificationCodeByUsername(account.getUsername())==null){//判断是否已经获得验证码
String message_login = "请先获得验证码";
model.addAttribute("message_login",message_login);
return "account/login";
}else if(!verificationService.getVerificationCodeByUsername(account.getUsername()).getCode().equals(verification)){//判断验证码是否正确
String message_login = "验证码错误";
model.addAttribute("message_login",message_login);
return "account/login";
}else{//判断用户名密码是否正确
verificationService.delVerificationCodeByUsername(account.getUsername());
if(accountService.getAccount(account.getUsername(), account.getPassword()) == null) {
String message_login = "用户名或密码错误";
model.addAttribute("message_login",message_login);
return "account/login";
}
else {
model.addAttribute("account",accountService.getAccount(account.getUsername(), account.getPassword()));
model.addAttribute("username",account.getUsername());
return "catalog/Main";
}
}
}else{
if(adminService.getAdmin(account.getUsername(),account.getPassword())!=null){
model.addAttribute("admin",adminService.getAdmin(account.getUsername(),account.getPassword()));
int[] BIRDS = {inventoryService.getSoldOutNumByByCategoryName("BIRDS"), inventoryService.getUnsoldNumByCategoryName("BIRDS"), inventoryService.getOrderedNumByCategoryName("BIRDS")};
int[] CATS = {inventoryService.getSoldOutNumByByCategoryName("CATS"), inventoryService.getUnsoldNumByCategoryName("CATS"), inventoryService.getOrderedNumByCategoryName("CATS")};
int[] DOGS = {inventoryService.getSoldOutNumByByCategoryName("DOGS"), inventoryService.getUnsoldNumByCategoryName("DOGS"), inventoryService.getOrderedNumByCategoryName("DOGS")};
int[] FISH = {inventoryService.getSoldOutNumByByCategoryName("FISH"), inventoryService.getUnsoldNumByCategoryName("FISH"), inventoryService.getOrderedNumByCategoryName("FISH")};
int[] REPTILES = {inventoryService.getSoldOutNumByByCategoryName("REPTILES"), inventoryService.getUnsoldNumByCategoryName("REPTILES"), inventoryService.getOrderedNumByCategoryName("REPTILES")};
model.addAttribute("BirdList", BIRDS);
model.addAttribute("CatList", CATS);
model.addAttribute("DogList", DOGS);
model.addAttribute("FishList", FISH);
model.addAttribute("ReptileList", REPTILES);
return "usual/index";
}else{
String message_login = "管理员用户名或密码错误";
model.addAttribute("message_login",message_login);
return "login";
}
}
}
@PostMapping("/newAccount")
public String newAccount(Account account,String verification,Model model){
if(account.getPassword()!=""||account.getPassword()!=null||account.getUsername()!=""||account.getUsername()!=null||account.getEmail()!=""||account.getEmail()!=null){
if(!verificationService.getVerificationCodeByUsername(account.getUsername()).getCode().equals(verification)){
model.addAttribute("message_new","验证码错误");
return "验证码错误";
}else{
account.setLanguagePreference("english");
account.setListOption(false);
account.setBannerOption(false);
account.setFavouriteCategoryId("CATS");
accountService.insertAccount(account);
model.addAttribute("message_new","注册用户成功");
verificationService.delVerificationCodeByUsername(account.getUsername());
return "注册用户成功";
}
}else{
model.addAttribute("message_new","注册信息不完整");
return "注册用户成功";
}
}
@PostMapping("/checkAccount")
@ResponseBody
public String checkAccount(Account account){
if(accountService.getAccount(account.getUsername())!=null){
return "用户名已存在";
}else{
return "用户名可以使用";
}
}
//获得用户信息
@GetMapping("/getAccount")
public String getAccount(Model model, HttpSession session){
// if(session.getAttribute("account")!=null){
model.addAttribute("account",session.getAttribute("account"));
return "account/EditAccountForm";
// }else{
// return "account/login";
// }
}
//获得用户信息
@GetMapping("/signout")
public String signout(HttpSession session,SessionStatus sessionStatus){
session.invalidate();
sessionStatus.setComplete();
return "catalog/Main";
}
//�
onnx
- 粉丝: 1w+
- 资源: 5626
最新资源
- 基于频域处理的图像去网纹方法及其应用
- Windows XP VM虚拟机文件
- Muc数字图像处理-频域处理+复原-去网纹实验代码
- matlab实现扩展卡尔曼滤波器(EKF)三维同步定位与建图(SLAM)及LQR轨迹控制研究-卡尔曼滤波-轨迹控制
- 基于opencv的目标检测 远程手势控制电脑音量项目 源代码 基于opencv实现的手势控制电脑音量项目 通过手部识别出21个关键点,并对21个关键点进行定位和着色,然后做出了个控制电脑音量小项目
- 数字图像处理领域中的甲骨文图符提取技术及其应用:边缘检测、多边形拟合与文字分割
- 双闭环永磁同步电机调速系统(SVPWM) 主电路采用两电平逆变器,永磁同步电机参数已设定,采用空间矢量PWM控制,扇区选择、中间变量、矢量作用时间、切点等模块均搭建完成 控制系统采用双闭环控制系统
- 基于最近电平逼近的开环MMC仿真 DC:12kV,N=12, 采用最近电平逼近调制, 采用基于排序的均压方法,冒泡排序+桥臂电流方向判断 连接负载,可以得到13电平相电压波形 子模块自行搭建,参数
- Muc数字图像处理-甲骨文图符提取代码及图料
- 飞跨电容型NPC逆变器仿真(SPWM) 仿真包含FCNPC拓扑、LCL滤波器、三相纯阻性负载构成主电路 采用SPWM,设计电容平衡模块,构成FCNPC逆变仿真系统 可以得到逆变器输出的三电平相电压
- fluent UDF 中文介绍.zip
- 二极管钳位型NPC逆变并网仿真(SPWM) Matlab 2021a 2016b均可 采用双环PI控制,SPWM,加设LCL滤波器,并网 可以得到逆变器输出为五电平线电压波形,滤波后输出电压,电流均
- 麻雀搜索算法(SSA)文章复现(改进Tent混沌初始化+改进Tent混沌扰动+高斯扰动)-CSSA 复现内容包括:改
- 直流电压源+双向DCDC变器+负载+锂离子电池+控制系统,Simulink仿真模型 有两种工作模式: 1锂离子电池经双向DCDC变器为负载供电 2电压源为负载供电同时经双向DCDC变器为锂离
- 2024年如何提升大模型任务能力报告.pptx
- DataFunSummit非数据中心GPU上的大模型并行训练.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈