def handle_login():
    email, _password = request.json.get(
            "email", None
        ), request.json.get(
            "_password", None
        )
    if not email or not _password:
        return "Missing info", 400
    user = User.get_by_email(email)
    if check_password_hash(user._password, _password):
        if user.is_psychologist and user.is_active:
            print(user.is_active)
            user_psy = User_psychologist.get_by_user_id(user.id)
            access_token = create_access_token(
                identity=user_psy.to_dict(),
                expires_delta=timedelta(minutes=60)
            )
            return jsonify({'token': access_token}), 200
        elif user.is_active:
            user_company = User_company.get_by_user_id(user.id)
            access_token = create_access_token(
                identity=user_company.to_dict(),
                expires_delta=timedelta(minutes=60)
            )
            return jsonify({'token': access_token}), 200
    return "Invalid info", 400
Exemple #2
0
def get_user(id):
    user = User.get_by_id(id)
    user_psychologist = User_psychologist.get_by_user_id(user.id)
    user_company = User_company.get_by_user_id(user.id)
    if user.is_active and user.is_psychologist:
        return jsonify(user_psychologist.to_dict()), 200
    if user.is_active and user.is_psychologist == False:
        return jsonify(user_company.to_dict()), 200