+11
-5
@@ -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,15 +62,19 @@ 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["OpenCount"] = ctx.Repo.Repository.NumOpenIssues
|
||||
ctx.Data["ClosedCount"] = ctx.Repo.Repository.NumClosedIssues
|
||||
ctx.Data["IssueCreatedCount"] = createdByCount
|
||||
ctx.Data["IsShowClosed"] = ctx.Query("state") == "closed"
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package repo
|
||||
|
||||
import (
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
func Releases(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Releases"
|
||||
ctx.Data["IsRepoToolbarReleases"] = true
|
||||
tags, err := models.GetTags(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "repo.Releases(GetTags)", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Releases"] = tags
|
||||
ctx.HTML(200, "release/list")
|
||||
}
|
||||
+30
-4
@@ -5,6 +5,7 @@
|
||||
package repo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -278,19 +279,44 @@ func SettingPost(ctx *middleware.Context) {
|
||||
|
||||
switch ctx.Query("action") {
|
||||
case "update":
|
||||
isNameChanged := false
|
||||
newRepoName := ctx.Query("name")
|
||||
// Check if repository name has been changed.
|
||||
if ctx.Repo.Repository.Name != newRepoName {
|
||||
isExist, err := models.IsRepositoryExist(ctx.Repo.Owner, newRepoName)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "repo.SettingPost(update: check existence)", err)
|
||||
return
|
||||
} else if isExist {
|
||||
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(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)
|
||||
|
||||
isNameChanged = true
|
||||
ctx.Repo.Repository.Name = newRepoName
|
||||
}
|
||||
|
||||
ctx.Repo.Repository.Description = ctx.Query("desc")
|
||||
ctx.Repo.Repository.Website = ctx.Query("site")
|
||||
if err := models.UpdateRepository(ctx.Repo.Repository); err != nil {
|
||||
ctx.Handle(404, "repo.SettingPost(update)", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["IsSuccess"] = true
|
||||
ctx.HTML(200, "repo/setting")
|
||||
log.Trace("%s Repository updated: %s/%s", ctx.Req.RequestURI, ctx.User.LowerName, ctx.Repo.Repository.LowerName)
|
||||
if isNameChanged {
|
||||
ctx.Redirect(fmt.Sprintf("/%s/%s/settings", ctx.Repo.Owner.Name, ctx.Repo.Repository.Name))
|
||||
} else {
|
||||
ctx.HTML(200, "repo/setting")
|
||||
}
|
||||
log.Trace("%s Repository updated: %s/%s", ctx.Req.RequestURI, ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
|
||||
case "delete":
|
||||
if len(ctx.Repo.Repository.Name) == 0 || ctx.Repo.Repository.Name != ctx.Query("repository") {
|
||||
ctx.Data["ErrorMsg"] = "Please make sure you entered repository name is correct."
|
||||
ctx.HTML(200, "repo/setting")
|
||||
ctx.RenderWithErr("Please make sure you entered repository name is correct.", "repo/setting", nil)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+17
-6
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"code.google.com/p/goauth2/oauth"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
"github.com/gogits/gogs/modules/oauth2"
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
@@ -5,14 +5,11 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"code.google.com/p/goauth2/oauth"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
"github.com/martini-contrib/oauth2"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
@@ -77,43 +74,6 @@ func Profile(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.HTML(200, "user/profile")
|
||||
}
|
||||
|
||||
// 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 SignIn(ctx *middleware.Context, form auth.LogInForm) {
|
||||
ctx.Data["Title"] = "Log In"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user