def create_user(self, username, name, password, email, is_active=False, is_staff=False, is_superuser=False): user = User(username=username, name=name, password=self.hasher.encrypt(password), is_active=is_active, is_staff=is_staff, is_superuser=is_superuser) user.last_login = datetime.datetime.now() self.db.add(user) email_object = Email(email=email, user=user, primary=True, verified=False) self.db.add(email_object) # flush the db now so user.id is available self.db.flush() return user
def add_email(self, user_id, email_address, primary=None, verified=False, public=False): user = self.get_user(user_id) # If primary is None, then we're going to auto detect whether this should be the # primary address or not. The basic rule is that if the user doesn't already # have a primary address, then the address we're adding now is going to be # set to their primary. if primary is None: primary = True if user.primary_email is None else False email = Email( email=email_address, user=user, primary=primary, verified=verified, public=public, ) self.db.add(email) self.db.flush() # flush the db now so email.id is available return email
def add_email(self, user_id, email_address, primary=False, verified=False): user = self.get_user(user_id) email = Email( email=email_address, user=user, primary=primary, verified=verified ) self.db.add(email) self.db.flush() # flush the db now so email.id is available return email
def test_has_primary_verified_email(self, db_session, email, verified, allowed): user = DBUserFactory.create() if email: e = Email(email=email, user=user, primary=True, verified=verified) db_session.add(e) db_session.flush() assert user.has_primary_verified_email == allowed
def test_two_factor_provisioning_allowed(self, db_session, email, verified, allowed): user = DBUserFactory.create() if email: e = Email(email=email, user=user, primary=True, verified=verified) db_session.add(e) db_session.flush() assert user.two_factor_provisioning_allowed == allowed
def user_add_email(request): user = request.db.query(User).get(request.matchdict["user_id"]) form = EmailForm(request.POST) if form.validate(): email = Email( email=form.email.data, user=user, primary=form.primary.data, verified=form.verified.data, ) request.db.add(email) request.session.flash(f"Added email for user {user.username!r}", queue="success") return HTTPSeeOther( request.route_path("admin.user.detail", user_id=user.id))
def add_email( self, user_id, email_address, ip_address, primary=None, verified=False, public=False, ): # Check to make sure that we haven't hitten the rate limit for this IP if not self.ratelimiters["email.add"].test(ip_address): self._metrics.increment( "warehouse.email.add.ratelimited", tags=["ratelimiter:email.add"], ) raise TooManyEmailsAdded( resets_in=self.ratelimiters["email.add"].resets_in(ip_address)) user = self.get_user(user_id) # If primary is None, then we're going to auto detect whether this should be the # primary address or not. The basic rule is that if the user doesn't already # have a primary address, then the address we're adding now is going to be # set to their primary. if primary is None: primary = True if user.primary_email is None else False email = Email( email=email_address, user=user, primary=primary, verified=verified, public=public, ) self.db.add(email) self.db.flush() # flush the db now so email.id is available self.ratelimiters["email.add"].hit(ip_address) self._metrics.increment("warehouse.email.add.ok") return email
def create_user(self, username, name, password, email, is_active=False, is_staff=False, is_superuser=False): user = User(username=username, name=name, password=password, is_active=is_active, is_staff=is_staff, is_superuser=is_superuser) user.last_login = datetime.datetime.now() self.db.add(user) email_object = Email(email=email, user=user, primary=True, verified=False) self.db.add(email_object) return user