package com.basic.x01.system.controller;
|
|
import javax.annotation.Resource;
|
|
import org.apache.ibatis.annotations.Param;
|
import org.apache.log4j.Logger;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
import com.basic.x01.base.BaseController;
|
import com.basic.x01.helper.CommonHelper;
|
import com.basic.x01.system.mapper.SystemMapper;
|
import com.basic.x01.system.model.TSysUser;
|
|
/**
|
* 用户登录
|
*
|
* @company 北京贝思科技术有限公司
|
* @author liuyajun, 8384503@qq.com
|
* @date 2016年1月12日
|
* @time 下午3:42:30
|
*/
|
|
@Controller
|
@Transactional(rollbackFor=Throwable.class)
|
public class Login extends BaseController {
|
|
Logger log = Logger.getLogger(getClass());
|
|
// @Autowired
|
// private UserService userService;
|
|
@Resource
|
private SystemMapper userMapper;
|
|
@RequestMapping(value="login")
|
public String login(){
|
return "forward:/frame-jsp/login.jsp";
|
}
|
|
@RequestMapping(value="loginedNoAccess")
|
public String loginedNoAccess(){
|
return "redirect:/frame-jsp/logined-no-access.jsp";
|
}
|
|
@RequestMapping(value="logOut")
|
public String logOut(){
|
this.getRequest().getSession().invalidate();
|
return "redirect:/";
|
}
|
|
@RequestMapping(value="myProfile")
|
public String myProfile(
|
@Param("option") String option,
|
@Param("oldpwd") String oldpwd,
|
TSysUser editUser){
|
|
if("modify".equals(option)){
|
//modify
|
TSysUser user = this.getLoingedUser();
|
|
if(editUser==null
|
|| this.isEmpty(editUser.getUserId())
|
|| this.isEmpty(editUser.getRealName())){
|
throw this.exception("输入参数错误");
|
}
|
|
if(! this.isEmpty(oldpwd)
|
&& ! this.isEmpty(editUser.getPassword())
|
&& ! user.getPassword().equals(oldpwd)){
|
throw this.exception("原密码不正确");
|
}
|
|
userMapper.updateUser(editUser);
|
|
//设置session中存储的对象值
|
user.setRealName(editUser.getRealName());
|
if(! this.isEmpty(editUser.getPassword())){
|
user.setPassword(editUser.getPassword());
|
}
|
|
return this.ajax(null);
|
}
|
|
this.getRequest().setAttribute("loginedUser", this.getLoingedUser());
|
return "system/my-profile";
|
}
|
|
@RequestMapping(value="/loginCheckUser", method=RequestMethod.POST)
|
//@Transactional(rollbackFor=Throwable.class, propagation=Propagation.NOT_SUPPORTED)
|
public String checkUser(TSysUser user) {
|
String loginName = user.getLoginName();
|
|
user = userMapper.getUserByLogin(user.getLoginName(), user.getPassword());
|
|
if(user ==null || ! CommonHelper.STATUS_VALID.equals(user.getStatus())){
|
log.info("Logined error: "+loginName);
|
throw this.exception("用户名密码错误");
|
}
|
|
if(user.getOrg()==null
|
|| ! CommonHelper.STATUS_VALID.equals(user.getOrg().getStatus())){
|
throw this.exception("当前用户组织已挂起");
|
}
|
|
if(user.getRole()==null
|
|| ! CommonHelper.STATUS_VALID.equals(user.getRole().getStatus())){
|
throw this.exception("无权限登录");
|
}
|
|
this.getRequest().getSession().setAttribute(
|
SESSION_LOGINED_USER_KEY, user);
|
|
log.info("Logined: "+user.getLoginName());
|
|
return this.ajax(null);
|
}
|
}
|