From b0e7dd6864717841dd218af93dd8bd30d198128d Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 1 Apr 2014 21:19:19 -0400 Subject: Update README --- gogs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index bbd65421..a81f3ab5 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.2.0.0330 Alpha" +const APP_VER = "0.2.0.0401 Alpha" func init() { base.AppVer = APP_VER -- cgit v1.2.3 From d9005ee970270bca97e81d59edca4722752d160d Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 2 Apr 2014 10:38:30 -0400 Subject: Improve issue mail content --- gogs.go | 2 +- models/repo.go | 1 + modules/mailer/mail.go | 11 +++++--- public/css/gogs.css | 4 +-- routers/repo/issue.go | 14 +++++++--- routers/user/user.go | 76 +++++++++++++++++++++++++------------------------- web.go | 24 ++++++++-------- 7 files changed, 71 insertions(+), 61 deletions(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index a81f3ab5..88f53eeb 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.2.0.0401 Alpha" +const APP_VER = "0.2.0.0402 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/repo.go b/models/repo.go index 0c808f18..8dd7da23 100644 --- a/models/repo.go +++ b/models/repo.go @@ -513,6 +513,7 @@ func NotifyWatchers(act *Action) error { continue } + act.Id = 0 act.UserId = watches[i].UserId if _, err = orm.InsertOne(act); err != nil { return errors.New("repo.NotifyWatchers(create action): " + err.Error()) diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index d0decbe0..b99fc8fd 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -92,8 +92,8 @@ func SendActiveMail(r *middleware.Render, user *models.User) { } // SendNotifyMail sends mail notification of all watchers. -func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content string) error { - watches, err := models.GetWatches(repoId) +func SendNotifyMail(user, owner *models.User, repo *models.Repository, issue *models.Issue) error { + watches, err := models.GetWatches(repo.Id) if err != nil { return errors.New("mail.NotifyWatchers(get watches): " + err.Error()) } @@ -101,7 +101,7 @@ func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content s tos := make([]string, 0, len(watches)) for i := range watches { uid := watches[i].UserId - if userId == uid { + if user.Id == uid { continue } u, err := models.GetUserById(uid) @@ -115,7 +115,10 @@ func SendNotifyMail(userId, repoId int64, userName, repoName, subject, content s return nil } - msg := NewMailMessageFrom(tos, userName, subject, content) + subject := fmt.Sprintf("[%s] %s", repo.Name, issue.Name) + content := fmt.Sprintf("%s
-
View it on Gogs.", + issue.Content, base.AppUrl, owner.Name, repo.Name, issue.Index) + msg := NewMailMessageFrom(tos, user.Name, subject, content) msg.Info = fmt.Sprintf("Subject: %s, send notify emails", subject) SendAsync(&msg) return nil diff --git a/public/css/gogs.css b/public/css/gogs.css index a018a9db..6bed7711 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -1235,9 +1235,9 @@ html, body { /* admin dashboard/configuration */ .admin-dl-horizontal > dt { - width: 320px; + width: 220px; } .admin-dl-horizontal > dd { - margin-left: 340px; + margin-left: 240px; } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index 6cad2c25..41b2c7e9 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -31,7 +31,8 @@ func Issues(ctx *middleware.Context) { ctx.Data["IssueCreatedCount"] = 0 var posterId int64 = 0 - if ctx.Query("type") == "created_by" { + isCreatedBy := ctx.Query("type") == "created_by" + if isCreatedBy { if !ctx.IsSigned { ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI)) ctx.Redirect("/user/login/", 302) @@ -53,6 +54,7 @@ func Issues(ctx *middleware.Context) { } var createdByCount int + showIssues := make([]models.Issue, 0, len(issues)) // Get posters. for i := range issues { u, err := models.GetUserById(issues[i].PosterId) @@ -60,13 +62,17 @@ func Issues(ctx *middleware.Context) { ctx.Handle(200, "issue.Issues(get poster): %v", err) return } - issues[i].Poster = u + if isCreatedBy && u.Id != posterId { + continue + } if u.Id == posterId { createdByCount++ } + issues[i].Poster = u + showIssues = append(showIssues, issues[i]) } - ctx.Data["Issues"] = issues + ctx.Data["Issues"] = showIssues ctx.Data["IssueCount"] = ctx.Repo.Repository.NumIssues ctx.Data["OpenCount"] = ctx.Repo.Repository.NumIssues - ctx.Repo.Repository.NumClosedIssues ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues @@ -107,7 +113,7 @@ func CreateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat // Mail watchers. if base.Service.NotifyMail { - if err = mailer.SendNotifyMail(ctx.User.Id, ctx.Repo.Repository.Id, ctx.User.Name, ctx.Repo.Repository.Name, issue.Name, issue.Content); err != nil { + if err = mailer.SendNotifyMail(ctx.User, ctx.Repo.Owner, ctx.Repo.Repository, issue); err != nil { ctx.Handle(200, "issue.CreateIssue", err) return } diff --git a/routers/user/user.go b/routers/user/user.go index 5890983b..c008a05c 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -5,14 +5,14 @@ package user import ( - "encoding/json" + // "encoding/json" "fmt" "net/url" "strings" - "code.google.com/p/goauth2/oauth" + // "code.google.com/p/goauth2/oauth" "github.com/go-martini/martini" - "github.com/martini-contrib/oauth2" + // "github.com/martini-contrib/oauth2" "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" @@ -78,41 +78,41 @@ func Profile(ctx *middleware.Context, params martini.Params) { } // github && google && ... -func SocialSignIn(tokens oauth2.Tokens) { - transport := &oauth.Transport{} - transport.Token = &oauth.Token{ - AccessToken: tokens.Access(), - RefreshToken: tokens.Refresh(), - Expiry: tokens.ExpiryTime(), - Extra: tokens.ExtraData(), - } - - // Github API refer: https://developer.github.com/v3/users/ - // FIXME: need to judge url - type GithubUser struct { - Id int `json:"id"` - Name string `json:"login"` - Email string `json:"email"` - } - - // Make the request. - scope := "https://api.github.com/user" - r, err := transport.Client().Get(scope) - if err != nil { - log.Error("connect with github error: %s", err) - // FIXME: handle error page - return - } - defer r.Body.Close() - - user := &GithubUser{} - err = json.NewDecoder(r.Body).Decode(user) - if err != nil { - log.Error("Get: %s", err) - } - log.Info("login: %s", user.Name) - // FIXME: login here, user email to check auth, if not registe, then generate a uniq username -} +// func SocialSignIn(tokens oauth2.Tokens) { +// transport := &oauth.Transport{} +// transport.Token = &oauth.Token{ +// AccessToken: tokens.Access(), +// RefreshToken: tokens.Refresh(), +// Expiry: tokens.ExpiryTime(), +// Extra: tokens.ExtraData(), +// } + +// // Github API refer: https://developer.github.com/v3/users/ +// // FIXME: need to judge url +// type GithubUser struct { +// Id int `json:"id"` +// Name string `json:"login"` +// Email string `json:"email"` +// } + +// // Make the request. +// scope := "https://api.github.com/user" +// r, err := transport.Client().Get(scope) +// if err != nil { +// log.Error("connect with github error: %s", err) +// // FIXME: handle error page +// return +// } +// defer r.Body.Close() + +// user := &GithubUser{} +// err = json.NewDecoder(r.Body).Decode(user) +// if err != nil { +// log.Error("Get: %s", err) +// } +// log.Info("login: %s", user.Name) +// // FIXME: login here, user email to check auth, if not registe, then generate a uniq username +// } func SignIn(ctx *middleware.Context, form auth.LogInForm) { ctx.Data["Title"] = "Log In" diff --git a/web.go b/web.go index 48d80b4f..ececd6c2 100644 --- a/web.go +++ b/web.go @@ -11,8 +11,8 @@ import ( "github.com/codegangsta/cli" "github.com/go-martini/martini" - "github.com/martini-contrib/oauth2" - "github.com/martini-contrib/sessions" + // "github.com/martini-contrib/oauth2" + // "github.com/martini-contrib/sessions" "github.com/gogits/binding" @@ -60,15 +60,15 @@ func runWeb(*cli.Context) { // Middlewares. m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}})) - scope := "https://api.github.com/user" - oauth2.PathCallback = "/oauth2callback" - m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123")))) - m.Use(oauth2.Github(&oauth2.Options{ - ClientId: "09383403ff2dc16daaa1", - ClientSecret: "5f6e7101d30b77952aab22b75eadae17551ea6b5", - RedirectURL: base.AppUrl + oauth2.PathCallback, - Scopes: []string{scope}, - })) + // scope := "https://api.github.com/user" + // oauth2.PathCallback = "/oauth2callback" + // m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123")))) + // m.Use(oauth2.Github(&oauth2.Options{ + // ClientId: "09383403ff2dc16daaa1", + // ClientSecret: "5f6e7101d30b77952aab22b75eadae17551ea6b5", + // RedirectURL: base.AppUrl + oauth2.PathCallback, + // Scopes: []string{scope}, + // })) m.Use(middleware.InitContext()) @@ -92,7 +92,7 @@ func runWeb(*cli.Context) { m.Get("/avatar/:hash", avt.ServeHTTP) m.Group("/user", func(r martini.Router) { - r.Any("/login/github", user.SocialSignIn) + // r.Any("/login/github", user.SocialSignIn) r.Any("/login", binding.BindIgnErr(auth.LogInForm{}), user.SignIn) r.Any("/sign_up", binding.BindIgnErr(auth.RegisterForm{}), user.SignUp) }, reqSignOut) -- cgit v1.2.3 From e9c4156c874ceeecc81fdf7fe00ff2f582110ecd Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 3 Apr 2014 16:33:27 -0400 Subject: Add: rename user --- gogs.go | 2 +- models/repo.go | 5 ++--- models/user.go | 49 +++++++++++++++++++++++++++++++++++++++++++++ modules/auth/user.go | 2 ++ routers/repo/repo.go | 2 +- routers/user/setting.go | 23 +++++++++++++++------ templates/user/setting.tmpl | 17 +++++++++++----- 7 files changed, 84 insertions(+), 16 deletions(-) (limited to 'gogs.go') diff --git a/gogs.go b/gogs.go index 88f53eeb..034e131b 100644 --- a/gogs.go +++ b/gogs.go @@ -19,7 +19,7 @@ import ( // Test that go1.2 tag above is included in builds. main.go refers to this definition. const go12tag = true -const APP_VER = "0.2.0.0402 Alpha" +const APP_VER = "0.2.0.0403 Alpha" func init() { base.AppVer = APP_VER diff --git a/models/repo.go b/models/repo.go index 11e23ecd..56f28909 100644 --- a/models/repo.go +++ b/models/repo.go @@ -372,9 +372,8 @@ func RepoPath(userName, repoName string) string { // ChangeRepositoryName changes all corresponding setting from old repository name to new one. func ChangeRepositoryName(userName, oldRepoName, newRepoName string) (err error) { // Update accesses. - accesses := make([]Access, 0, 5) - err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}) - if err != nil { + accesses := make([]Access, 0, 10) + if err = orm.Find(&accesses, &Access{RepoName: strings.ToLower(userName + "/" + oldRepoName)}); err != nil { return err } for i := range accesses { diff --git a/models/user.go b/models/user.go index 4908552f..c5e46b48 100644 --- a/models/user.go +++ b/models/user.go @@ -203,8 +203,52 @@ func VerifyUserActiveCode(code string) (user *User) { return nil } +// ChangeUserName changes all corresponding setting from old user name to new one. +func ChangeUserName(user *User, newUserName string) (err error) { + newUserName = strings.ToLower(newUserName) + + // Update accesses of user. + accesses := make([]Access, 0, 10) + if err = orm.Find(&accesses, &Access{UserName: user.LowerName}); err != nil { + return err + } + for i := range accesses { + accesses[i].UserName = newUserName + if strings.HasPrefix(accesses[i].RepoName, user.LowerName+"/") { + accesses[i].RepoName = strings.Replace(accesses[i].RepoName, user.LowerName, newUserName, 1) + if err = UpdateAccess(&accesses[i]); err != nil { + return err + } + } + } + + repos, err := GetRepositories(user) + if err != nil { + return err + } + for i := range repos { + accesses = make([]Access, 0, 10) + // Update accesses of user repository. + if err = orm.Find(&accesses, &Access{RepoName: user.LowerName + "/" + repos[i].LowerName}); err != nil { + return err + } + + for j := range accesses { + accesses[j].RepoName = newUserName + "/" + repos[i].LowerName + if err = UpdateAccess(&accesses[j]); err != nil { + return err + } + } + } + + // Change user directory name. + return os.Rename(UserPath(user.LowerName), UserPath(newUserName)) +} + // UpdateUser updates user's information. func UpdateUser(user *User) (err error) { + user.LowerName = strings.ToLower(user.Name) + if len(user.Location) > 255 { user.Location = user.Location[:255] } @@ -233,6 +277,11 @@ func DeleteUser(user *User) error { return err } + // Delete all accesses. + if _, err = orm.Delete(&Access{UserName: user.LowerName}); err != nil { + return err + } + // Delete all SSH keys. keys := make([]PublicKey, 0, 10) if err = orm.Find(&keys, &PublicKey{OwnerId: user.Id}); err != nil { diff --git a/modules/auth/user.go b/modules/auth/user.go index 2d3c29fd..015059f7 100644 --- a/modules/auth/user.go +++ b/modules/auth/user.go @@ -75,6 +75,7 @@ type FeedsForm struct { } type UpdateProfileForm struct { + UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"` Email string `form:"email" binding:"Required;Email;MaxSize(50)"` Website string `form:"website" binding:"MaxSize(50)"` Location string `form:"location" binding:"MaxSize(50)"` @@ -83,6 +84,7 @@ type UpdateProfileForm struct { func (f *UpdateProfileForm) Name(field string) string { names := map[string]string{ + "UserName": "Username", "Email": "E-mail address", "Website": "Website", "Location": "Location", diff --git a/routers/repo/repo.go b/routers/repo/repo.go index a55647a3..ae51c551 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 75adf2b8..4b6d88a3 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) } diff --git a/templates/user/setting.tmpl b/templates/user/setting.tmpl index 283a8df8..f44218cd 100644 --- a/templates/user/setting.tmpl +++ b/templates/user/setting.tmpl @@ -10,30 +10,37 @@ {{if .IsSuccess}}

Your profile has been successfully updated.

{{else if .HasError}}

{{.ErrorMsg}}

{{end}}

Your Email will be public and used for Account related notifications and any web based operations made via the web.

- +
- + +
+
+ +
+ +
+
- +
- +
- +
-- cgit v1.2.3