Skip to content

Commit f69bc8f

Browse files
committed
Fix ungraceful error on non-unique OAuthClient title
1 parent 5a173ee commit f69bc8f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

app/blueprints/oauth/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,18 @@ def create_edit_client(username, id_=None):
194194

195195
if form.validate_on_submit():
196196
if is_new:
197+
if OAuthClient.query.filter(OAuthClient.title.ilike(form.title.data.strip())).count() > 0:
198+
flash(gettext("An OAuth client with that title already exists. Please choose a new title."), "danger")
199+
return render_template("oauth/create_edit.html", user=user, form=form, client=client)
200+
197201
client = OAuthClient()
198202
db.session.add(client)
199203
client.owner = user
200204
client.id = random_string(24)
201205
client.secret = random_string(32)
202206
client.approved = current_user.rank.at_least(UserRank.EDITOR)
203207

208+
204209
form.populate_obj(client)
205210

206211
verb = "Created" if is_new else "Edited"

app/templates/oauth/create_edit.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ <h3 class="mt-0">{{ _("Application isn't approved yet") }}</h3>
6464
<form method="POST" action="" enctype="multipart/form-data">
6565
{{ form.hidden_tag() }}
6666

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

0 commit comments

Comments
 (0)