首页>代码>ssm开发组织机构后台管理系统>/human/src/main/java/com/ycxm/controller/LoginController.java
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日
最近浏览更多
xiaoaitx  LV8 1月1日
dongandmin  LV9 2024年11月13日
bluerstar  LV1 2024年10月21日
chn-lei  LV2 2024年7月31日
TY0165  LV20 2024年6月24日
心随伴侣  LV2 2024年6月6日
yancyss 2024年5月29日
暂无贡献等级
李俊雄  LV3 2024年5月8日
294163799 2024年4月23日
暂无贡献等级
微信网友_6906962132258816  LV7 2024年4月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友