Spaces:
Runtime error
Runtime error
File size: 1,162 Bytes
b9a69cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from flask_login import LoginManager, UserMixin
from werkzeug.security import check_password_hash, generate_password_hash
from portalrhjobs.ext.database import db
from PortalRH.portalrhjobs.ext.models import User
login_manager = LoginManager()
def init_app(app):
def verify_login(user):
"""Valida o usuario e senha para efetuar o login"""
username = user.get('username')
password = user.get('password')
if not username or not password:
return False
existing_user = User.query.filter_by(username=username).first()
if not existing_user:
return False
if check_password_hash(existing_user.password, password):
return True
return False
def create_user(username, password):
"""Registra um novo usuario caso nao esteja cadastrado"""
if User.query.filter_by(username=username).first():
raise RuntimeError(f'{username} ja esta cadastrado')
user = User(username=username, password=generate_password_hash(password))
db.session.add(user)
db.session.commit()
return user
|