Пример #1
0
def register_user(user:UserRegister):
    """Register a new user"""
    if User().get_user_by_email(user.email):
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail='This user is already registered.'
        )
    user.password = bcrypt.hashpw(
        user.password.encode('utf-8'),
        bcrypt.gensalt()
    ).decode('utf-8')
    
    try:
        user = User().register_user(user.dict())
    except Exception as e:
        raise HTTPException(
            status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
            detail=str(e) or 'An unknown error occurred.'
        )
    user.pop('password')
    return {
        "status":True,
        "message":"User successfully registered.",
        "data":user
    }
Пример #2
0
def check_user():
    """Check is nickname avaible and add new nickname to db"""
    nickname = request.args.get("nickname")
    if nickname in users:
        return jsonify({"user": "******"})
    User(nickname)
    return jsonify({"user": "******"})
Пример #3
0
def get_all_users():
    """Get all users"""
    users = User().get_all_users()
    p = [user.pop('password') for user in users]
    if not users:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail='No users found.'
        )
    return {
        'status':True,
        'message':f'Successfully fetched {len(users)} users.',
        'data':users
    }
Пример #4
0
def get_user_by_id(id:str):
    """Get user by id"""
    if not check_valid_id(id):
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
            detail='User ID is invalid.'
        )
    
    user = User().get_user(id)
    if not user:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail='This user does not exist.'
        )
    user['data'].pop('password')
    user['data']['tweets'] = Tweet().get_all_user_tweets(id)
    return {
        'status':True,
        'message':'User successfully fetched.',
        'data':user['data']
    }
Пример #5
0
def login():
    """Log user in"""

    # Forget any user_id
    session.clear()

    # User reached route via POST (as by submitting a form via POST)
    if request.method == "POST":

        # Ensure username was submitted
        if not request.form.get("username"):
            return apology("must provide username", 403)

        # Ensure password was submitted
        elif not request.form.get("password"):
            return apology("must provide password", 403)

        # Query database for username
        db_obj = db.execute("SELECT * FROM users WHERE username = :username",
                            username=request.form.get("username"))

        # Ensure username exists and password is correct
        if len(db_obj) != 1 or not check_password_hash(
                db_obj[0]["hash"], request.form.get("password")):
            return apology("invalid username and/or password", 403)

        # Remember which user has logged in
        session["user_id"] = db_obj[0]["id"]

        # Create user object
        global user
        user = User(db_obj)

        # Redirect user to home page
        return redirect("/")

    # User reached route via GET (as by clicking a link or via redirect)
    else:
        return render_template("login.html")
Пример #6
0
def login_user(user:UserSignIn):
    """Login a registered user."""
    user_data=User().get_user_by_email(user.email)
    if user_data and bcrypt.checkpw(
        user.password.encode('utf-8'),
        user_data['password'].encode('utf-8')):
        token = jwtUtils.generate_jwt(
            {'id':user_data['id'],'email':user_data['email'],'fullname':user_data['fullname'],'username':user_data['username']
        })
        user_data.pop('password')
        return {
            "status":True,
            "message":"User successfully Logged in.",
            "data":{
                **user_data,
                "access_token":token
            }
        }
    else:
        raise HTTPException(
            status_code=status.HTTP_400_BAD_REQUEST,
            detail='Invalid Email or Password'
        )
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from os import chdir
import os.path

import pandas as pd
import curses
import numpy as np
from helpers import is_annotated, Finding, RightSideMenu, MasterTable, fish, ProgressBar, User, Confidence

current_annotator = User()


class SimpleAnnotaor(object):
    def __init__(self):
        self.foo = "bar"

    def check_untypical_length(self, text):
        if len(text) < 250 or len(text) > 2000:
            return True
        else:
            return False


simple_annotator = SimpleAnnotaor()


def scroll_reports(key, row, n_row):
    if key == ord('n') or key == curses.KEY_RIGHT:
        if row < (n_row - 1):
            row += 1