package com.ycxm.controller;
import java.util.HashMap;
import java.util.Map;
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.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("login")
public class LoginController {
@GetMapping("page")
public String loginPage() {
return "login";
}
@PostMapping("login")
@ResponseBody
public Map<String, Object> login(String name,String password) {
Map<String, Object> map = new HashMap<>();
Subject subject = SecurityUtils.getSubject();
if (!subject.isAuthenticated()) {
UsernamePasswordToken token = new UsernamePasswordToken(name, password);
try {
subject.login(token);
map.put("code", "100");
} catch (UnknownAccountException e) {
map.put("code", "账号不存在,请查证后重新录入");
e.printStackTrace();
} catch (IncorrectCredentialsException e) {
map.put("code", "账号或密码不正确,请查证后重新录入");
e.printStackTrace();
}
}
return map;
}
@RequestMapping("/logout")
public String logout() {
Subject currentUser = SecurityUtils.getSubject();
currentUser.logout();
return "redirect:/login";
}
}
最近下载更多
zxc131313 LV12
2022年10月22日
45618955 LV8
2022年6月16日
我是helloworld LV23
2022年5月25日
wuying8208 LV15
2022年5月12日
893213895 LV18
2021年12月19日
噜噜啦啦露露 LV8
2021年12月14日
wanglinddad LV55
2021年12月10日
志犟CR7 LV8
2021年11月10日
苏屿999 LV9
2021年10月18日
最代码-宋家辉 LV61
2021年8月22日

最近浏览