1
0
Fork 0
forked from forgejo/forgejo

Improve issue mail content

This commit is contained in:
Unknown 2014-04-02 10:38:30 -04:00
parent b0e7dd6864
commit d9005ee970
7 changed files with 68 additions and 58 deletions

View file

@ -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
}

View file

@ -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(),
}
// 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"`
}
// // 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()
// // 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
}
// 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"