def authenticate(self): """Checks whether username and password match any records in the User table. """ username = self.form_result['username'] password = unicode( hashlib.sha224(self.form_result['password']).hexdigest()) user_q = meta.Session.query(model.User) user = user_q.filter(model.User.username == username).filter( model.User.password == password).first() if user: # Successful login # Update session and app_globals data (function located in lib/functions.py) h.updateSessionAndGlobals(user) redirect(url(controller='home', action='index')) else: session['flash'] = 'Authentication failed.' return render('/derived/login/login.html')
def authenticate(self): """Checks whether username and password match any records in the User table. """ username = self.form_result['username'] password = unicode( hashlib.sha224(self.form_result['password']).hexdigest()) user_q = meta.Session.query(model.User) user = user_q.filter(model.User.username==username).filter( model.User.password==password).first() if user: # Successful login # Update session and app_globals data (function located in lib/functions.py) h.updateSessionAndGlobals(user) redirect(url(controller='home', action='index')) else: session['flash'] = 'Authentication failed.' return render('/derived/login/login.html')
except Invalid, e: result = {'valid': False, 'errors': e.unpack_errors()} return json.dumps(result) else: username = values['username'] password = unicode(hashlib.sha224(values['password']).hexdigest()) user = meta.Session.query( model.User).filter(model.User.username == username).filter( model.User.password == password).first() if user: # Successful login # Update session and app_globals data (function located in # lib/functions.py) h.updateSessionAndGlobals(user) result = {'valid': True, 'authenticated': True} return json.dumps(result) else: result = {'valid': True, 'authenticated': False} return json.dumps(result) def check_authentication_ajax(self): """Checks if the user is logged in, i.e., checks if 'user_username' is in the session. """ response.headers['Content-Type'] = 'application/json' return json.dumps('user_username' in session)
result = {'valid': False, 'errors': e.unpack_errors()} return json.dumps(result) else: username = values['username'] password = unicode( hashlib.sha224(values['password']).hexdigest()) user = meta.Session.query(model.User).filter( model.User.username==username).filter( model.User.password==password).first() if user: # Successful login # Update session and app_globals data (function located in # lib/functions.py) h.updateSessionAndGlobals(user) result = {'valid': True, 'authenticated': True} return json.dumps(result) else: result = {'valid': True, 'authenticated': False} return json.dumps(result) def check_authentication_ajax(self): """Checks if the user is logged in, i.e., checks if 'user_username' is in the session. """ response.headers['Content-Type'] = 'application/json' return json.dumps('user_username' in session)