Skip to content

Commit

Permalink
Handle email address not exist (#19089) (#19121)
Browse files Browse the repository at this point in the history
Backport #19089

* Handle email address not exist. (#19089)

* Fix lint about strings.Title

Co-authored-by: KN4CK3R <admin@oldschoolhack.me>
  • Loading branch information
lunny and KN4CK3R authored Mar 19, 2022
1 parent 9bcbbd4 commit 79a5e68
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 28 deletions.
6 changes: 3 additions & 3 deletions modules/repository/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions modules/setting/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 10 additions & 7 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
18 changes: 11 additions & 7 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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")
Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
}
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"reflect"
"runtime"
"strconv"
"strings"

"code.gitea.io/gitea/models"
asymkey_model "code.gitea.io/gitea/models/asymkey"
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions routers/web/admin/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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], ":")
Expand Down Expand Up @@ -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()
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 79a5e68

Please sign in to comment.