def reset_password(self): """ Resets the patient's password to match an sha256 hash of a randomly generated string. """ password = generate_easy_alphanumeric_string() self.set_password(password) return password
def create_with_password(cls, **kwargs): """ Creates a new participant with randomly generated patient_id and password. """ # Ensure that a unique patient_id is generated. If it is not after # twenty tries, raise an error. patient_id = generate_easy_alphanumeric_string() for _ in range(20): if not cls.objects.filter(patient_id=patient_id).exists(): # If patient_id does not exist in the database already break patient_id = generate_easy_alphanumeric_string() else: raise RuntimeError( 'Could not generate unique Patient ID for new Participant.') # Create a Participant, and generate for them a password participant = cls(patient_id=patient_id, **kwargs) password = participant.reset_password() # this saves participant return patient_id, password
def create(cls, study_id): """ Creates a new patient with random patient_id and password.""" patient_id = generate_easy_alphanumeric_string() if User(patient_id): cls.create(study_id) #if user exists, recurse. password, password_hash, salt = generate_user_password_and_salt() new_client = { ID_KEY: patient_id, "password":password_hash, 'device_id':None, "salt":salt, 'study_id':study_id } super(User, cls).create(new_client) return patient_id, password
def log_in_researcher(username): """ populate session for a researcher """ session[SESSION_UUID] = generate_easy_alphanumeric_string() session[EXPIRY_NAME] = datetime.now() + timedelta(hours=6) session[SESSION_NAME] = username
def log_in_admin(username): session['admin_uuid'] = generate_easy_alphanumeric_string() session['expiry'] = datetime.now() + timedelta(hours=6) session['admin_username'] = username
def log_in_admin(username, timezone): session['admin_uuid'] = generate_easy_alphanumeric_string() session['expiry'] = datetime.now() + timedelta(seconds=SESSION_EXPIRE_IN_SECONDS) session['admin_username'] = username session['timezone'] = timezone