diff options
author | Unknown <joe2010xtmf@163.com> | 2014-04-03 16:33:27 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-04-03 16:33:27 -0400 |
commit | e9c4156c874ceeecc81fdf7fe00ff2f582110ecd (patch) | |
tree | 091d17fbfa89444ab16c97d4c4b8da361a1c6ad8 /routers | |
parent | 79a610592ea7c2e93ab2f91190af1782c4aa8f8d (diff) | |
download | gitea-e9c4156c874ceeecc81fdf7fe00ff2f582110ecd.tar.gz gitea-e9c4156c874ceeecc81fdf7fe00ff2f582110ecd.zip |
Add: rename user
Diffstat (limited to 'routers')
-rw-r--r-- | routers/repo/repo.go | 2 | ||||
-rw-r--r-- | routers/user/setting.go | 23 |
2 files changed, 18 insertions, 7 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a55647a314..ae51c55139 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -291,7 +291,7 @@ func SettingPost(ctx *middleware.Context) { ctx.RenderWithErr("Repository name has been taken in your repositories.", "repo/setting", nil) return } else if err = models.ChangeRepositoryName(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name, newRepoName); err != nil { - ctx.Handle(404, "repo.SettingPost(update)", err) + ctx.Handle(404, "repo.SettingPost(change repository name)", err) return } log.Trace("%s Repository name changed: %s/%s -> %s", ctx.Req.RequestURI, ctx.User.Name, ctx.Repo.Repository.Name, newRepoName) diff --git a/routers/user/setting.go b/routers/user/setting.go index 75adf2b81d..4b6d88a362 100644 --- a/routers/user/setting.go +++ b/routers/user/setting.go @@ -23,15 +23,27 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { user := ctx.User ctx.Data["Owner"] = user - if ctx.Req.Method == "GET" { + if ctx.Req.Method == "GET" || ctx.HasError() { ctx.HTML(200, "user/setting") return } - // below is for POST requests - if hasErr, ok := ctx.Data["HasError"]; ok && hasErr.(bool) { - ctx.HTML(200, "user/setting") - return + // Check if user name has been changed. + if user.Name != form.UserName { + isExist, err := models.IsUserExist(form.UserName) + if err != nil { + ctx.Handle(404, "user.Setting(update: check existence)", err) + return + } else if isExist { + ctx.RenderWithErr("User name has been taken.", "user/setting", &form) + return + } else if err = models.ChangeUserName(user, form.UserName); err != nil { + ctx.Handle(404, "user.Setting(change user name)", err) + return + } + log.Trace("%s User name changed: %s -> %s", ctx.Req.RequestURI, user.Name, form.UserName) + + user.Name = form.UserName } user.Email = form.Email @@ -46,7 +58,6 @@ func Setting(ctx *middleware.Context, form auth.UpdateProfileForm) { ctx.Data["IsSuccess"] = true ctx.HTML(200, "user/setting") - log.Trace("%s User setting updated: %s", ctx.Req.RequestURI, ctx.User.LowerName) } |