* 登录
* @return
*/
public String login(){
//校验用户名和密码
JSONObject result=CommonDAO.getSingle(SqlMgr.getSql("LOGIN_CHECK"), userName,password);
if(result==null){
this.setReqAttr("errorMsg", "登录失败,用户名或密码不正确。");
return "error";
}else if(result.getString("state").equals("-1")){//已注册,但尚未激活
this.setReqAttr("regMsg", "EMAIL_NOT_CHECK");
email=result.getString("email");
String mailAddr="mail."+email.substring(email.lastIndexOf("@")+1);
this.setReqAttr("mailAddr",mailAddr);
return "checkEmail";
}else if(result!=null){
//更新用户状态为已登录,并更新IP地址、记录最后登录时间
String ipAddr=this.getIpAddr();
CommonDAO.update(SqlMgr.getSql("USER_LOGIN"),ipAddr,userName);
//加载用户的权限代码
JSONArray permissions=CommonDAO.getList(SqlMgr.getSql("GET_USER_PERMISSION"),userName);
if(permissions!=null){
Iterator<JSONObject> iter=permissions.iterator();
while(iter.hasNext()){
JSONObject jsonObj=iter.next();
this.setSessionAttr(jsonObj.getString("permission_code"), jsonObj.getString("permission_desc"));
}
}
//取用户资料
JSONObject userInfo=CommonDAO.getSingle(SqlMgr.getSql("GET_USER_INFO"), userName);
if(userInfo!=null){
this.setSessionAttr("nickName",userInfo.get("nick_name"));
this.setSessionAttr("gradeName",userInfo.get("grade_name"));
this.setSessionAttr("gender",userInfo.get("gender").equals("0")?"男":"女");
this.setSessionAttr("cityId",userInfo.get("city_id"));
this.setSessionAttr("articles",userInfo.get("articles"));
this.setSessionAttr("posts",userInfo.get("posts"));
this.setSessionAttr("allTimes",userInfo.get("all_times"));
this.setSessionAttr("money",userInfo.get("money"));
this.setSessionAttr("state",userInfo.get("state"));
this.setSessionAttr("examGrade",userInfo.get(""));
this.setSessionAttr("qq",userInfo.get("qq"));
}
//加载个人主页相关信息
//设置会话参数
this.setSessionAttr("userName", userName);