package com.younike.admin.shiro.authc;

import org.apache.shiro.authc.AuthenticationToken;

/**
 * 自定义认证令牌（AuthenticationToken）：手机验证码认证登录
 * <p>
 * 手机验证：
 */
public class SmsToken implements AuthenticationToken {
    private static final long serialVersionUID = -2191772573134310838L;

    /**
     * 手机号码
     */
    private String phoneNumber;

    /**
     * 验证码
     */
    private char[] verificationCode;

    /**
     * Whether or not 'rememberMe' should be enabled for the corresponding login attempt;
     * default is <code>false</code>
     */
    private boolean rememberMe = false;

    /**
     * The location from where the login attempt occurs, or <code>null</code> if not known or explicitly
     * omitted.
     */
    private String host;

    public SmsToken(String phoneNumber, char[] verificationCode, boolean rememberMe, String host) {
        this.phoneNumber = phoneNumber;
        this.verificationCode = verificationCode;
        this.rememberMe = rememberMe;
        this.host = host;
    }

    public SmsToken(String phoneNumber, String verificationCode, boolean rememberMe, String host) {
        this(phoneNumber, verificationCode != null ? verificationCode.toCharArray() : null, rememberMe, host);
    }

    public SmsToken(String phoneNumber, String verificationCode) {
        this(phoneNumber, verificationCode, false, null);
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public char[] getVerificationCode() {
        return verificationCode;
    }

    public void setVerificationCode(char[] verificationCode) {
        this.verificationCode = verificationCode;
    }


    public void setHost(String host) {
        this.host = host;
    }


    public void setRememberMe(boolean rememberMe) {
        this.rememberMe = rememberMe;
    }

    @Override
    public Object getPrincipal() {
        return this.getPhoneNumber();
    }

    @Override
    public Object getCredentials() {
        return this.getVerificationCode();
    }
}
