package com.zhiqiyun.open.core.service.impl;


import com.zhiqiyun.open.core.models.user.OauthInfo;
import com.zhiqiyun.open.core.service.OauthService;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author jtoms
 */
public abstract class BaseOauthService implements OauthService {


    /**
     * 生成密码
     *
     * @param loginPwd
     * @param secret
     * @return
     */
    @Override
    public String generatePassword(String loginPwd, String secret) {
        if (loginPwd == null) {
            return "";
        }
        loginPwd = DigestUtils.sha256Hex(loginPwd);
        return DigestUtils.md5Hex(loginPwd + "@" + secret);
    }

    /**
     * 保存用户登录信息
     *
     * @param accessToken
     * @param oauthInfo
     */
    @Override
    public abstract void setAuth(String accessToken, OauthInfo oauthInfo);

    /**
     * 获取用户登录信息
     *
     * @param accessToken
     * @return
     */
    @Override
    public abstract OauthInfo getAuth(String accessToken);

    /**
     * 销毁用户登录信息
     *
     * @param accessToken
     */
    @Override
    public abstract void destroy(String accessToken);
}
