fei.wang
9 天以前 e15f561a1f9eddfde503d59baf45a860b131928e
src/main/java/com/flow/controller/LoginController.java
@@ -9,6 +9,7 @@
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;
@@ -21,12 +22,14 @@
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;
@@ -44,6 +47,8 @@
    LoginJiLuService loginJiLuService;
    @Autowired
    CompanyService companyService;
    @Autowired
    LoginFailRecordService loginFailRecordService;
    public LoginController() {
    }
@@ -52,19 +57,19 @@
    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));
        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());
    }
    @GetMapping({"FindLoginJiLuZi"})
    public result<List<Loginjilu>> FindCardZi(String Zong, Integer page, Integer limit) throws Exception {
        PageInfo<Loginjilu> cz = this.loginJiLuService.FindLoginJiLuZi(Zong, page, limit);
    @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));
        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());
@@ -74,9 +79,10 @@
    @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(DESUtil.encrypt(company.getPassword(), DESUtil.key));
//        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) {
@@ -124,6 +130,39 @@
        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 {
@@ -155,4 +194,32 @@
        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;
        }
    }
}