@@ -41,7 +41,7 @@ const (
41
41
tplSettingsOrganization base.TplName = "user/settings/organization"
42
42
tplSettingsRepositories base.TplName = "user/settings/repos"
43
43
tplSettingsDelete base.TplName = "user/settings/delete"
44
- tplSecurity base.TplName = "user/security"
44
+ tplSettingsSecurity base.TplName = "user/settings /security"
45
45
)
46
46
47
47
// Settings render user's profile page
@@ -191,22 +191,35 @@ func SettingsDeleteAvatar(ctx *context.Context) {
191
191
ctx .Redirect (setting .AppSubURL + "/user/settings/avatar" )
192
192
}
193
193
194
- // SettingsPassword render change user's password page
195
- func SettingsPassword (ctx * context.Context ) {
194
+ // SettingsSecurity render change user's password page and 2FA
195
+ func SettingsSecurity (ctx * context.Context ) {
196
196
ctx .Data ["Title" ] = ctx .Tr ("settings" )
197
- ctx .Data ["PageIsSettingsPassword " ] = true
197
+ ctx .Data ["PageIsSettingsSecurity " ] = true
198
198
ctx .Data ["Email" ] = ctx .User .Email
199
- ctx .HTML (200 , tplSettingsPassword )
199
+
200
+ enrolled := true
201
+ _ , err := models .GetTwoFactorByUID (ctx .User .ID )
202
+ if err != nil {
203
+ if models .IsErrTwoFactorNotEnrolled (err ) {
204
+ enrolled = false
205
+ } else {
206
+ ctx .Handle (500 , "SettingsTwoFactor" , err )
207
+ return
208
+ }
209
+ }
210
+
211
+ ctx .Data ["TwofaEnrolled" ] = enrolled
212
+ ctx .HTML (200 , tplSettingsSecurity )
200
213
}
201
214
202
- // SettingsPasswordPost response for change user's password
203
- func SettingsPasswordPost (ctx * context.Context , form auth.ChangePasswordForm ) {
215
+ // SettingsSecurityPost response for change user's password
216
+ func SettingsSecurityPost (ctx * context.Context , form auth.ChangePasswordForm ) {
204
217
ctx .Data ["Title" ] = ctx .Tr ("settings" )
205
- ctx .Data ["PageIsSettingsPassword " ] = true
218
+ ctx .Data ["PageIsSettingsSecurity " ] = true
206
219
ctx .Data ["PageIsSettingsDelete" ] = true
207
220
208
221
if ctx .HasError () {
209
- ctx .HTML (200 , tplSettingsPassword )
222
+ ctx .HTML (200 , tplSettingsSecurity )
210
223
return
211
224
}
212
225
@@ -230,7 +243,7 @@ func SettingsPasswordPost(ctx *context.Context, form auth.ChangePasswordForm) {
230
243
ctx .Flash .Success (ctx .Tr ("settings.change_password_success" ))
231
244
}
232
245
233
- ctx .Redirect (setting .AppSubURL + "/user/settings/password " )
246
+ ctx .Redirect (setting .AppSubURL + "/user/settings/security " )
234
247
}
235
248
236
249
// SettingsEmails render user's emails page
@@ -509,30 +522,10 @@ func SettingsDeleteApplication(ctx *context.Context) {
509
522
})
510
523
}
511
524
512
- // SettingsTwoFactor renders the 2FA page.
513
- func SettingsTwoFactor (ctx * context.Context ) {
514
- ctx .Data ["Title" ] = ctx .Tr ("settings" )
515
- ctx .Data ["PageIsSettingsTwofa" ] = true
516
-
517
- enrolled := true
518
- _ , err := models .GetTwoFactorByUID (ctx .User .ID )
519
- if err != nil {
520
- if models .IsErrTwoFactorNotEnrolled (err ) {
521
- enrolled = false
522
- } else {
523
- ctx .Handle (500 , "SettingsTwoFactor" , err )
524
- return
525
- }
526
- }
527
-
528
- ctx .Data ["TwofaEnrolled" ] = enrolled
529
- ctx .HTML (200 , tplSettingsTwofa )
530
- }
531
-
532
525
// SettingsTwoFactorRegenerateScratch regenerates the user's 2FA scratch code.
533
526
func SettingsTwoFactorRegenerateScratch (ctx * context.Context ) {
534
527
ctx .Data ["Title" ] = ctx .Tr ("settings" )
535
- ctx .Data ["PageIsSettingsTwofa " ] = true
528
+ ctx .Data ["PageIsSettingsSecurity " ] = true
536
529
537
530
t , err := models .GetTwoFactorByUID (ctx .User .ID )
538
531
if err != nil {
@@ -551,13 +544,13 @@ func SettingsTwoFactorRegenerateScratch(ctx *context.Context) {
551
544
}
552
545
553
546
ctx .Flash .Success (ctx .Tr ("settings.twofa_scratch_token_regenerated" , t .ScratchToken ))
554
- ctx .Redirect (setting .AppSubURL + "/user/settings/two_factor " )
547
+ ctx .Redirect (setting .AppSubURL + "/user/settings/security " )
555
548
}
556
549
557
550
// SettingsTwoFactorDisable deletes the user's 2FA settings.
558
551
func SettingsTwoFactorDisable (ctx * context.Context ) {
559
552
ctx .Data ["Title" ] = ctx .Tr ("settings" )
560
- ctx .Data ["PageIsSettingsTwofa " ] = true
553
+ ctx .Data ["PageIsSettingsSecurity " ] = true
561
554
562
555
t , err := models .GetTwoFactorByUID (ctx .User .ID )
563
556
if err != nil {
@@ -571,7 +564,7 @@ func SettingsTwoFactorDisable(ctx *context.Context) {
571
564
}
572
565
573
566
ctx .Flash .Success (ctx .Tr ("settings.twofa_disabled" ))
574
- ctx .Redirect (setting .AppSubURL + "/user/settings/two_factor " )
567
+ ctx .Redirect (setting .AppSubURL + "/user/settings/security " )
575
568
}
576
569
577
570
func twofaGenerateSecretAndQr (ctx * context.Context ) bool {
@@ -615,7 +608,7 @@ func twofaGenerateSecretAndQr(ctx *context.Context) bool {
615
608
// SettingsTwoFactorEnroll shows the page where the user can enroll into 2FA.
616
609
func SettingsTwoFactorEnroll (ctx * context.Context ) {
617
610
ctx .Data ["Title" ] = ctx .Tr ("settings" )
618
- ctx .Data ["PageIsSettingsTwofa " ] = true
611
+ ctx .Data ["PageIsSettingsSecurity " ] = true
619
612
620
613
t , err := models .GetTwoFactorByUID (ctx .User .ID )
621
614
if t != nil {
@@ -638,7 +631,7 @@ func SettingsTwoFactorEnroll(ctx *context.Context) {
638
631
// SettingsTwoFactorEnrollPost handles enrolling the user into 2FA.
639
632
func SettingsTwoFactorEnrollPost (ctx * context.Context , form auth.TwoFactorAuthForm ) {
640
633
ctx .Data ["Title" ] = ctx .Tr ("settings" )
641
- ctx .Data ["PageIsSettingsTwofa " ] = true
634
+ ctx .Data ["PageIsSettingsSecurity " ] = true
642
635
643
636
t , err := models .GetTwoFactorByUID (ctx .User .ID )
644
637
if t != nil {
@@ -691,7 +684,7 @@ func SettingsTwoFactorEnrollPost(ctx *context.Context, form auth.TwoFactorAuthFo
691
684
ctx .Session .Delete ("twofaSecret" )
692
685
ctx .Session .Delete ("twofaUri" )
693
686
ctx .Flash .Success (ctx .Tr ("settings.twofa_enrolled" , t .ScratchToken ))
694
- ctx .Redirect (setting .AppSubURL + "/user/settings/two_factor " )
687
+ ctx .Redirect (setting .AppSubURL + "/user/settings/security " )
695
688
}
696
689
697
690
// SettingsAccountLinks render the account links settings page
0 commit comments