Exemple #1
0
 // 通过传入的登录用户名,密码,去尝试登录,如果登录成功,则返回一个唯一的sessionId,否则,返回null
 public String login() {
   user.setErrorInfo(null);
   if (StringUtils.isBlank(userService.login(user))) {
     return "success";
   } else {
     user.setErrorInfo("login error...please reconfirm your username/password...");
     return "failed";
   }
 }
 public String login(User user) {
   // 如果成功登录,则调用公共方法,生成一个唯一的key,然后插入数据库的临时表中
   User newUser = userDao.detailUser(user);
   if (null != newUser) {
     logger.info("login success...");
     // 通过用户的hashcode生成唯一key
     String onlyKey = CommonUtils.generateKeyByUser(newUser);
     System.out.println(onlyKey);
     UserTmp userTmp = new UserTmp();
     if (!StringUtils.isBlank(onlyKey)) {
       userTmp.setUid(newUser.getUid());
       userTmp.setUserSessionId(onlyKey);
       userTmp.setStartTime(CommonUtils.generateDateString(new Date()));
       userTmpDao.createUserTmp(userTmp);
       logger.info("create user session successfully ...session is " + onlyKey);
       return onlyKey;
     }
   }
   return "";
 }