def validator(self): token = None if 'user_token' in request.form: token = request.form['user_token'] elif 'user_token' in request.args: token = request.args.get('user_token') if token: this_user = User.get_user(user_token=token) if this_user and this_user.token_matches(token): return True return False
def register(): if request.method == 'POST': email = request.form['email'] pw1, pw2 = request.form['password1'], request.form['password2'] if User.get_user(email=email): flash("That email is already taken!", 'error') return render_template('register.html') elif len(pw1) < 6: flash("Passwords must be at least six characters!", 'error') return render_template('register.html', email=email) elif pw1 != pw2: flash("Passwords do not match!", 'error') return render_template('register.html', email=email) new_user = User(email, pw1) new_user.save() flash("Account successfully created.", 'success') return render_template('login.html') else: return render_template('register.html')
def logout(): """ Called when an API user wishes to log out and stop using their token. """ auth_user = User.get_user(user_token=request.form['user_token']) auth_user.clear_token() return JSON_SUCCESS()
def get_test_user(): user = User.get_user(email='test') if not user: user = User('test', base64.b64encode(os.urandom(16))) return user
def test_func(): """ Test function for logged in users. """ auth_user = User.get_user(user_token=request.form['user_token']) return JSON_SUCCESS(your_email=auth_user.email)