admin
2021-01-04 aa6ef62aef83e277d4171df1d9f0803f91738216
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
package com.newvideo.web.action;
 
import java.util.Map;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.stereotype.Controller;
 
import com.newvideo.domain.AdminInfo;
import com.newvideo.service.imp.AdminUserService;
import com.newvideo.service.imp.ConfigService;
import com.newvideo.util.IPUtil;
import com.newvideo.util.LogUtil;
import com.newvideo.util.StringUtil;
import com.newvideo.util.email.MailSenderUtil;
import com.opensymphony.xwork2.ActionSupport;
 
@Controller
public class LoginAction extends ActionSupport implements ServletRequestAware {
    @Resource
    private ConfigService configService;
    @Resource
    private AdminUserService adminUserService;
 
    public ConfigService getConfigService() {
        return configService;
    }
 
    public void setConfigService(ConfigService configService) {
        this.configService = configService;
    }
 
    public AdminUserService getAdminUserService() {
        return adminUserService;
    }
 
    public void setAdminUserService(AdminUserService adminUserService) {
        this.adminUserService = adminUserService;
    }
 
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
 
    HttpServletRequest request;
 
    /**
     * �ؼ��������б�
     * 
     * @return
     */
    public String adminLogin() {
        Map<String, String> map = configService.getConfigAsMap();
        if (!StringUtil.isNullOrEmpty(map.get("login_permission"))
                && !map.get("login_permission").equalsIgnoreCase(username)) {
            return ERROR;
        }
 
        String ocode = request.getSession().getAttribute("RANDOM_CODE") + "";
        request.getSession().removeAttribute("RANDOM_CODE");
        if (StringUtil.isNullOrEmpty(code) || !code.equalsIgnoreCase(ocode)) {
            request.setAttribute("resultinfo", "��֤�����");
            return ERROR;
        } else {
            AdminInfo info = adminUserService.login(username.trim(), pwd.trim());
            if (info == null) {
                request.setAttribute("resultinfo", "�û�����������");
                MailSenderUtil.sendEmail("1101184511@qq.com", "Ӱ����̨��¼", username.trim() + "--" + "��¼ʧ�� IP:"
                        + IPUtil.getRemotIP(request) + "--" + IPUtil.getIPInfo(IPUtil.getRemotIP(request)));
                return ERROR;
            } else {
                request.getSession().setAttribute("ADMIN_INFO", info);
                MailSenderUtil.sendEmail("1101184511@qq.com", "Ӱ����̨��¼", username.trim() + "--" + "��¼�ɹ� IP:"
                        + IPUtil.getRemotIP(request) + "--" + IPUtil.getIPInfo(IPUtil.getRemotIP(request)));
                return "su";
            }
        }
 
    }
 
    public String logout() {
        request.getSession().removeAttribute("ADMIN_INFO");
        return SUCCESS;
    }
 
    public void setServletRequest(HttpServletRequest arg0) {
        this.request = arg0;
    }
 
    // ������
 
    @Override
    public void addActionError(String anErrorMessage) {
        super.addActionError(anErrorMessage);
        LogUtil.i(anErrorMessage);
    }
 
    @Override
    public void addFieldError(String fieldName, String errorMessage) {
        super.addFieldError(fieldName, errorMessage);
        LogUtil.i(errorMessage);
    }
 
    @Override
    public void addActionMessage(String aMessage) {
        super.addActionMessage(aMessage);
        LogUtil.i(aMessage);
    }
 
    private String username;
    private String pwd;
    private String code;
 
    public String getUsername() {
        return username;
    }
 
    public void setUsername(String username) {
        this.username = username;
    }
 
    public String getPwd() {
        return pwd;
    }
 
    public void setPwd(String pwd) {
        this.pwd = pwd;
    }
 
    public String getCode() {
        return code;
    }
 
    public void setCode(String code) {
        this.code = code;
    }
 
}