All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.shoulder.security.code.email.EmailCodeProcessor Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.2
Show newest version
package org.shoulder.security.code.email;

import org.shoulder.code.dto.ValidateCodeDTO;
import org.shoulder.code.exception.ValidateCodeException;
import org.shoulder.code.generator.ValidateCodeGenerator;
import org.shoulder.code.processor.AbstractValidateCodeProcessor;
import org.shoulder.code.propertities.BaseValidateCodeProperties;
import org.shoulder.code.store.ValidateCodeStore;
import org.shoulder.security.SecurityConst;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * email验证码处理器
 *
 * @author lym
 */
public class EmailCodeProcessor extends AbstractValidateCodeProcessor implements EmailValidateCodeType {

    /**
     * email验证码发送器
     */
    private final EmailCodeSender emailCodeSender;

    public EmailCodeProcessor(BaseValidateCodeProperties baseValidateCodeProperties, ValidateCodeGenerator validateCodeGenerator,
                              ValidateCodeStore validateCodeStore, EmailCodeSender emailCodeSender) {
        super(baseValidateCodeProperties, validateCodeGenerator, validateCodeStore);
        this.emailCodeSender = emailCodeSender;
    }

    /**
     * email验证码只有 POST 请求才能获取(避免直接在浏览器地址栏上直接访问调用)
     */
    @Override
    protected boolean isPostOnly() {
        return true;
    }

    @Override
    public void send(ServletWebRequest request, ValidateCodeDTO validateCode) throws ValidateCodeException {
        try {
            String email = ServletRequestUtils.getRequiredStringParameter(request.getRequest(),
                    SecurityConst.AUTHENTICATION_EMAIL_PARAMETER_NAME);
            emailCodeSender.send(email, validateCode.getCode());
        } catch (Exception e) {
            throw new ValidateCodeException("send emailCode fail", e);
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy