fei.wang
10 天以前 e15f561a1f9eddfde503d59baf45a860b131928e
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
 
package com.flow.controller;
 
import com.flow.pojo.Company;
import com.flow.pojo.Loginjilu;
import com.flow.service.CompanyService;
import com.flow.service.LoginJiLuService;
import com.flow.service.LoginFailRecordService;
import com.flow.util.DESUtil;
import com.flow.util.IpUtil;
import com.flow.util.result;
import com.flow.util.resultutil;
import com.github.pagehelper.PageInfo;
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
 
import java.io.IOException;
import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;
 
@RequestMapping({"/hxzk"})
@RestController
public class LoginController {
    private String SecretId = "AKIDrjZOI4e6KLZu9FAsSRN8eOwSt52lbMBz";
    private String SecretKey = "xnRtHUL3YqdMyOLVSBjKkz1pQoxujS4d";
    @Autowired
    LoginJiLuService loginJiLuService;
    @Autowired
    CompanyService companyService;
    @Autowired
    LoginFailRecordService loginFailRecordService;
 
    public LoginController() {
    }
 
    @GetMapping({"FindLoginJiLu"})
    public result<List<Loginjilu>> FindCard(Integer page, Integer limit) throws Exception {
        PageInfo<Loginjilu> cz = this.loginJiLuService.FindLoginJiLu(page, limit);
 
        for (int i = 0; i < cz.getSize(); ++i) {
            ((Loginjilu) cz.getList().get(i)).setLoginphone(DESUtil.decrypt(((Loginjilu) cz.getList().get(i)).getLoginphone(), DESUtil.key));
        }
 
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @PostMapping({"FindLoginJiLuZi"})
    public result<List<Loginjilu>> FindCardZi(Loginjilu loginjilu, Integer page, Integer limit) throws Exception {
        PageInfo<Loginjilu> cz = this.loginJiLuService.FindLoginJiLuZi(loginjilu, page, limit);
 
        for (int i = 0; i < cz.getSize(); ++i) {
            ((Loginjilu) cz.getList().get(i)).setLoginphone(DESUtil.decrypt(((Loginjilu) cz.getList().get(i)).getLoginphone(), DESUtil.key));
        }
 
        return resultutil.returnSuccess(cz.getTotal(), cz.getList());
    }
 
    @PostMapping({"Login"})
    @ResponseBody
    public Company Login(Company company, HttpSession session) throws Exception {
        company.setCompanyabbname(company.getCompanyabbname());
 
//        company.setLoginphone(DESUtil.encrypt(company.getLoginphone(), DESUtil.key));
        if (company.getPassword() != null) {
            company.setPassword(company.getPassword());
        }
        Company company1 = this.companyService.findUser(company);
        if (company1 != null) {
            session.setAttribute("admin", company.getCompanyabbname());
        }
 
        return company1;
    }
 
    @PostMapping({"LoginIp"})
    @ResponseBody
    public int Login(Loginjilu loginjilu, HttpServletRequest request) throws Exception {
        String ip = IpUtil.getIpAddress(request);
        loginjilu.setIp(ip);
        return this.loginJiLuService.LoginIp(loginjilu);
    }
 
    @GetMapping({"fwl"})
    public List fwl() {
        return this.loginJiLuService.fwl();
    }
 
    @GetMapping({"huiLogin"})
    public void hui(HttpServletResponse response) throws IOException {
        response.sendRedirect("../Login.jsp");
    }
 
    @PostMapping({"upUser"})
    public ModelAndView UpUser(Company company, HttpServletResponse response) throws Exception {
        this.companyService.upUser(company);
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/page/setting.jsp");
        return modelAndView;
    }
 
    @ResponseBody
    @PostMapping({"lophone"})
    public Company lophone(Company company) throws Exception {
        return this.companyService.HuoPhone(company);
    }
 
    @PostMapping({"userdate"})
    public int userdate(String Zong) {
        String userdate = this.loginJiLuService.userdate(Zong);
        return this.loginJiLuService.upuserdate(Zong, userdate);
    }
 
    @PostMapping({"accountLogin"})
    @ResponseBody
    public Company accountLogin(String account, String password, HttpSession session) throws Exception {
        if (account == null || password == null) {
            return null;
        }
        
        // 检查账号是否被锁定
        if (loginFailRecordService.isAccountLocked(account)) {
            // 账号被锁定,返回特殊标识
            Company lockedCompany = new Company();
            lockedCompany.setCompanyabbname("LOCKED");
            return lockedCompany;
        }
        
        // 构造Company对象,假设account为公司简称或登录账号字段
        Company company = new Company();
        company.setLoginphone(account);
        company.setPassword(password);
        Company company1 = this.companyService.findUser(company);
        
        if (company1 != null) {
            // 登录成功,清除失败记录
            loginFailRecordService.unlockAccount(account);
            session.setAttribute("admin", company.getCompanyabbname());
        } else {
            // 登录失败,记录失败次数
            loginFailRecordService.recordLoginFail(account);
        }
        
        return company1;
    }
 
    @GetMapping({"Login11"})
    @ResponseBody
    public int sms(String phone) throws TencentCloudSDKException {
        int randomNumber = 0;
 
        try {
            Random random = new Random();
            randomNumber = random.nextInt(10000) + 10000;
            System.out.println("生成的随机整数是:" + randomNumber);
            Credential cred = new Credential(this.SecretId, this.SecretKey);
            HttpProfile httpProfile = new HttpProfile();
            httpProfile.setEndpoint("sms.tencentcloudapi.com");
            ClientProfile clientProfile = new ClientProfile();
            clientProfile.setHttpProfile(httpProfile);
            SmsClient client = new SmsClient(cred, "ap-beijing", clientProfile);
            SendSmsRequest req = new SendSmsRequest();
            String[] phoneNumberSet1 = new String[]{phone};
            req.setPhoneNumberSet(phoneNumberSet1);
            req.setSmsSdkAppId("1400838975");
            req.setSignName("北京华星北斗智控");
            req.setTemplateId("1878379");
            String[] templateParamSet1 = new String[]{String.valueOf(randomNumber)};
            req.setTemplateParamSet(templateParamSet1);
            SendSmsResponse resp = client.SendSms(req);
            System.out.println(SendSmsResponse.toJsonString(resp));
        } catch (TencentCloudSDKException var12) {
            System.out.println(var12.toString());
        }
 
        return randomNumber;
    }
    
    /**
     * 验证码登录解锁账号
     */
    @PostMapping({"unlockAccountBySms"})
    @ResponseBody
    public Company unlockAccountBySms(String phone, String verificationCode, HttpSession session) throws Exception {
        if (phone == null || verificationCode == null) {
            return null;
        }
        
        // 验证验证码(这里需要根据实际的验证码验证逻辑来实现)
        // 假设验证码验证成功
        boolean isCodeValid = true; // 这里应该调用实际的验证码验证逻辑
        
        if (isCodeValid) {
            // 验证码正确,解锁账号
            loginFailRecordService.unlockAccount(phone);
            
            // 返回登录成功的信息
            Company company = new Company();
            company.setCompanyabbname("UNLOCKED");
            session.setAttribute("admin", phone);
            return company;
        } else {
            return null;
        }
    }
}