Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. @app.route('/')
  2. def index():
  3. if 'username' in session:
  4. return 'Logged in as %s' % escape(session['username'])
  5. return 'You are not logged in'
  6.  
  7. @app.route('/login', methods=['GET', 'POST'])
  8. def login():
  9. if request.method == 'POST':
  10. username = request.form['username']
  11. password = request.form['password']
  12. if authenticate(str(username), str(password)):
  13. session['username'] = request.form['username']
  14. return redirect(url_for('index'))
  15. else:
  16. return 'Invalid username/password'
  17. return '''
  18. <form action="" method="post">
  19. <p><input type=text name=username>
  20. <p><input type=password name=password>
  21. <p><input type=submit value=Login>
  22. </form>
  23. '''
  24. @app.route('/logout')
  25. def logout():
  26. # remove the username from the session if it's there
  27. session.pop('username', None)
  28. return redirect(url_for('index'))
  29.  
  30. <html>
  31. <head>
  32. {% if title %}
  33. <title>{{title}} - Web</title>
  34. {% else %}
  35. <title>Welcome to Web</title>
  36. {% endif %}
  37. </head>
  38. <body>
  39. <h1>Hello, {{username}}!</h1>
  40. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement