Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @web_bp.route('/login', methods=['GET', 'POST'])
- def login():
- if request.method == 'POST':
- # Delegate request to API login with converting Content-Type to json
- api_env = request.environ.copy()
- api_req = json.dumps(dict(username=request.form['username'], password=request.form['password']))
- api_env['CONTENT_TYPE'] = 'application/json'
- api_env['CONTENT_LENGTH'] = len(api_req)
- api_env['wsgi.input'] = StringIO(api_req)
- with current_app.request_context(api_env):
- response = current_app.view_functions['api.login']()
- # Dispatch response
- if response.status_code < 300:
- # Success
- # TODO Keep session
- return redirect('index.html')
- else:
- # TODO Error page or another
- return response
- return render_template('login.html')
Add Comment
Please, Sign In to add comment