Skip to content

Commit

Permalink
Fix ungraceful error on non-unique OAuthClient title
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Sep 29, 2024
1 parent 5a173ee commit f69bc8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/blueprints/oauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,18 @@ def create_edit_client(username, id_=None):

if form.validate_on_submit():
if is_new:
if OAuthClient.query.filter(OAuthClient.title.ilike(form.title.data.strip())).count() > 0:
flash(gettext("An OAuth client with that title already exists. Please choose a new title."), "danger")
return render_template("oauth/create_edit.html", user=user, form=form, client=client)

client = OAuthClient()
db.session.add(client)
client.owner = user
client.id = random_string(24)
client.secret = random_string(32)
client.approved = current_user.rank.at_least(UserRank.EDITOR)


form.populate_obj(client)

verb = "Created" if is_new else "Edited"
Expand Down
4 changes: 2 additions & 2 deletions app/templates/oauth/create_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ <h3 class="mt-0">{{ _("Application isn't approved yet") }}</h3>
<form method="POST" action="" enctype="multipart/form-data">
{{ form.hidden_tag() }}

{{ render_field(form.title) }}
{{ render_field(form.description, hint=_("Shown to users when you request access to their account")) }}
{{ render_field(form.title, hint=_("Titles must be globally unique. For example, what's the name of your application?")) }}
{{ render_field(form.description, hint=_("Shown to users when you request access to their account. For example, what does your application do?")) }}
{{ render_field(form.redirect_url) }}
{{ render_field(form.app_type, hint=_("Where will you store your client_secret?")) }}

Expand Down

0 comments on commit f69bc8f

Please sign in to comment.