Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. @app.route('/')
  2. @app.route('/login',methods=['GET', 'POST'])
  3. def login():
  4. error=None
  5. if request.method =='POST':
  6. s = Server('appauth.corp.domain.com:636', use_ssl=True, get_info=ALL)
  7. c = Connection(s,user=request.form['username'],password=request.form['password'],check_names=True, lazy=False,raise_exceptions=False)
  8. c.open()
  9. c.bind()
  10.  
  11. if request.form['username'].lower() not in users or (c.bind() != True) is True:
  12. error='Invalid credentials. Please try again'
  13. else:
  14. session['username'] = request.form['username'].lower()
  15. return redirect(url_for('index'))
  16. return render_template('login.html',error=error)
  17. @app.route('/index',methods=['GET','POST'])
  18. def index():
  19. if 'username' in session:
  20. return render_template('index.html')
  21. @app.route('/logout')
  22. def logout():
  23. # remove the username from the session if it's there
  24. session.pop('username', None)
  25. return redirect(url_for('login'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement