package com.philisense.www.api.generator.impl;

import com.philisense.www.api.generator.VcodeGenerator;
import com.philisense.www.dto.EmailCode;
import com.philisense.www.properties.VcodeProperties;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.web.context.request.ServletWebRequest;

import javax.annotation.Resource;

/**
 * 邮件验证码生成
 */
public class EmailCodeGenerator implements VcodeGenerator {

    @Resource
    private VcodeProperties vcodeProperties;

    @Override
    public EmailCode generate(ServletWebRequest request) {
        int length = vcodeProperties.getCodeLength();
        String code = RandomStringUtils.randomNumeric(length);
        return new EmailCode(code);
    }
}
