import re
import hashlib
import os

# from flask import current_app as app
from flask import session
from .models import User

SALT = os.environ["SALT"]


def hasher(s: str) -> str:
    return hashlib.sha256(str(s + SALT).encode()).hexdigest()


def signIn(email: str, password: str) -> bool:

    user = User.objects(email=email)

    if user.count() == 0:
        return False

    user = user[0]

    if hasher(password) == user["password"]:
        # sign in success
        session["user"] = {
            "name": user["email"],
            "email": user["email"],
            "role": user["role"],
        }
        return session["user"]
    else:
        # sign in fail
        return False


def getUser():

    if not "user" in session:
        return False

    user = User.objects.get(email=session["user"]["email"])
    return user

a0d320665cb943ab4df796f74f62fb1b2b2cf871
<mask token>


def hasher(s: str) ->str:
    return hashlib.sha256(str(s + SALT).encode()).hexdigest()


<mask token>

<mask token>


def hasher(s: str) ->str:
    return hashlib.sha256(str(s + SALT).encode()).hexdigest()


def signIn(email: str, password: str) ->bool:
    user = User.objects(email=email)
    if user.count() == 0:
        return False
    user = user[0]
    if hasher(password) == user['password']:
        session['user'] = {'name': user['email'], 'email': user['email'],
            'role': user['role']}
        return session['user']
    else:
        return False


def getUser():
    if not 'user' in session:
        return False
    user = User.objects.get(email=session['user']['email'])
    return user

<mask token>
SALT = os.environ['SALT']


def hasher(s: str) ->str:
    return hashlib.sha256(str(s + SALT).encode()).hexdigest()


def signIn(email: str, password: str) ->bool:
    user = User.objects(email=email)
    if user.count() == 0:
        return False
    user = user[0]
    if hasher(password) == user['password']:
        session['user'] = {'name': user['email'], 'email': user['email'],
            'role': user['role']}
        return session['user']
    else:
        return False


def getUser():
    if not 'user' in session:
        return False
    user = User.objects.get(email=session['user']['email'])
    return user

import re
import hashlib
import os
from flask import session
from .models import User
SALT = os.environ['SALT']


def hasher(s: str) ->str:
    return hashlib.sha256(str(s + SALT).encode()).hexdigest()


def signIn(email: str, password: str) ->bool:
    user = User.objects(email=email)
    if user.count() == 0:
        return False
    user = user[0]
    if hasher(password) == user['password']:
        session['user'] = {'name': user['email'], 'email': user['email'],
            'role': user['role']}
        return session['user']
    else:
        return False


def getUser():
    if not 'user' in session:
        return False
    user = User.objects.get(email=session['user']['email'])
    return user

import re
import hashlib
import os

# from flask import current_app as app
from flask import session
from .models import User

SALT = os.environ["SALT"]


def hasher(s: str) -> str:
    return hashlib.sha256(str(s + SALT).encode()).hexdigest()


def signIn(email: str, password: str) -> bool:

    user = User.objects(email=email)

    if user.count() == 0:
        return False

    user = user[0]

    if hasher(password) == user["password"]:
        # sign in success
        session["user"] = {
            "name": user["email"],
            "email": user["email"],
            "role": user["role"],
        }
        return session["user"]
    else:
        # sign in fail
        return False


def getUser():

    if not "user" in session:
        return False

    user = User.objects.get(email=session["user"]["email"])
    return user
