def successful_login(self, user, assumed_by=None): login_rec = model.Login(user) login_rec.successful = True login_rec.session_id = str(uuid.uuid4()) login_rec.assumed_by = assumed_by #session_id = "session_id:{}".format(login_rec.session_id) session_id_signature = actual_hmac_creation(login_rec.session_id) session_id_signed = login_rec.session_id + ":" + session_id_signature logger.debug("session_id_signed:", session_id_signed) session = dict(login_time = time.time(), user_id = user.id, user_email_address = user.email_address) key = UserSession.cookie_name + ":" + login_rec.session_id logger.debug("Key when signing:", key) Redis.hmset(key, session) if self.remember_me: expire_time = self.remember_time else: expire_time = THREE_DAYS Redis.expire(key, expire_time) db_session.add(login_rec) db_session.commit() return session_id_signed
def successful_login(self, user, assumed_by=None): login_rec = model.Login(user) login_rec.successful = True login_rec.session_id = str(uuid.uuid4()) login_rec.assumed_by = assumed_by #session_id = "session_id:{}".format(login_rec.session_id) session_id_signature = actual_hmac_creation(login_rec.session_id) session_id_signed = login_rec.session_id + ":" + session_id_signature logger.debug("session_id_signed:", session_id_signed) session = dict(login_time=time.time(), user_id=user.id, user_email_address=user.email_address) key = UserSession.cookie_name + ":" + login_rec.session_id logger.debug("Key when signing:", key) Redis.hmset(key, session) if self.remember_me: expire_time = self.remember_time else: expire_time = THREE_DAYS Redis.expire(key, expire_time) db_session.add(login_rec) db_session.commit() return session_id_signed
def __init__(self, kw): self.thank_you_mode = False self.errors = [] self.user = Bunch() self.user.email_address = kw.get('email_address', '').strip() if not (5 <= len(self.user.email_address) <= 50): self.errors.append( 'Email Address needs to be between 5 and 50 characters.') self.user.full_name = kw.get('full_name', '').strip() if not (5 <= len(self.user.full_name) <= 50): self.errors.append( 'Full Name needs to be between 5 and 50 characters.') self.user.organization = kw.get('organization', '').strip() if self.user.organization and not (5 <= len(self.user.organization) <= 50): self.errors.append( 'Organization needs to be empty or between 5 and 50 characters.' ) password = str(kw.get('password', '')) if not (6 <= len(password)): self.errors.append('Password needs to be at least 6 characters.') if kw.get('password_confirm') != password: self.errors.append("Passwords don't match.") if self.errors: return logger.debug("No errors!") set_password(password, self.user) self.user.registration_info = json.dumps(basic_info(), sort_keys=True) self.new_user = model.User(**self.user.__dict__) db_session.add(self.new_user) try: db_session.commit() except sqlalchemy.exc.IntegrityError: # This exception is thrown if the email address is already in the database # To do: Perhaps put a link to sign in using an existing account here self.errors.append( "An account with this email address already exists. " "Click the button above to sign in using an existing account.") return logger.debug("Adding verification email to queue") #self.send_email_verification() VerificationEmail(self.new_user) logger.debug("Added verification email to queue") self.thank_you_mode = True
def import_traits_to_user(self): collections_list = json.loads(Redis.get(self.key)) for collection in collections_list: uc = model.UserCollection() uc.name = collection['name'] collection_exists = g.user_session.user_ob.get_collection_by_name(uc.name) if collection_exists: continue else: uc.user = g.user_session.user_id uc.members = json.dumps(collection['members']) db_session.add(uc) db_session.commit()
def __init__(self, kw): self.thank_you_mode = False self.errors = [] self.user = Bunch() self.user.email_address = kw.get('email_address', '').strip() if not (5 <= len(self.user.email_address) <= 50): self.errors.append('Email Address needs to be between 5 and 50 characters.') self.user.full_name = kw.get('full_name', '').strip() if not (5 <= len(self.user.full_name) <= 50): self.errors.append('Full Name needs to be between 5 and 50 characters.') self.user.organization = kw.get('organization', '').strip() if self.user.organization and not (5 <= len(self.user.organization) <= 50): self.errors.append('Organization needs to be empty or between 5 and 50 characters.') password = str(kw.get('password', '')) if not (6 <= len(password)): self.errors.append('Password needs to be at least 6 characters.') if kw.get('password_confirm') != password: self.errors.append("Passwords don't match.") if self.errors: return logger.debug("No errors!") set_password(password, self.user) self.user.registration_info = json.dumps(basic_info(), sort_keys=True) self.new_user = model.User(**self.user.__dict__) db_session.add(self.new_user) try: db_session.commit() except sqlalchemy.exc.IntegrityError: # This exception is thrown if the email address is already in the database # To do: Perhaps put a link to sign in using an existing account here self.errors.append("An account with this email address already exists. " "Click the button above to sign in using an existing account.") return logger.debug("Adding verification email to queue") #self.send_email_verification() VerificationEmail(self.new_user) logger.debug("Added verification email to queue") self.thank_you_mode = True
def create_new(collection_name): params = request.args uc = model.UserCollection() uc.name = collection_name print("user_session:", g.user_session.__dict__) uc.user = g.user_session.user_id unprocessed_traits = params['traits'] traits = process_traits(unprocessed_traits) uc.members = json.dumps(list(traits)) print("traits are:", traits) db_session.add(uc) db_session.commit() print("Created: " + uc.name) return redirect(url_for('view_collection', uc_id=uc.id))
def __init__(self, kw): self.thank_you_mode = False self.errors = [] self.user = Bunch() self.user.email_address = kw.get('email_address', '').strip() if not (5 <= len(self.user.email_address) <= 50): self.errors.append('Email Address needs to be between 5 and 50 characters.') self.user.full_name = kw.get('full_name', '').strip() if not (5 <= len(self.user.full_name) <= 50): self.errors.append('Full Name needs to be between 5 and 50 characters.') self.user.organization = kw.get('organization', '').strip() if self.user.organization and not (5 <= len(self.user.organization) <= 50): self.errors.append('Organization needs to be empty or between 5 and 50 characters.') password = str(kw.get('password', '')) if not (6 <= len(password)): self.errors.append('Password needs to be at least 6 characters.') if kw.get('password_confirm') != password: self.errors.append("Passwords don't match.") if self.errors: return print("No errors!") set_password(password, self.user) self.user.registration_info = json.dumps(basic_info(), sort_keys=True) self.new_user = model.User(**self.user.__dict__) db_session.add(self.new_user) db_session.commit() print("Adding verification email to queue") #self.send_email_verification() VerificationEmail(self.new_user) print("Added verification email to queue") self.thank_you_mode = True
def create_new(collection_name): params = request.args unprocessed_traits = params['traits'] traits = process_traits(unprocessed_traits) if g.user_session.logged_in: uc = model.UserCollection() uc.name = collection_name print("user_session:", g.user_session.__dict__) uc.user = g.user_session.user_id uc.members = json.dumps(list(traits)) db_session.add(uc) db_session.commit() return redirect(url_for('view_collection', uc_id=uc.id)) else: current_collections = user_manager.AnonUser().get_collections() ac = AnonCollection(collection_name) ac.changed_timestamp = datetime.datetime.utcnow().strftime('%b %d %Y %I:%M%p') ac.add_traits(params) return redirect(url_for('view_collection', collection_id=ac.id))
def unsuccessful_login(self, user): login_rec = model.Login(user) login_rec.successful = False db_session.add(login_rec) db_session.commit()