Skip to content

Commit 85fa954

Browse files
authored
Improve some Forms (#24878)
Don't really know a better name for this. I've gone through some Forms and added missing HTML attributes (mostly `maxlength`). I tried to fill the Forms with dummy Data and see if Gitea throws a Error (e.g. maximum length). If yes, I added the missing HTML attribute. While working on this, I discovered that the Form to add OAuth2 Apps just silently fails when filled with invalid data, so I fixed that too.
1 parent 18f26cf commit 85fa954

20 files changed

+39
-38
lines changed

routers/web/user/setting/oauth2_common.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func (oa *OAuth2CommonHandlers) renderEditPage(ctx *context.Context) {
3131
func (oa *OAuth2CommonHandlers) AddApp(ctx *context.Context) {
3232
form := web.GetForm(ctx).(*forms.EditOAuth2ApplicationForm)
3333
if ctx.HasError() {
34+
ctx.Flash.Error(ctx.GetErrMsg())
3435
// go to the application list page
3536
ctx.Redirect(oa.BasePathList)
3637
return

templates/admin/user/edit.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{{.CsrfTokenHtml}}
1010
<div class="field {{if .Err_UserName}}error{{end}}">
1111
<label for="user_name">{{.locale.Tr "username"}}</label>
12-
<input id="user_name" name="user_name" value="{{.User.Name}}" autofocus {{if not .User.IsLocal}}disabled{{end}}>
12+
<input id="user_name" name="user_name" value="{{.User.Name}}" autofocus {{if not .User.IsLocal}}disabled{{end}} maxlength="40">
1313
</div>
1414
<!-- Types and name -->
1515
<div class="inline required field {{if .Err_LoginType}}error{{end}}">
@@ -59,7 +59,7 @@
5959
</div>
6060
<div class="field {{if .Err_FullName}}error{{end}}">
6161
<label for="full_name">{{.locale.Tr "settings.full_name"}}</label>
62-
<input id="full_name" name="full_name" value="{{.User.FullName}}">
62+
<input id="full_name" name="full_name" value="{{.User.FullName}}" maxlength="100">
6363
</div>
6464
<div class="required field {{if .Err_Email}}error{{end}}">
6565
<label for="email">{{.locale.Tr "email"}}</label>
@@ -72,18 +72,18 @@
7272
</div>
7373
<div class="field {{if .Err_Website}}error{{end}}">
7474
<label for="website">{{.locale.Tr "settings.website"}}</label>
75-
<input id="website" name="website" type="url" value="{{.User.Website}}" placeholder="e.g. http://mydomain.com or https://mydomain.com">
75+
<input id="website" name="website" type="url" value="{{.User.Website}}" placeholder="e.g. http://mydomain.com or https://mydomain.com" maxlength="255">
7676
</div>
7777
<div class="field {{if .Err_Location}}error{{end}}">
7878
<label for="location">{{.locale.Tr "settings.location"}}</label>
79-
<input id="location" name="location" value="{{.User.Location}}">
79+
<input id="location" name="location" value="{{.User.Location}}" maxlength="50">
8080
</div>
8181

8282
<div class="ui divider"></div>
8383

8484
<div class="inline field {{if .Err_MaxRepoCreation}}error{{end}}">
8585
<label for="max_repo_creation">{{.locale.Tr "admin.users.max_repo_creation"}}</label>
86-
<input id="max_repo_creation" name="max_repo_creation" type="number" value="{{.User.MaxRepoCreation}}">
86+
<input id="max_repo_creation" name="max_repo_creation" type="number" min="-1" value="{{.User.MaxRepoCreation}}">
8787
<p class="help">{{.locale.Tr "admin.users.max_repo_creation_desc"}}</p>
8888
</div>
8989

@@ -181,7 +181,7 @@
181181

182182
<div class="inline field">
183183
<label for="avatar">{{.locale.Tr "settings.choose_new_avatar"}}</label>
184-
<input name="avatar" type="file" >
184+
<input name="avatar" type="file" accept="image/png,image/jpeg,image/gif,image/webp">
185185
</div>
186186

187187
<div class="field">

templates/admin/user/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
</div>
5454
<div class="required field {{if .Err_UserName}}error{{end}}">
5555
<label for="user_name">{{.locale.Tr "username"}}</label>
56-
<input id="user_name" type="text" name="user_name" value="{{.user_name}}" autofocus required>
56+
<input id="user_name" type="text" name="user_name" value="{{.user_name}}" autofocus required maxlength="40">
5757
</div>
5858
<div class="required field {{if .Err_Email}}error{{end}}">
5959
<label for="email">{{.locale.Tr "email"}}</label>

templates/org/settings/options.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
<div class="inline field {{if .Err_MaxRepoCreation}}error{{end}}">
7171
<label for="max_repo_creation">{{.locale.Tr "admin.users.max_repo_creation"}}</label>
72-
<input id="max_repo_creation" name="max_repo_creation" type="number" value="{{.Org.MaxRepoCreation}}">
72+
<input id="max_repo_creation" name="max_repo_creation" type="number" min="-1" value="{{.Org.MaxRepoCreation}}">
7373
<p class="help">{{.locale.Tr "admin.users.max_repo_creation_desc"}}</p>
7474
</div>
7575
{{end}}

templates/repo/create.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
4545
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
46-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" autofocus required>
46+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" autofocus required maxlength="100">
4747
<span class="help">{{.locale.Tr "repo.repo_name_helper"}}</span>
4848
</div>
4949
<div class="inline field">
@@ -61,7 +61,7 @@
6161
</div>
6262
<div class="inline field {{if .Err_Description}}error{{end}}">
6363
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
64-
<textarea id="description" name="description" placeholder="{{.locale.Tr "repo.repo_desc_helper"}}">{{.description}}</textarea>
64+
<textarea id="description" name="description" placeholder="{{.locale.Tr "repo.repo_desc_helper"}}" maxlength="2048">{{.description}}</textarea>
6565
</div>
6666
<div class="inline field">
6767
<label>{{.locale.Tr "repo.template"}}</label>

templates/repo/issue/search.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<input type="hidden" name="project" value="{{$.ProjectID}}">
88
<input type="hidden" name="assignee" value="{{$.AssigneeID}}">
99
<input type="hidden" name="poster" value="{{$.PosterID}}">
10-
<input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}...">
10+
<input name="q" value="{{.Keyword}}" placeholder="{{.locale.Tr "explore.search"}}..." maxlength="255">
1111
{{if .PageIsIssueList}}
1212
<button id="issue-list-quick-goto" class="ui small icon button gt-hidden" data-tooltip-content="{{.locale.Tr "explore.go_to"}}" data-repo-link="{{.RepoLink}}">{{svg "octicon-hash"}}</button>
1313
{{end}}

templates/repo/migrate/codebase.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
8585
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
86-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
86+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
8787
</div>
8888
<div class="inline field">
8989
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -99,7 +99,7 @@
9999
</div>
100100
<div class="inline field {{if .Err_Description}}error{{end}}">
101101
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
102-
<textarea id="description" name="description">{{.description}}</textarea>
102+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
103103
</div>
104104

105105
<div class="inline field">

templates/repo/migrate/git.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757

5858
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
5959
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
60-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
60+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
6161
</div>
6262
<div class="inline field">
6363
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -73,7 +73,7 @@
7373
</div>
7474
<div class="inline field {{if .Err_Description}}error{{end}}">
7575
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
76-
<textarea id="description" name="description">{{.description}}</textarea>
76+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
7777
</div>
7878

7979
<div class="inline field">

templates/repo/migrate/gitbucket.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
101101
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
102-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
102+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
103103
</div>
104104
<div class="inline field">
105105
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -115,7 +115,7 @@
115115
</div>
116116
<div class="inline field {{if .Err_Description}}error{{end}}">
117117
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
118-
<textarea id="description" name="description">{{.description}}</textarea>
118+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
119119
</div>
120120

121121
<div class="inline field">

templates/repo/migrate/gitea.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595

9696
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
9797
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
98-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
98+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
9999
</div>
100100
<div class="inline field">
101101
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -111,7 +111,7 @@
111111
</div>
112112
<div class="inline field {{if .Err_Description}}error{{end}}">
113113
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
114-
<textarea id="description" name="description">{{.description}}</textarea>
114+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
115115
</div>
116116

117117
<div class="inline field">

templates/repo/migrate/github.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
9999
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
100-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
100+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
101101
</div>
102102
<div class="inline field">
103103
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -113,7 +113,7 @@
113113
</div>
114114
<div class="inline field {{if .Err_Description}}error{{end}}">
115115
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
116-
<textarea id="description" name="description">{{.description}}</textarea>
116+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
117117
</div>
118118

119119
<div class="inline field">

templates/repo/migrate/gitlab.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@
9494

9595
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
9696
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
97-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
97+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
9898
</div>
9999
<div class="inline field">
100100
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -110,7 +110,7 @@
110110
</div>
111111
<div class="inline field {{if .Err_Description}}error{{end}}">
112112
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
113-
<textarea id="description" name="description">{{.description}}</textarea>
113+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
114114
</div>
115115

116116
<div class="inline field">

templates/repo/migrate/gogs.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797

9898
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
9999
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
100-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
100+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
101101
</div>
102102
<div class="inline field">
103103
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -113,7 +113,7 @@
113113
</div>
114114
<div class="inline field {{if .Err_Description}}error{{end}}">
115115
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
116-
<textarea id="description" name="description">{{.description}}</textarea>
116+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
117117
</div>
118118

119119
<div class="inline field">

templates/repo/migrate/onedev.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
<div class="inline required field {{if .Err_RepoName}}error{{end}}">
8585
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
86-
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required>
86+
<input id="repo_name" name="repo_name" value="{{.repo_name}}" required maxlength="100">
8787
</div>
8888
<div class="inline field">
8989
<label>{{.locale.Tr "repo.visibility"}}</label>
@@ -99,7 +99,7 @@
9999
</div>
100100
<div class="inline field {{if .Err_Description}}error{{end}}">
101101
<label for="description">{{.locale.Tr "repo.repo_desc"}}</label>
102-
<textarea id="description" name="description">{{.description}}</textarea>
102+
<textarea id="description" name="description" maxlength="2048">{{.description}}</textarea>
103103
</div>
104104

105105
<div class="inline field">

templates/repo/settings/options.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@
826826
</div>
827827
<div class="required field">
828828
<label for="repo_name">{{.locale.Tr "repo.repo_name"}}</label>
829-
<input id="repo_name" name="repo_name" required>
829+
<input id="repo_name" name="repo_name" required maxlength="100">
830830
</div>
831831

832832
<div class="text right actions">

templates/user/settings/applications.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
{{.CsrfTokenHtml}}
4646
<div class="field {{if .Err_Name}}error{{end}}">
4747
<label for="name">{{.locale.Tr "settings.token_name"}}</label>
48-
<input id="name" name="name" value="{{.name}}" autofocus required>
48+
<input id="name" name="name" value="{{.name}}" autofocus required maxlength="255">
4949
</div>
5050
<!--Temporarily disable-->
5151
<details class="gt-hidden ui optional field">

templates/user/settings/applications_oauth2_edit_form.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@
3636
{{.CsrfTokenHtml}}
3737
<div class="field {{if .Err_AppName}}error{{end}}">
3838
<label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label>
39-
<input id="application-name" value="{{.App.Name}}" name="application_name" required>
39+
<input id="application-name" value="{{.App.Name}}" name="application_name" required maxlength="255">
4040
</div>
4141
<div class="field {{if .Err_RedirectURI}}error{{end}}">
4242
<label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label>
43-
<input type="url" name="redirect_uri" value="{{.App.PrimaryRedirectURI}}" id="redirect-uri">
43+
<input type="url" name="redirect_uri" value="{{.App.PrimaryRedirectURI}}" id="redirect-uri" required>
4444
</div>
4545
<div class="field ui checkbox {{if .Err_ConfidentialClient}}error{{end}}">
4646
<label>{{.locale.Tr "settings.oauth2_confidential_client"}}</label>

templates/user/settings/applications_oauth2_list.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
{{.CsrfTokenHtml}}
3232
<div class="field {{if .Err_AppName}}error{{end}}">
3333
<label for="application-name">{{.locale.Tr "settings.oauth2_application_name"}}</label>
34-
<input id="application-name" name="application_name" value="{{.application_name}}" required>
34+
<input id="application-name" name="application_name" value="{{.application_name}}" required maxlength="255">
3535
</div>
3636
<div class="field {{if .Err_RedirectURI}}error{{end}}">
3737
<label for="redirect-uri">{{.locale.Tr "settings.oauth2_redirect_uri"}}</label>

templates/user/settings/keys_ssh.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{{.CsrfTokenHtml}}
1313
<div class="field {{if .Err_Title}}error{{end}}">
1414
<label for="title">{{.locale.Tr "settings.key_name"}}</label>
15-
<input id="ssh-key-title" name="title" value="{{.title}}" autofocus required>
15+
<input id="ssh-key-title" name="title" value="{{.title}}" autofocus required maxlength="50">
1616
</div>
1717
<div class="field {{if .Err_Content}}error{{end}}">
1818
<label for="content">{{.locale.Tr "settings.key_content"}}</label>

templates/user/settings/profile.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212
<span class="text red gt-hidden" id="name-change-prompt"> {{.locale.Tr "settings.change_username_prompt"}}</span>
1313
<span class="text red gt-hidden" id="name-change-redirect-prompt"> {{.locale.Tr "settings.change_username_redirect_prompt"}}</span>
1414
</label>
15-
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}}>
15+
<input id="username" name="name" value="{{.SignedUser.Name}}" data-name="{{.SignedUser.Name}}" autofocus required {{if or (not .SignedUser.IsLocal) .IsReverseProxy}}disabled{{end}} maxlength="40">
1616
{{if or (not .SignedUser.IsLocal) .IsReverseProxy}}
1717
<p class="help text blue">{{$.locale.Tr "settings.password_username_disabled"}}</p>
1818
{{end}}
1919
</div>
2020
<div class="field {{if .Err_FullName}}error{{end}}">
2121
<label for="full_name">{{.locale.Tr "settings.full_name"}}</label>
22-
<input id="full_name" name="full_name" value="{{.SignedUser.FullName}}">
22+
<input id="full_name" name="full_name" value="{{.SignedUser.FullName}}" maxlength="100">
2323
</div>
2424
<div class="field {{if .Err_Email}}error{{end}}">
2525
<label for="email">{{.locale.Tr "email"}}</label>
@@ -33,15 +33,15 @@
3333
</div>
3434
<div class="field {{if .Err_Description}}error{{end}}">
3535
<label for="description">{{$.locale.Tr "user.user_bio"}}</label>
36-
<textarea id="description" name="description" rows="2" placeholder="{{.locale.Tr "settings.biography_placeholder"}}">{{.SignedUser.Description}}</textarea>
36+
<textarea id="description" name="description" rows="2" placeholder="{{.locale.Tr "settings.biography_placeholder"}}" maxlength="255">{{.SignedUser.Description}}</textarea>
3737
</div>
3838
<div class="field {{if .Err_Website}}error{{end}}">
3939
<label for="website">{{.locale.Tr "settings.website"}}</label>
40-
<input id="website" name="website" type="url" value="{{.SignedUser.Website}}">
40+
<input id="website" name="website" type="url" value="{{.SignedUser.Website}}" maxlength="255">
4141
</div>
4242
<div class="field">
4343
<label for="location">{{.locale.Tr "settings.location"}}</label>
44-
<input id="location" name="location" value="{{.SignedUser.Location}}">
44+
<input id="location" name="location" value="{{.SignedUser.Location}}" maxlength="50">
4545
</div>
4646

4747
<div class="ui divider"></div>

0 commit comments

Comments
 (0)