fei.wang
7 天以前 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;
@@ -46,6 +47,8 @@
    LoginJiLuService loginJiLuService;
    @Autowired
    CompanyService companyService;
    @Autowired
    LoginFailRecordService loginFailRecordService;
    public LoginController() {
    }
@@ -76,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));
//        company.setLoginphone(DESUtil.encrypt(company.getLoginphone(), DESUtil.key));
        if (company.getPassword() != null) {
            company.setPassword(DESUtil.encrypt(company.getPassword(), DESUtil.key));
            company.setPassword(company.getPassword());
        }
        Company company1 = this.companyService.findUser(company);
        if (company1 != null) {
@@ -126,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 {
@@ -157,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;
        }
    }
}