def login(): if request.method == 'POST': user = model.authenticate(request.form['username'], request.form['password']) if user: login_user(user, remember=True) url = request.form['next'] if 'next' in request.form else '/' return redirect(url) else: flash('Invalid login', 'error') return redirect('/login') return render_template('users/login.html', next=request.args.get('next'))
def decorated(*args, **kwargs): auth = request.authorization if auth: from literable.model import authenticate user = authenticate(auth.username, auth.password) if user: login_user(user) return f(*args, **kwargs) return Response( 'Could not verify your access level for that URL.\n' 'You have to login with proper credentials', 401, {'WWW-Authenticate': 'Basic realm="Login Required"'})