def log_in(): username = request.form['username'] password = request.form['password'] user = load_user(username) if user: hashed = user.passw if bcrypt.check_password_hash(hashed, password): # everything's gucci login_user(user) return serve_response({}) return serve_error('invalid username or password', 401)
def log_in(): username = request.form['username'] password = request.form['password'] user = load_user(username) if user: hashed = user.password if bcrypt.check_password_hash(hashed, password): # everything's gucci login_user(user) Event.log(username, 'login') return serve_response({}) return serve_error('invalid username or password', 401)
def create_user(): """Create a new user""" # Get form contents username = request.form['username'] password = request.form['password'] display = request.form['display'] # Create the user if doesn't already exist user = load_user(username) if user is None: hashed = bcrypt.generate_password_hash(password) user = User(username=username, passw=hashed, display=display, admin=0) user.commit_to_session() return serve_response({}) return serve_error('username already exists', 401)
def create_user(): # Verify that the poster is an admin if current_user.admin == 0: return server_error('Must be admin to create users', 401) # Get form contents username = request.form['username'] password = request.form['password'] display = request.form['display'] # Create the user if doesn't already exist user = load_user(username) if user is None: hashed = bcrypt.generate_password_hash(password) user = User(username=username, passw=hashed, display=display, admin=0) session.add(user) session.flush() session.commit() return serve_response({}) return serve_error('username already exists', 401)