package cn.updev.Users.Static;

import cn.updev.Users.Static.IUser;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by hypo on 15-9-29.
 */
public class Login {
    private IUser user;
    private String passWord;

    public Login(String loginName, String passWord) {

        //loginName 可能是邮箱或者用户名， 分别尝试获得user对象
        user = null;

        this.passWord = passWord;

        try {
            //密码MD5加密 把注册邮箱作为盐
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update((passWord + user.geteMail()).getBytes());
            passWord = new String(md.digest());
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
    }

    public Boolean judge(){

        if(user == null){
            return false;
        }

        if(passWord.equals(user.getPassWord())){
            return true;
        }

        return false;
    }
}

@@ -36,37 +36,134 @@
 ort 
-cn.updev.Users.Static.IUser;%0A
+org.apache.struts2.ServletActionContext;%0A%0Aimport javax.servlet.http.HttpServletRequest;%0Aimport javax.servlet.http.HttpSession;
 %0Aimp
@@ -247,16 +247,34 @@
 n;%0A%0A/**%0A
+ * %E7%99%BB%E5%BD%95%E5%88%A4%E6%96%AD%0A * %E8%8E%B7%E5%BE%97%E7%99%BB%E5%BD%95%E7%94%A8%E6%88%B7%0A
  * Creat
@@ -396,90 +396,93 @@
 gin(
-String loginName, String passWord) %7B%0A%0A        //loginName %E5%8F%AF%E8%83%BD%E6%98%AF%E9%82%AE%E7%AE%B1%E6%88%96%E8%80%85%E7%94%A8%E6%88%B7%E5%90%8D%EF%BC%8C %E5%88%86%E5%88%AB%E5%B0%9D%E8%AF%95%E8%8E%B7%E5%BE%97user%E5%AF%B9%E8%B1%A1
+)%7B%0A%0A    %7D%0A%0A    public Login(String email, String passWord) %7B%0A%0A        // email%E6%98%AF%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E9%82%AE%E7%AE%B1
 %0A   
@@ -995,16 +995,42 @@
 rd()))%7B%0A
+            setSession();%0A
         
@@ -1084,11 +1084,467 @@
 e;%0A    %7D
+%0A%0A    private void setSession()%7B%0A%0A        HttpServletRequest request = ServletActionContext.getRequest();%0A        HttpSession session = request.getSession();%0A%0A        session.setAttribute(%22user%22, user);%0A%0A    %7D%0A%0A    public IUser getLoginedUser()%7B%0A%0A        HttpServletRequest request = ServletActionContext.getRequest();%0A        HttpSession session = request.getSession();%0A%0A        IUser rnt = (IUser) session.getAttribute(%22user%22);%0A%0A        return rnt;%0A    %7D
 %0A%7D%0A

add login judge and set/get session for logined user