首页>代码>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  LV54 2021年12月10日
志犟CR7  LV3 2021年11月10日
苏屿999  LV9 2021年10月18日
最代码-宋家辉  LV61 2021年8月22日
最近浏览更多
294163799 昨天
暂无贡献等级
wddq123 4月3日
暂无贡献等级
minjing123  LV8 1月4日
WBelong  LV7 2023年12月26日
shuangfu  LV24 2023年12月2日
uni-code_0123  LV1 2023年11月27日
政政123456  LV3 2023年10月22日
泓鼎168  LV19 2023年10月16日
wwewww  LV4 2023年10月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友