Beispiel #1
0
def login():
    error = None
    if request.method == 'POST':
        check_user = Player.gql("WHERE username = :username", username=request.form['username'])
        if check_user.count() == 0:
            error = 'Username does not exist'
        elif not verify_password(request.form['password'], check_user.get().password_hash):
            error = "Invalid password"
        else:
            session['logged_in'] = True
            flash('You were logged in')
            return redirect(url_for('show_games'))
    return render_template('login.html', error=error)
Beispiel #2
0
def rest_login():
    error = None
    # The first item is username, and the second is password
    user_data = [str(request.json['username']), str(request.json['password'])]  # get this from the url
    player = Player.all().filter('username ='******'Username does not exist'
        return jsonify({'status': error, "user_id": None})
    elif not verify_password(user_data[1], player.password_hash):
        error = "Invalid password"
        return jsonify({'status': error, "user_id": None})
    else:
        session['logged_in'] = True
        flash('You were logged in')
        return jsonify({'status': True, "user_id": player.key().id()})  # this tells the client side that the user is successfully logged in