def create( cls, name, owner, logo_url=None, contact_email=None, homepage_url=None, privacy_policy_url=None, ): from webapp import utils """Creates a new application. arguments: - name: human-readable name - owner: a User who owns this application. - logo_url: an url to a logo image for this application. - contact_email: an email address that users can use to contact someone about this application. - homepage_url: the url of the application's homepage - privacy_policy_url: the url of the application's privacy policy.""" instance = cls(name=utils.strip_control_chars(name), logo_url=logo_url, contact_email=contact_email, homepage_url=homepage_url, privacy_policy_url=privacy_policy_url) if owner: instance.owners.append(owner.id) return instance
def create(cls, username, email, avatar_url=None): """Create a new user with the given username, email and avatar url.""" logging.debug("Create a new user %r" % { "username": username, "email": email, "avatar_url": avatar_url, }) email_hash = None emails = [] if email: email_hash = md5.md5(email).hexdigest() emails = [email] while not cls.is_username_available(username): username += random.choice("1234567890") instance = cls( id=str(uuid.uuid4()), username=utils.strip_control_chars(username), primary_email=email, email_addresses=emails, avatar_url=avatar_url or "https://gravatar.com/avatar/%s" % email_hash, following=[], joined=datetime.datetime.now(), provided_identities=[], subscriptions=[], is_new=True, is_email_verified=False ) return instance
def create(cls, username, email, avatar_url=None): """Create a new user with the given username, email and avatar url.""" logging.debug("Create a new user %r" % { "username": username, "email": email, "avatar_url": avatar_url, }) email_hash = None emails = [] if email: email_hash = md5.md5(email).hexdigest() emails = [email] while not cls.is_username_available(username): username += random.choice("1234567890") instance = cls(id=str(uuid.uuid4()), username=utils.strip_control_chars(username), primary_email=email, email_addresses=emails, avatar_url=avatar_url or "https://gravatar.com/avatar/%s" % email_hash, following=[], joined=datetime.datetime.now(), provided_identities=[], subscriptions=[], is_new=True, is_email_verified=False) return instance
def update_profile(self, username=None, email=None, avatar_url=None): errors = [] if username and username != user.username: username = utils.strip_control_chars(username) if self.is_username_available(username): self.username = username else: errors.append("The username you entered is taken.") if email: if "@" in email: self.primary_email = email else: errors.append("That email address is invalid.") if avatar_url: try: utils.validate_url(avatar_url) self.avatar_url = avatar_url except ValueError: errors.append("The avatar url is invalid.") return errors
def create(cls, name, owner, logo_url=None, contact_email=None, homepage_url=None, privacy_policy_url=None,): from webapp import utils """Creates a new application. arguments: - name: human-readable name - owner: a User who owns this application. - logo_url: an url to a logo image for this application. - contact_email: an email address that users can use to contact someone about this application. - homepage_url: the url of the application's homepage - privacy_policy_url: the url of the application's privacy policy.""" instance = cls( name=utils.strip_control_chars(name), logo_url=logo_url, contact_email=contact_email, homepage_url=homepage_url, privacy_policy_url=privacy_policy_url ) if owner: instance.owners.append(owner.id) return instance