Handle email address not exist (#19089) (#19121)

Backport #19089

* Handle email address not exist. (#19089)

* Fix lint about strings.Title

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
This commit is contained in:
Lunny Xiao 2022-03-19 19:35:23 +08:00 committed by GitHub
parent 9bcbbd419f
commit 79a5e68816
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 40 additions and 28 deletions

View file

@ -43,7 +43,7 @@ var defaultTransformers = []transformer{
{Name: "PASCAL", Transform: xstrings.ToCamelCase},
{Name: "LOWER", Transform: strings.ToLower},
{Name: "UPPER", Transform: strings.ToUpper},
{Name: "TITLE", Transform: strings.Title},
{Name: "TITLE", Transform: strings.Title}, // nolint
}
func generateExpansion(src string, templateRepo, generateRepo *repo_model.Repository) string {
@ -62,7 +62,7 @@ func generateExpansion(src string, templateRepo, generateRepo *repo_model.Reposi
{Name: "TEMPLATE_SSH_URL", Value: templateRepo.CloneLink().SSH, Transformers: nil},
}
var expansionMap = make(map[string]string)
expansionMap := make(map[string]string)
for _, e := range expansions {
expansionMap[e.Name] = e.Value
for _, tr := range e.Transformers {
@ -159,7 +159,7 @@ func generateRepoCommit(repo, templateRepo, generateRepo *repo_model.Repository,
if err := os.WriteFile(path,
[]byte(generateExpansion(string(content), templateRepo, generateRepo)),
0644); err != nil {
0o644); err != nil {
return err
}
break

View file

@ -15,13 +15,17 @@ import (
"code.gitea.io/gitea/modules/json"
"code.gitea.io/gitea/modules/log"
"golang.org/x/text/cases"
"golang.org/x/text/language"
ini "gopkg.in/ini.v1"
)
var filenameSuffix = ""
var descriptionLock = sync.RWMutex{}
var logDescriptions = make(map[string]*LogDescription)
var (
filenameSuffix = ""
descriptionLock = sync.RWMutex{}
logDescriptions = make(map[string]*LogDescription)
)
// GetLogDescriptions returns a race safe set of descriptions
func GetLogDescriptions() map[string]*LogDescription {
@ -86,7 +90,7 @@ func RemoveSubLogDescription(key, name string) bool {
type defaultLogOptions struct {
levelName string // LogLevel
flags string
filename string //path.Join(LogRootPath, "gitea.log")
filename string // path.Join(LogRootPath, "gitea.log")
bufferLength int64
disableConsole bool
}
@ -243,7 +247,7 @@ func generateNamedLogger(key string, options defaultLogOptions) *LogDescription
Provider: provider,
Config: config,
})
log.Info("%s Log: %s(%s:%s)", strings.Title(key), strings.Title(name), provider, levelName)
log.Info("%s Log: %s(%s:%s)", cases.Title(language.English).String(key), cases.Title(language.English).String(name), provider, levelName)
}
AddLogDescription(key, &description)
@ -327,7 +331,7 @@ func newLogService() {
Provider: provider,
Config: config,
})
log.Info("Gitea Log Mode: %s(%s:%s)", strings.Title(name), strings.Title(provider), levelName)
log.Info("Gitea Log Mode: %s(%s:%s)", cases.Title(language.English).String(name), cases.Title(language.English).String(provider), levelName)
}
AddLogDescription(log.DEFAULT, &description)

View file

@ -30,6 +30,8 @@ import (
"github.com/unknwon/com"
gossh "golang.org/x/crypto/ssh"
"golang.org/x/text/cases"
"golang.org/x/text/language"
ini "gopkg.in/ini.v1"
)
@ -637,7 +639,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
}
UnixSocketPermissionRaw := sec.Key("UNIX_SOCKET_PERMISSION").MustString("666")
UnixSocketPermissionParsed, err := strconv.ParseUint(UnixSocketPermissionRaw, 8, 32)
if err != nil || UnixSocketPermissionParsed > 0777 {
if err != nil || UnixSocketPermissionParsed > 0o777 {
log.Fatal("Failed to parse unixSocketPermission: %s", UnixSocketPermissionRaw)
}
@ -793,16 +795,16 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
SSH.AuthorizedPrincipalsAllow, SSH.AuthorizedPrincipalsEnabled = parseAuthorizedPrincipalsAllow(sec.Key("SSH_AUTHORIZED_PRINCIPALS_ALLOW").Strings(","))
if !SSH.Disabled && !SSH.StartBuiltinServer {
if err := os.MkdirAll(SSH.RootPath, 0700); err != nil {
if err := os.MkdirAll(SSH.RootPath, 0o700); err != nil {
log.Fatal("Failed to create '%s': %v", SSH.RootPath, err)
} else if err = os.MkdirAll(SSH.KeyTestPath, 0644); err != nil {
} else if err = os.MkdirAll(SSH.KeyTestPath, 0o644); err != nil {
log.Fatal("Failed to create '%s': %v", SSH.KeyTestPath, err)
}
if len(trustedUserCaKeys) > 0 && SSH.AuthorizedPrincipalsEnabled {
fname := sec.Key("SSH_TRUSTED_USER_CA_KEYS_FILENAME").MustString(filepath.Join(SSH.RootPath, "gitea-trusted-user-ca-keys.pem"))
if err := os.WriteFile(fname,
[]byte(strings.Join(trustedUserCaKeys, "\n")), 0600); err != nil {
[]byte(strings.Join(trustedUserCaKeys, "\n")), 0o600); err != nil {
log.Fatal("Failed to create '%s': %v", fname, err)
}
}
@ -943,8 +945,9 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
// The following is a purposefully undocumented option. Please do not run Gitea as root. It will only cause future headaches.
// Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
unsafeAllowRunAsRoot := Cfg.Section("").Key("I_AM_BEING_UNSAFE_RUNNING_AS_ROOT").MustBool(false)
RunMode = Cfg.Section("").Key("RUN_MODE").MustString("prod")
IsProd = strings.EqualFold(RunMode, "prod")
RunMode = Cfg.Section("").Key("RUN_MODE").MustString("Prod")
RunMode = cases.Title(language.English).String(strings.ToLower(RunMode))
IsProd = RunMode == "Prod"
// Does not check run user when the install lock is off.
if InstallLock {
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
@ -1074,7 +1077,7 @@ func loadInternalToken(sec *ini.Section) string {
}
switch tempURI.Scheme {
case "file":
fp, err := os.OpenFile(tempURI.RequestURI(), os.O_RDWR, 0600)
fp, err := os.OpenFile(tempURI.RequestURI(), os.O_RDWR, 0o600)
if err != nil {
log.Fatal("Failed to open InternalTokenURI (%s): %v", uri, err)
}

View file

@ -38,6 +38,8 @@ import (
"code.gitea.io/gitea/modules/timeutil"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/gitdiff"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"github.com/editorconfig/editorconfig-core-go/v2"
)
@ -49,7 +51,7 @@ var mailSubjectSplit = regexp.MustCompile(`(?m)^-{3,}[\s]*$`)
func NewFuncMap() []template.FuncMap {
return []template.FuncMap{map[string]interface{}{
"GoVer": func() string {
return strings.Title(runtime.Version())
return cases.Title(language.English).String(runtime.Version())
},
"UseHTTPS": func() bool {
return strings.HasPrefix(setting.AppURL, "https")
@ -285,7 +287,7 @@ func NewFuncMap() []template.FuncMap {
return util.MergeInto(dict, values...)
},
"percentage": func(n int, values ...int) float32 {
var sum = 0
sum := 0
for i := 0; i < len(values); i++ {
sum += values[i]
}
@ -386,7 +388,7 @@ func NewFuncMap() []template.FuncMap {
func NewTextFuncMap() []texttmpl.FuncMap {
return []texttmpl.FuncMap{map[string]interface{}{
"GoVer": func() string {
return strings.Title(runtime.Version())
return cases.Title(language.English).String(runtime.Version())
},
"AppName": func() string {
return setting.AppName
@ -477,7 +479,7 @@ func NewTextFuncMap() []texttmpl.FuncMap {
return dict, nil
},
"percentage": func(n int, values ...int) float32 {
var sum = 0
sum := 0
for i := 0; i < len(values); i++ {
sum += values[i]
}
@ -501,8 +503,10 @@ func NewTextFuncMap() []texttmpl.FuncMap {
}}
}
var widthRe = regexp.MustCompile(`width="[0-9]+?"`)
var heightRe = regexp.MustCompile(`height="[0-9]+?"`)
var (
widthRe = regexp.MustCompile(`width="[0-9]+?"`)
heightRe = regexp.MustCompile(`height="[0-9]+?"`)
)
func parseOthers(defaultSize int, defaultClass string, others ...interface{}) (int, string) {
size := defaultSize
@ -736,7 +740,7 @@ func RenderEmoji(text string) template.HTML {
return template.HTML(renderedText)
}
//ReactionToEmoji renders emoji for use in reactions
// ReactionToEmoji renders emoji for use in reactions
func ReactionToEmoji(reaction string) template.HTML {
val := emoji.FromCode(reaction)
if val != nil {

View file

@ -10,7 +10,6 @@ import (
"reflect"
"runtime"
"strconv"
"strings"
"code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey"
@ -47,6 +46,8 @@ import (
"code.gitea.io/gitea/services/repository/archiver"
"code.gitea.io/gitea/services/task"
"code.gitea.io/gitea/services/webhook"
"golang.org/x/text/cases"
"golang.org/x/text/language"
"gitea.com/go-chi/session"
)
@ -111,7 +112,7 @@ func GlobalInitInstalled(ctx context.Context) {
log.Info("Custom path: %s", setting.CustomPath)
log.Info("Log path: %s", setting.LogRootPath)
log.Info("Configuration file: %s", setting.CustomConf)
log.Info("Run Mode: %s", strings.Title(setting.RunMode))
log.Info("Run Mode: %s", cases.Title(language.English).String(setting.RunMode))
// Setup i18n
translation.InitLocales()

View file

@ -209,7 +209,7 @@ func shadowPassword(provider, cfgItem string) string {
case "redis":
return shadowPasswordKV(cfgItem, ",")
case "mysql":
//root:@tcp(localhost:3306)/macaron?charset=utf8
// root:@tcp(localhost:3306)/macaron?charset=utf8
atIdx := strings.Index(cfgItem, "@")
if atIdx > 0 {
colonIdx := strings.Index(cfgItem[:atIdx], ":")
@ -244,7 +244,7 @@ func Config(ctx *context.Context) {
ctx.Data["OfflineMode"] = setting.OfflineMode
ctx.Data["DisableRouterLog"] = setting.DisableRouterLog
ctx.Data["RunUser"] = setting.RunUser
ctx.Data["RunMode"] = strings.Title(setting.RunMode)
ctx.Data["RunMode"] = setting.RunMode
if version, err := git.LocalVersion(); err == nil {
ctx.Data["GitVersion"] = version.Original()
}

View file

@ -195,7 +195,7 @@ func SignInPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.SignInForm)
u, source, err := auth_service.UserSignIn(form.UserName, form.Password)
if err != nil {
if user_model.IsErrUserNotExist(err) {
if user_model.IsErrUserNotExist(err) || user_model.IsErrEmailAddressNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
} else if user_model.IsErrEmailAlreadyUsed(err) {