package com.cdy.dormitory.controller;
import com.cdy.dormitory.dto.AccountDto;
import com.cdy.dormitory.form.AccountForm;
import com.cdy.dormitory.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpSession;
/**
* @author 缘生
* @create 2022/11/1 14:44
*/
@Controller
@RequestMapping("/account")
public class AccountController {
@Autowired
private AccountService accountService;
@PostMapping("/login")
public ModelAndView login(AccountForm accountForm, HttpSession session){
AccountDto accountDto = this.accountService.login(accountForm);
ModelAndView modelAndView = new ModelAndView();
switch (accountDto.getCode()){
case -1:
modelAndView.setViewName("login");
modelAndView.addObject("usernameError","用户名不存在");
break;
case -2:
modelAndView.setViewName("login");
modelAndView.addObject("passwordError","密码错误");
break;
case 0:
switch (accountForm.getType()){
case "systemAdmin":
modelAndView.setViewName("systemadmin");
session.setAttribute("systemAdmin", accountDto.getAdmin());
break;
case "dormitoryAdmin":
modelAndView.setViewName("dormitoryadmin");
session.setAttribute("dormitoryAdmin", accountDto.getAdmin());
break;
}
break;
}
return modelAndView;
}
// @RestController = @Controller + @ResponseBody
@GetMapping("/logout")
public String logout(HttpSession session){
session.invalidate();
return "login";
}
}
最近下载更多
xiaoaitx LV8
1月1日
zolscy LV24
2024年11月26日
adap12345 LV5
2023年6月15日
微信网友_6184005683466240 LV11
2023年6月10日
skook7 LV2
2023年6月7日
微信网友_6260196253601792 LV7
2023年6月7日
12345681 LV2
2023年5月30日
七梦辞 LV2
2023年5月25日
asa566 LV10
2023年4月26日
养猪专业户 LV12
2023年4月25日
最近浏览更多
赵林123 LV6
9月26日
暂无贡献等级
zq1685 LV4
6月14日
SX520886 LV6
4月24日
花璃lilililililili
4月17日
暂无贡献等级
微信网友_7144533052690432 LV1
3月21日
哪里的完整版 LV8
3月6日
docnnxxy688
3月1日
暂无贡献等级
pxqtsht LV16
2月21日
kkkxyh LV13
2月11日

