def authenticate(self, username=None, password=None, save_password=False): logger.debug('Authenticating {0}'.format(username)) lily = Lily() username = username.lower() session = lily.login(username, password) if session: try: user = User.objects.get(username=username) user.set_password(password) user.save() except User.DoesNotExist: user = User(username=username, password=password) user.save() logger.info('Created new {0}'.format(user)) profile, created = LilyProfile.objects.get_or_create( user=user, defaults={'display_name': session.uid}) if save_password: profile.lily_password = password else: profile.lily_password = None profile.last_session = session.dumps() profile.save() return user else: return None
def get_active_connection(username): try: user = User.objects.get(username=username) except User.DoesNotExist: return None profile = user.get_profile() lily = Lily(profile.last_session) if mc.get('act.{0}'.format(user.id)) or lily.is_logged_in(): logger.debug('{0}: last_session valid. Success'.format(user)) mc.set('act.{0}'.format(user.id), 1, time=60) return lily if profile.lily_password is not None: lily = Lily() session = lily.login(user.username, profile.lily_password) if session: profile.last_session = session.dumps() profile.save() logger.debug('{0}: saved password valid. Success'.format(user)) mc.set('act.{0}'.format(user.id), 1, time=60) return lily else: profile.lily_password = None profile.save() logger.debug('{0}: password changed. Failure'.format(user)) return None else: profile.last_session = None profile.save() logger.debug('{0}: no saved password. Failure'.format(user)) return None
def authenticate(self, username=None, password=None, save_password=False): logger.debug('Authenticating {0}'.format(username)) lily = Lily() username = username.lower() session = lily.login(username, password) if session: try: user = User.objects.get(username=username) user.set_password(password) user.save() except User.DoesNotExist: user = User(username=username, password=password) user.save() logger.info('Created new {0}'.format(user)) profile, created = LilyProfile.objects.get_or_create(user=user, defaults={'display_name': session.uid}) if save_password: profile.lily_password = password else: profile.lily_password = None profile.last_session = session.dumps() profile.save() return user else: return None