diff --git a/app/models.py b/app/models.py index 2bbc23d6..9b423db0 100644 --- a/app/models.py +++ b/app/models.py @@ -168,19 +168,22 @@ class User(db.Model, ModelMixin, UserMixin): else: return url_for("static", filename="default-avatar.png") - def suggested_emails(self) -> (str, [str]): + def suggested_emails(self, website_name) -> (str, [str]): """return suggested email and other email choices """ + website_name = convert_to_id(website_name) + all_gen_emails = [ge.email for ge in GenEmail.filter_by(user_id=self.id)] - if self.can_create_new_random_alias(): - # create a new email - suggested_gen_email = generate_email() + if self.can_create_new_custom_alias(): + suggested_gen_email = GenEmail.create_custom_alias( + self.id, prefix=website_name + ).email else: # pick an email from the list of gen emails suggested_gen_email = random.choice(all_gen_emails) return ( suggested_gen_email, - list(set(all_gen_emails).difference(set([suggested_gen_email]))), + list(set(all_gen_emails).difference({suggested_gen_email})), ) def suggested_names(self) -> (str, [str]): diff --git a/app/oauth/views/authorize.py b/app/oauth/views/authorize.py index 42d8a706..2602624a 100644 --- a/app/oauth/views/authorize.py +++ b/app/oauth/views/authorize.py @@ -100,7 +100,7 @@ def authorize(): LOG.debug("user %s has already allowed client %s", current_user, client) user_info = client_user.get_user_info() else: - suggested_email, other_emails = current_user.suggested_emails() + suggested_email, other_emails = current_user.suggested_emails(client.name) suggested_name, other_names = current_user.suggested_names() email_suffix = random_string(6)