# -*- coding: utf-8 -*-
"""
Created on Sun Jul  5 18:35:37 2020
generate verification token and confirm the verification token
@author: joy
"""

from itsdangerous import URLSafeTimedSerializer
from flask import current_app


def generate_verification_token(email):
    serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
    return serializer.dumps(email,salt=current_app.config['SECURITY_PASSWORD_SALT'])
    
def confirm_verification_token(token, expiration=3600):
    serializer = URLSafeTimedSerializer(current_app.config['SECRET_KEY'])
    try:
        email = serializer.loads(token,salt=current_app.config['SECURITY_PASSWORD_SALT'],max_age=expiration)
    except Exception as e :
        return e
    return email