Guest User

Untitled

a guest
Dec 26th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. @web_bp.route('/login', methods=['GET', 'POST'])
  2. def login():
  3. if request.method == 'POST':
  4. # Delegate request to API login with converting Content-Type to json
  5. api_env = request.environ.copy()
  6. api_req = json.dumps(dict(username=request.form['username'], password=request.form['password']))
  7. api_env['CONTENT_TYPE'] = 'application/json'
  8. api_env['CONTENT_LENGTH'] = len(api_req)
  9. api_env['wsgi.input'] = StringIO(api_req)
  10.  
  11. with current_app.request_context(api_env):
  12. response = current_app.view_functions['api.login']()
  13.  
  14. # Dispatch response
  15. if response.status_code < 300:
  16. # Success
  17. # TODO Keep session
  18. return redirect('index.html')
  19. else:
  20. # TODO Error page or another
  21. return response
  22.  
  23. return render_template('login.html')
Add Comment
Please, Sign In to add comment