package com.example.shiqicha.controller;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import com.example.shiqicha.bean.*;
import com.example.shiqicha.bean.enterprise.EnterpriseInformation;
import com.example.shiqicha.bean.param.EnterpriseInformationParam;
import com.example.shiqicha.service.EnterpriseInformationService;
import com.example.shiqicha.service.UserService;
import com.example.shiqicha.tool.ConFig;
import com.example.shiqicha.tool.MD5;
import com.example.shiqicha.tool.PaginationTool;
import com.sun.istack.internal.NotNull;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.validation.constraints.Size;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** 系统用户控制层 用户管理 功能接口 登录 注册
* 创建人
* 创建时间 */
@Controller
public class UserController {
//日志
private static final Logger LOG = LoggerFactory.getLogger(UserController.class);
@Autowired
EnterpriseInformationService enterpriseInformationService;
//用户实现层
@Autowired
UserService userService;
/**
* shiro 未登录输入其他地址进行拦截跳转接口
*/
@RequestMapping("/index")
public String index(Model model) {
model.addAttribute("user_name_error","用户名");
model.addAttribute("wrong_password","密码");
return "index.html";
}
@RequestMapping("/shouye")
public ModelAndView shouye(EnterpriseInformationParam enterpriseInformationParam, Water water){
//查询当前登录用户信息
User user = userService.selectCurrentUser(ConFig.GetId());
//web端-景点信息档案查询
List<EnterpriseInformation> enterpriseInformations = enterpriseInformationService.selectEnterpriseInformation(enterpriseInformationParam);
//售票数量
List<Water> waters = enterpriseInformationService.selectWaterQuality(water);
//售票数量
int shoupiao =waters.size();
//景点数量
int jidian=enterpriseInformations.size();
ModelAndView modelAndView=new ModelAndView("shouye");
modelAndView.addObject("user",user);
modelAndView.addObject("shoupiao",shoupiao);
modelAndView.addObject("jidian",jidian);
return modelAndView;
}
/**
* 登录接口
* 参数 user_name 用户名
* password 密码
*/
@RequestMapping(value = "/SignIn")
public String SignIn(@NotNull String user_name, @NotNull String password, Model model, HttpServletResponse response, HttpServletRequest request) {
if (user_name==null&&password==null){
model.addAttribute("user_name_error","用户名");
model.addAttribute("wrong_password","密码");
return "index.html";
}
//使用shiro编写认证操作
//获取subject
Subject subject= SecurityUtils.getSubject();
//MD5加密
String passwordmdMD5 = MD5.string2MD5(password);
//封装用户数据
UsernamePasswordToken token=new UsernamePasswordToken(user_name,passwordmdMD5,"");
//执行登录方法
try {
subject.login(token);
//登录成功
List<User> selectidentifier = userService.selectidentifier(ConFig.GetId());
if (selectidentifier.get(0) == null) {
Cookie newCookie = new Cookie("JSESSIONID", "");
newCookie.setMaxAge(0);
response.addCookie(newCookie);
return "index.html";
}
//查询当前登录用户信息
User user = userService.selectCurrentUser(ConFig.GetId());
//创建session对象
HttpSession session = request.getSession();
//将用户信息存储到session中
session.setAttribute("user", user);
//设置sessiong存储时间
session.setMaxInactiveInterval(24 * 60 * 60);
//创建cookie
Cookie cookie=new Cookie("JSESSIONID",session.getId());
//设置cookie时间 一天
cookie.setMaxAge(24*60*60);
response.addCookie(cookie);
model.addAttribute("user", user);
model.addAttribute("mechanism_id",user.getUser_mechanism_id());
return "homepage.html";
} catch (UnknownAccountException e) {
//登录失败 用户名不存在
model.addAttribute("user_name_error", "用户名错误");
model.addAttribute("wrong_password", "密码");
return "index.html";
} catch (IncorrectCredentialsException e) {
//登录失败 密码错误
model.addAttribute("user_name_error", "用户名");
model.addAttribute("wrong_password", "密码错误");
return "index.html";
}
}
//退出登录
@RequestMapping("/remove")
public String remove(HttpSession session, Model model){
session.setAttribute("user",null);
model.addAttribute("user_name_error","用户名");
model.addAttribute("wrong_password","密码");
return "index.html";
}
/**用户注册机构查询接口 用户注册页面前进入此接口
* 参数 无
* 返回 用户注册页面*/
@RequestMapping("/selectMechanism")
public ModelAndView selectMechanism(User user){
try {
//机构信息查询接口
List<Mechanism> mechanisms = userService.selectMechanism(ConFig.GetId());
//查询全部权限名称 及其id
List<User> selectidentifiers = userService.selectidentifiers();
ModelAndView modelAndView=new ModelAndView("insertuser");
modelAndView.addObject("selectidentifiers",selectidentifiers);
modelAndView.addObject("mechanisms",mechanisms);
modelAndView.addObject("user",user);
return modelAndView;
}catch (Exception e){
ModelAndView modelAndView=new ModelAndView("insertuser");
return modelAndView;
}
}
/**用户注册接口
* 参数 jurisdiction_id 权限数组
* user 用户封装类 */
@RequestMapping("/insertuser")
public ModelAndView insertuser(int[] jurisdiction_id, User user, RedirectAttributes redirectAttributes){
try {
/**先注册用户 获取新注册用户id 在拿用户id和获取来的权限id向用户权限表添加*/
//查询用户名是否已被注册 返回true代表没有注册 返回false代表
没有合适的资源?快使用搜索试试~ 我知道了~
基于java的疫情物资送饭系统
共836个文件
png:160个
js:158个
gif:156个
需积分: 0 1 下载量 20 浏览量
2024-08-05
14:57:13
上传
评论
收藏 74.86MB ZIP 举报
温馨提示
基于java的疫情物资送饭系统 数据库采用mysql5.5版本 jdk1.8 maven3.6.1
资源推荐
资源详情
资源评论
收起资源包目录
基于java的疫情物资送饭系统 (836个子文件)
UserController.class 16KB
EnterpriseInformationController.class 9KB
Water.class 6KB
VEnterpriseInformation.class 6KB
VxInsertEnterprise.class 5KB
UserServiceImpl.class 5KB
EnterpriseInformationServiceImpl.class 5KB
User.class 4KB
EnterpriseInformationParam.class 4KB
SelectVxUserVo.class 4KB
VxInsertEnterpriseReviewParam.class 4KB
EnterpriseInformation.class 4KB
ShiroConfig.class 4KB
Access.class 4KB
ConFig.class 3KB
UserRealm.class 3KB
VxUserSignInParam.class 3KB
MD5.class 2KB
Mechanism.class 2KB
UserMapper.class 2KB
EnterpriseInformationMapper.class 2KB
UserExcel.class 2KB
EnterpriseInformationService.class 2KB
ManageSpringBeans.class 2KB
UserService.class 2KB
SelectVxUserParam.class 2KB
VenterpriseInformationParam.class 2KB
Page.class 2KB
WebMvcConfig.class 1KB
PaginationTool.class 999B
ShiqichaApplication.class 914B
ShiqichaApplicationTests.class 551B
layui.css 106KB
layui.css 106KB
layui.css 58KB
layui.css 58KB
loaders.css 56KB
loaders.css 56KB
jquery.mCustomScrollbar.css 52KB
jquery.mCustomScrollbar.css 52KB
layui.css 27KB
layui.css 27KB
fancy-textbox.css 19KB
fancy-textbox.css 19KB
backHome.css 15KB
backHome.css 15KB
font-awesome.css 15KB
font-awesome.css 15KB
layer.css 14KB
layer.css 14KB
layui.mobile.css 10KB
layui.mobile.css 10KB
layui.mobile.css 10KB
layui.mobile.css 10KB
frameStyle.css 9KB
frameStyle.css 9KB
login.css 8KB
login.css 8KB
laydate.css 7KB
laydate.css 7KB
sleep.css 7KB
sleep.css 7KB
iconfontStyle.css 6KB
iconfontStyle.css 6KB
zTreeStyle.css 6KB
zTreeStyle.css 6KB
styles.css 6KB
styles.css 6KB
base.css 5KB
base.css 5KB
home_middle_page.css 5KB
home_middle_page.css 5KB
iconfont.css 4KB
iconfont.css 4KB
reportForm.css 2KB
reportForm.css 2KB
public.css 2KB
public.css 2KB
normalize.css 2KB
normalize.css 2KB
formRL.css 2KB
formRL.css 2KB
demo.css 2KB
demo.css 2KB
login1.css 1KB
login1.css 1KB
default.css 1KB
default.css 1KB
dropSort.css 1KB
dropSort.css 1KB
timePage.css 1KB
timePage.css 1KB
paging.css 1KB
paging.css 1KB
code.css 1KB
code.css 1KB
font.css 505B
font.css 505B
errorPage.css 460B
errorPage.css 460B
共 836 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
网顺技术团队
- 粉丝: 1w+
- 资源: 62
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功