aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/user/setting/account.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2022-05-21 15:29:49 +0100
committerGitHub <noreply@github.com>2022-05-21 22:29:49 +0800
commit468387e9ced12367aecc8b863e20e105fbdd0c82 (patch)
treef478efe769bc4946632db3bc07fa8c468aac9eb4 /routers/web/user/setting/account.go
parentbc4764ffc67d240149fba9b0e8d23a68bc95fc6c (diff)
downloadgitea-468387e9ced12367aecc8b863e20e105fbdd0c82.tar.gz
gitea-468387e9ced12367aecc8b863e20e105fbdd0c82.zip
Prevent NPE when cache service is disabled (#19703)
The cache service can be disabled - at which point ctx.Cache will be nil and the use of it will cause an NPE. The main part of this PR is that the cache is used for restricting resending of activation mails and without this we cache we cannot restrict this. Whilst this code could be re-considered to use the db and probably should be, I think we can simply disable this code in the case that the cache is disabled. There are also several bug fixes in the /nodeinfo API endpoint. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers/web/user/setting/account.go')
-rw-r--r--routers/web/user/setting/account.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go
index 92f6c9a183..3e96cc7c85 100644
--- a/routers/web/user/setting/account.go
+++ b/routers/web/user/setting/account.go
@@ -105,7 +105,7 @@ func EmailPost(ctx *context.Context) {
// Send activation Email
if ctx.FormString("_method") == "SENDACTIVATION" {
var address string
- if ctx.Cache.IsExist("MailResendLimit_" + ctx.Doer.LowerName) {
+ if setting.CacheService.Enabled && ctx.Cache.IsExist("MailResendLimit_"+ctx.Doer.LowerName) {
log.Error("Send activation: activation still pending")
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
return
@@ -141,8 +141,10 @@ func EmailPost(ctx *context.Context) {
}
address = email.Email
- if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil {
- log.Error("Set cache(MailResendLimit) fail: %v", err)
+ if setting.CacheService.Enabled {
+ if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil {
+ log.Error("Set cache(MailResendLimit) fail: %v", err)
+ }
}
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", address, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())))
ctx.Redirect(setting.AppSubURL + "/user/settings/account")
@@ -201,8 +203,10 @@ func EmailPost(ctx *context.Context) {
// Send confirmation email
if setting.Service.RegisterEmailConfirm {
mailer.SendActivateEmailMail(ctx.Doer, email)
- if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil {
- log.Error("Set cache(MailResendLimit) fail: %v", err)
+ if setting.CacheService.Enabled {
+ if err := ctx.Cache.Put("MailResendLimit_"+ctx.Doer.LowerName, ctx.Doer.LowerName, 180); err != nil {
+ log.Error("Set cache(MailResendLimit) fail: %v", err)
+ }
}
ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language())))
} else {
@@ -273,7 +277,7 @@ func loadAccountData(ctx *context.Context) {
user_model.EmailAddress
CanBePrimary bool
}
- pendingActivation := ctx.Cache.IsExist("MailResendLimit_" + ctx.Doer.LowerName)
+ pendingActivation := setting.CacheService.Enabled && ctx.Cache.IsExist("MailResendLimit_"+ctx.Doer.LowerName)
emails := make([]*UserEmail, len(emlist))
for i, em := range emlist {
var email UserEmail