package cn.updev.Users.Static;

import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
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(){

    }

    public Login(String email, String passWord) {

        // email是用户注册邮箱
        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())){
            setSession();
            return true;
        }

        return false;
    }

    private void setSession(){

        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();

        session.setAttribute("user", user);

    }

    public IUser getLoginedUser(){

        HttpServletRequest request = ServletActionContext.getRequest();
        HttpSession session = request.getSession();

        IUser rnt = (IUser) session.getAttribute("user");

        return rnt;
    }
}

@@ -241,16 +241,80 @@
 ception;
+%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;
 %0A%0A/**%0A *
@@ -518,16 +518,251 @@
 ord) %7B%0A%0A
+        //%E5%88%A4%E6%96%AD%E5%90%88%E6%B3%95E-Mail%0A        Pattern pattern = Pattern.compile(%22%5E%5C%5Cs*%5C%5Cw+(?:%5C%5C.%7B0,1%7D%5B%5C%5Cw-%5D+)*@%5Ba-zA-Z0-9%5D+(?:%5B-.%5D%5Ba-zA-Z0-9%5D+)*%5C%5C.%5Ba-zA-Z%5D+%5C%5Cs*$%22);%0A        Matcher matcher = pattern.matcher(email);%0A%0A        if(matcher.matches())%7B%0A%0A    
         
@@ -777,16 +777,20 @@
 %E6%98%AF%E7%94%A8%E6%88%B7%E6%B3%A8%E5%86%8C%E9%82%AE%E7%AE%B1%0A
+    
         
@@ -801,16 +801,98 @@
  = null;
+%0A        %7Delse%7B%0A%0A            // %E9%82%AE%E7%AE%B1%E9%9D%9E%E6%B3%95%EF%BC%8C%E4%B8%8D%E7%94%A8%E5%86%8D%E5%8E%BB%E5%B0%9D%E8%AF%95%E8%8E%B7%E5%8F%96%E7%94%A8%E6%88%B7%0A            user = null;%0A        %7D
 %0A%0A      
@@ -1654,25 +1654,32 @@
 tAttribute(%22
-u
+LoingedU
 ser%22, user);
@@ -1898,17 +1898,24 @@
 ribute(%22
-u
+LoingedU
 ser%22);%0A%0A

update login