예제 #1
0
def verify_password(username, password):
    user = User.query.filter_by(username=username).first()
    if not user or not user.verify_password(password):
        raise myexception.Unauthorized("Invalid username or password", 401)
    g.user = user
    session['logged_in'] = True
    raise myexception.Unauthorized("Access Granted and logged in", 200)
예제 #2
0
def authenticate():
    # if session['logged_in'] == False:
    username = request.authorization.username
    password = request.authorization.password
    if username is None or password is None:
        raise myexception.Unauthorized("Please enter username and password",
                                       401)
        # abort(400)  # missing arguments
    elif User.query.filter_by(username=username).first() is not None:
        verify_password(username, password)
예제 #3
0
def new_user():
    username = request.authorization.username
    password = request.authorization.password
    if username == '' or password == '':
        raise myexception.Unauthorized("Please enter username and password",
                                       401)  # missing arguments
    elif User.query.filter_by(username=username).first() is not None:
        raise myexception.UserExists("User Already exists",
                                     402)  # existing user
    else:
        user = User(username=username)
        user.hash_password(password)
        db.session.add(user)
        db.session.commit()
        raise myexception.AccessGranted("New user added and Logged in", 200)