forked from forgejo/forgejo
Move binding as subrepo
This commit is contained in:
parent
33f2d33a46
commit
5c2da610a2
18 changed files with 1594 additions and 445 deletions
196
routers/user/home.go
Normal file
196
routers/user/home.go
Normal file
|
@ -0,0 +1,196 @@
|
|||
// 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 (
|
||||
"fmt"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
func Dashboard(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Dashboard"
|
||||
ctx.Data["PageIsUserDashboard"] = true
|
||||
repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Dashboard", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["MyRepos"] = repos
|
||||
|
||||
feeds, err := models.GetFeeds(ctx.User.Id, 0, false)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Dashboard", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Feeds"] = feeds
|
||||
ctx.HTML(200, "user/dashboard")
|
||||
}
|
||||
|
||||
func Profile(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Profile"
|
||||
|
||||
// TODO: Need to check view self or others.
|
||||
user, err := models.GetUserByName(params["username"])
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Owner"] = user
|
||||
|
||||
tab := ctx.Query("tab")
|
||||
ctx.Data["TabName"] = tab
|
||||
|
||||
switch tab {
|
||||
case "activity":
|
||||
feeds, err := models.GetFeeds(user.Id, 0, true)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Feeds"] = feeds
|
||||
default:
|
||||
repos, err := models.GetRepositories(user)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Repos"] = repos
|
||||
}
|
||||
|
||||
ctx.Data["PageIsUserProfile"] = true
|
||||
ctx.HTML(200, "user/profile")
|
||||
}
|
||||
|
||||
func Email2User(ctx *middleware.Context) {
|
||||
u, err := models.GetUserByEmail(ctx.Query("email"))
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "user.Email2User", err)
|
||||
} else {
|
||||
ctx.Handle(500, "user.Email2User(GetUserByEmail)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Redirect("/user/" + u.Name)
|
||||
}
|
||||
|
||||
const (
|
||||
TPL_FEED = `<i class="icon fa fa-%s"></i>
|
||||
<div class="info"><span class="meta">%s</span><br>%s</div>`
|
||||
)
|
||||
|
||||
func Feeds(ctx *middleware.Context, form auth.FeedsForm) {
|
||||
actions, err := models.GetFeeds(form.UserId, form.Page*20, false)
|
||||
if err != nil {
|
||||
ctx.JSON(500, err)
|
||||
}
|
||||
|
||||
feeds := make([]string, len(actions))
|
||||
for i := range actions {
|
||||
feeds[i] = fmt.Sprintf(TPL_FEED, base.ActionIcon(actions[i].OpType),
|
||||
base.TimeSince(actions[i].Created), base.ActionDesc(actions[i]))
|
||||
}
|
||||
ctx.JSON(200, &feeds)
|
||||
}
|
||||
|
||||
func Issues(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Your Issues"
|
||||
ctx.Data["ViewType"] = "all"
|
||||
|
||||
page, _ := base.StrTo(ctx.Query("page")).Int()
|
||||
repoId, _ := base.StrTo(ctx.Query("repoid")).Int64()
|
||||
|
||||
ctx.Data["RepoId"] = repoId
|
||||
|
||||
var posterId int64 = 0
|
||||
if ctx.Query("type") == "created_by" {
|
||||
posterId = ctx.User.Id
|
||||
ctx.Data["ViewType"] = "created_by"
|
||||
}
|
||||
|
||||
// Get all repositories.
|
||||
repos, err := models.GetRepositories(ctx.User)
|
||||
if err != nil {
|
||||
ctx.Handle(200, "user.Issues(get repositories)", err)
|
||||
return
|
||||
}
|
||||
|
||||
showRepos := make([]models.Repository, 0, len(repos))
|
||||
|
||||
isShowClosed := ctx.Query("state") == "closed"
|
||||
var closedIssueCount, createdByCount, allIssueCount int
|
||||
|
||||
// Get all issues.
|
||||
allIssues := make([]models.Issue, 0, 5*len(repos))
|
||||
for i, repo := range repos {
|
||||
issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, isShowClosed, false, "", "")
|
||||
if err != nil {
|
||||
ctx.Handle(200, "user.Issues(get issues)", err)
|
||||
return
|
||||
}
|
||||
|
||||
allIssueCount += repo.NumIssues
|
||||
closedIssueCount += repo.NumClosedIssues
|
||||
|
||||
// Set repository information to issues.
|
||||
for j := range issues {
|
||||
issues[j].Repo = &repos[i]
|
||||
}
|
||||
allIssues = append(allIssues, issues...)
|
||||
|
||||
repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
|
||||
if repos[i].NumOpenIssues > 0 {
|
||||
showRepos = append(showRepos, repos[i])
|
||||
}
|
||||
}
|
||||
|
||||
showIssues := make([]models.Issue, 0, len(allIssues))
|
||||
ctx.Data["IsShowClosed"] = isShowClosed
|
||||
|
||||
// Get posters and filter issues.
|
||||
for i := range allIssues {
|
||||
u, err := models.GetUserById(allIssues[i].PosterId)
|
||||
if err != nil {
|
||||
ctx.Handle(200, "user.Issues(get poster): %v", err)
|
||||
return
|
||||
}
|
||||
allIssues[i].Poster = u
|
||||
if u.Id == ctx.User.Id {
|
||||
createdByCount++
|
||||
}
|
||||
|
||||
if repoId > 0 && repoId != allIssues[i].Repo.Id {
|
||||
continue
|
||||
}
|
||||
|
||||
if isShowClosed == allIssues[i].IsClosed {
|
||||
showIssues = append(showIssues, allIssues[i])
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["Repos"] = showRepos
|
||||
ctx.Data["Issues"] = showIssues
|
||||
ctx.Data["AllIssueCount"] = allIssueCount
|
||||
ctx.Data["ClosedIssueCount"] = closedIssueCount
|
||||
ctx.Data["OpenIssueCount"] = allIssueCount - closedIssueCount
|
||||
ctx.Data["CreatedByCount"] = createdByCount
|
||||
ctx.HTML(200, "issue/user")
|
||||
}
|
||||
|
||||
func Pulls(ctx *middleware.Context) {
|
||||
ctx.HTML(200, "user/pulls")
|
||||
}
|
||||
|
||||
func Stars(ctx *middleware.Context) {
|
||||
ctx.HTML(200, "user/stars")
|
||||
}
|
|
@ -7,12 +7,14 @@ package user
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.google.com/p/goauth2/oauth"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
|
@ -115,3 +117,205 @@ func SocialSignIn(params martini.Params, ctx *middleware.Context) {
|
|||
log.Trace("socialId: %v", oa.Id)
|
||||
ctx.Redirect(next)
|
||||
}
|
||||
|
||||
// ________.__ __ ___ ___ ___.
|
||||
// / _____/|__|/ |_ / | \ __ _\_ |__
|
||||
// / \ ___| \ __\/ ~ \ | \ __ \
|
||||
// \ \_\ \ || | \ Y / | / \_\ \
|
||||
// \______ /__||__| \___|_ /|____/|___ /
|
||||
// \/ \/ \/
|
||||
|
||||
type SocialGithub struct {
|
||||
Token *oauth.Token
|
||||
*oauth.Transport
|
||||
}
|
||||
|
||||
func (s *SocialGithub) Type() int {
|
||||
return models.OT_GITHUB
|
||||
}
|
||||
|
||||
func init() {
|
||||
github := &SocialGithub{}
|
||||
name := "github"
|
||||
config := &oauth.Config{
|
||||
ClientId: "09383403ff2dc16daaa1", //base.OauthService.GitHub.ClientId, // FIXME: panic when set
|
||||
ClientSecret: "0e4aa0c3630df396cdcea01a9d45cacf79925fea", //base.OauthService.GitHub.ClientSecret,
|
||||
RedirectURL: strings.TrimSuffix(base.AppUrl, "/") + "/user/login/" + name, //ctx.Req.URL.RequestURI(),
|
||||
Scope: "https://api.github.com/user",
|
||||
AuthURL: "https://github.com/login/oauth/authorize",
|
||||
TokenURL: "https://github.com/login/oauth/access_token",
|
||||
}
|
||||
github.Transport = &oauth.Transport{
|
||||
Config: config,
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
SocialMap[name] = github
|
||||
}
|
||||
|
||||
func (s *SocialGithub) SetRedirectUrl(url string) {
|
||||
s.Transport.Config.RedirectURL = url
|
||||
}
|
||||
|
||||
func (s *SocialGithub) UserInfo(token *oauth.Token, _ *url.URL) (*BasicUserInfo, error) {
|
||||
transport := &oauth.Transport{
|
||||
Token: token,
|
||||
}
|
||||
var data struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"login"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
var err error
|
||||
r, err := transport.Client().Get(s.Transport.Scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BasicUserInfo{
|
||||
Identity: strconv.Itoa(data.Id),
|
||||
Name: data.Name,
|
||||
Email: data.Email,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ________ .__
|
||||
// / _____/ ____ ____ ____ | | ____
|
||||
// / \ ___ / _ \ / _ \ / ___\| | _/ __ \
|
||||
// \ \_\ ( <_> | <_> ) /_/ > |_\ ___/
|
||||
// \______ /\____/ \____/\___ /|____/\___ >
|
||||
// \/ /_____/ \/
|
||||
|
||||
type SocialGoogle struct {
|
||||
Token *oauth.Token
|
||||
*oauth.Transport
|
||||
}
|
||||
|
||||
func (s *SocialGoogle) Type() int {
|
||||
return models.OT_GOOGLE
|
||||
}
|
||||
|
||||
func init() {
|
||||
google := &SocialGoogle{}
|
||||
name := "google"
|
||||
// get client id and secret from
|
||||
// https://console.developers.google.com/project
|
||||
config := &oauth.Config{
|
||||
ClientId: "849753812404-mpd7ilvlb8c7213qn6bre6p6djjskti9.apps.googleusercontent.com", //base.OauthService.GitHub.ClientId, // FIXME: panic when set
|
||||
ClientSecret: "VukKc4MwaJUSmiyv3D7ANVCa", //base.OauthService.GitHub.ClientSecret,
|
||||
Scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",
|
||||
AuthURL: "https://accounts.google.com/o/oauth2/auth",
|
||||
TokenURL: "https://accounts.google.com/o/oauth2/token",
|
||||
}
|
||||
google.Transport = &oauth.Transport{
|
||||
Config: config,
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
SocialMap[name] = google
|
||||
}
|
||||
|
||||
func (s *SocialGoogle) SetRedirectUrl(url string) {
|
||||
s.Transport.Config.RedirectURL = url
|
||||
}
|
||||
|
||||
func (s *SocialGoogle) UserInfo(token *oauth.Token, _ *url.URL) (*BasicUserInfo, error) {
|
||||
transport := &oauth.Transport{Token: token}
|
||||
var data struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
var err error
|
||||
|
||||
reqUrl := "https://www.googleapis.com/oauth2/v1/userinfo"
|
||||
r, err := transport.Client().Get(reqUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BasicUserInfo{
|
||||
Identity: data.Id,
|
||||
Name: data.Name,
|
||||
Email: data.Email,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ________ ________
|
||||
// \_____ \ \_____ \
|
||||
// / / \ \ / / \ \
|
||||
// / \_/. \/ \_/. \
|
||||
// \_____\ \_/\_____\ \_/
|
||||
// \__> \__>
|
||||
|
||||
type SocialQQ struct {
|
||||
Token *oauth.Token
|
||||
*oauth.Transport
|
||||
reqUrl string
|
||||
}
|
||||
|
||||
func (s *SocialQQ) Type() int {
|
||||
return models.OT_QQ
|
||||
}
|
||||
|
||||
func init() {
|
||||
qq := &SocialQQ{}
|
||||
name := "qq"
|
||||
config := &oauth.Config{
|
||||
ClientId: "801497180", //base.OauthService.GitHub.ClientId, // FIXME: panic when set
|
||||
ClientSecret: "16cd53b8ad2e16a36fc2c8f87d9388f2", //base.OauthService.GitHub.ClientSecret,
|
||||
Scope: "all",
|
||||
AuthURL: "https://open.t.qq.com/cgi-bin/oauth2/authorize",
|
||||
TokenURL: "https://open.t.qq.com/cgi-bin/oauth2/access_token",
|
||||
}
|
||||
qq.reqUrl = "https://open.t.qq.com/api/user/info"
|
||||
qq.Transport = &oauth.Transport{
|
||||
Config: config,
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
SocialMap[name] = qq
|
||||
}
|
||||
|
||||
func (s *SocialQQ) SetRedirectUrl(url string) {
|
||||
s.Transport.Config.RedirectURL = url
|
||||
}
|
||||
|
||||
func (s *SocialQQ) UserInfo(token *oauth.Token, URL *url.URL) (*BasicUserInfo, error) {
|
||||
var data struct {
|
||||
Data struct {
|
||||
Id string `json:"openid"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
} `json:"data"`
|
||||
}
|
||||
var err error
|
||||
// https://open.t.qq.com/api/user/info?
|
||||
//oauth_consumer_key=APP_KEY&
|
||||
//access_token=ACCESSTOKEN&openid=openid
|
||||
//clientip=CLIENTIP&oauth_version=2.a
|
||||
//scope=all
|
||||
var urls = url.Values{
|
||||
"oauth_consumer_key": {s.Transport.Config.ClientId},
|
||||
"access_token": {token.AccessToken},
|
||||
"openid": URL.Query()["openid"],
|
||||
"oauth_version": {"2.a"},
|
||||
"scope": {"all"},
|
||||
}
|
||||
r, err := http.Get(s.reqUrl + "?" + urls.Encode())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BasicUserInfo{
|
||||
Identity: data.Data.Id,
|
||||
Name: data.Data.Name,
|
||||
Email: data.Data.Email,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -1,73 +0,0 @@
|
|||
// 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"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"code.google.com/p/goauth2/oauth"
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
)
|
||||
|
||||
type SocialGithub struct {
|
||||
Token *oauth.Token
|
||||
*oauth.Transport
|
||||
}
|
||||
|
||||
func (s *SocialGithub) Type() int {
|
||||
return models.OT_GITHUB
|
||||
}
|
||||
|
||||
func init() {
|
||||
github := &SocialGithub{}
|
||||
name := "github"
|
||||
config := &oauth.Config{
|
||||
ClientId: "09383403ff2dc16daaa1", //base.OauthService.GitHub.ClientId, // FIXME: panic when set
|
||||
ClientSecret: "0e4aa0c3630df396cdcea01a9d45cacf79925fea", //base.OauthService.GitHub.ClientSecret,
|
||||
RedirectURL: strings.TrimSuffix(base.AppUrl, "/") + "/user/login/" + name, //ctx.Req.URL.RequestURI(),
|
||||
Scope: "https://api.github.com/user",
|
||||
AuthURL: "https://github.com/login/oauth/authorize",
|
||||
TokenURL: "https://github.com/login/oauth/access_token",
|
||||
}
|
||||
github.Transport = &oauth.Transport{
|
||||
Config: config,
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
SocialMap[name] = github
|
||||
}
|
||||
|
||||
func (s *SocialGithub) SetRedirectUrl(url string) {
|
||||
s.Transport.Config.RedirectURL = url
|
||||
}
|
||||
|
||||
func (s *SocialGithub) UserInfo(token *oauth.Token, _ *url.URL) (*BasicUserInfo, error) {
|
||||
transport := &oauth.Transport{
|
||||
Token: token,
|
||||
}
|
||||
var data struct {
|
||||
Id int `json:"id"`
|
||||
Name string `json:"login"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
var err error
|
||||
r, err := transport.Client().Get(s.Transport.Scope)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BasicUserInfo{
|
||||
Identity: strconv.Itoa(data.Id),
|
||||
Name: data.Name,
|
||||
Email: data.Email,
|
||||
}, nil
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
// 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"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"github.com/gogits/gogs/models"
|
||||
|
||||
"code.google.com/p/goauth2/oauth"
|
||||
)
|
||||
|
||||
type SocialGoogle struct {
|
||||
Token *oauth.Token
|
||||
*oauth.Transport
|
||||
}
|
||||
|
||||
func (s *SocialGoogle) Type() int {
|
||||
return models.OT_GOOGLE
|
||||
}
|
||||
|
||||
func init() {
|
||||
google := &SocialGoogle{}
|
||||
name := "google"
|
||||
// get client id and secret from
|
||||
// https://console.developers.google.com/project
|
||||
config := &oauth.Config{
|
||||
ClientId: "849753812404-mpd7ilvlb8c7213qn6bre6p6djjskti9.apps.googleusercontent.com", //base.OauthService.GitHub.ClientId, // FIXME: panic when set
|
||||
ClientSecret: "VukKc4MwaJUSmiyv3D7ANVCa", //base.OauthService.GitHub.ClientSecret,
|
||||
Scope: "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile",
|
||||
AuthURL: "https://accounts.google.com/o/oauth2/auth",
|
||||
TokenURL: "https://accounts.google.com/o/oauth2/token",
|
||||
}
|
||||
google.Transport = &oauth.Transport{
|
||||
Config: config,
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
SocialMap[name] = google
|
||||
}
|
||||
|
||||
func (s *SocialGoogle) SetRedirectUrl(url string) {
|
||||
s.Transport.Config.RedirectURL = url
|
||||
}
|
||||
|
||||
func (s *SocialGoogle) UserInfo(token *oauth.Token, _ *url.URL) (*BasicUserInfo, error) {
|
||||
transport := &oauth.Transport{Token: token}
|
||||
var data struct {
|
||||
Id string `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
var err error
|
||||
|
||||
reqUrl := "https://www.googleapis.com/oauth2/v1/userinfo"
|
||||
r, err := transport.Client().Get(reqUrl)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BasicUserInfo{
|
||||
Identity: data.Id,
|
||||
Name: data.Name,
|
||||
Email: data.Email,
|
||||
}, nil
|
||||
}
|
|
@ -1,83 +0,0 @@
|
|||
// 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.
|
||||
|
||||
// api reference: http://wiki.open.t.qq.com/index.php/OAuth2.0%E9%89%B4%E6%9D%83/Authorization_code%E6%8E%88%E6%9D%83%E6%A1%88%E4%BE%8B
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"github.com/gogits/gogs/models"
|
||||
|
||||
"code.google.com/p/goauth2/oauth"
|
||||
)
|
||||
|
||||
type SocialQQ struct {
|
||||
Token *oauth.Token
|
||||
*oauth.Transport
|
||||
reqUrl string
|
||||
}
|
||||
|
||||
func (s *SocialQQ) Type() int {
|
||||
return models.OT_QQ
|
||||
}
|
||||
|
||||
func init() {
|
||||
qq := &SocialQQ{}
|
||||
name := "qq"
|
||||
config := &oauth.Config{
|
||||
ClientId: "801497180", //base.OauthService.GitHub.ClientId, // FIXME: panic when set
|
||||
ClientSecret: "16cd53b8ad2e16a36fc2c8f87d9388f2", //base.OauthService.GitHub.ClientSecret,
|
||||
Scope: "all",
|
||||
AuthURL: "https://open.t.qq.com/cgi-bin/oauth2/authorize",
|
||||
TokenURL: "https://open.t.qq.com/cgi-bin/oauth2/access_token",
|
||||
}
|
||||
qq.reqUrl = "https://open.t.qq.com/api/user/info"
|
||||
qq.Transport = &oauth.Transport{
|
||||
Config: config,
|
||||
Transport: http.DefaultTransport,
|
||||
}
|
||||
SocialMap[name] = qq
|
||||
}
|
||||
|
||||
func (s *SocialQQ) SetRedirectUrl(url string) {
|
||||
s.Transport.Config.RedirectURL = url
|
||||
}
|
||||
|
||||
func (s *SocialQQ) UserInfo(token *oauth.Token, URL *url.URL) (*BasicUserInfo, error) {
|
||||
var data struct {
|
||||
Data struct {
|
||||
Id string `json:"openid"`
|
||||
Name string `json:"name"`
|
||||
Email string `json:"email"`
|
||||
} `json:"data"`
|
||||
}
|
||||
var err error
|
||||
// https://open.t.qq.com/api/user/info?
|
||||
//oauth_consumer_key=APP_KEY&
|
||||
//access_token=ACCESSTOKEN&openid=openid
|
||||
//clientip=CLIENTIP&oauth_version=2.a
|
||||
//scope=all
|
||||
var urls = url.Values{
|
||||
"oauth_consumer_key": {s.Transport.Config.ClientId},
|
||||
"access_token": {token.AccessToken},
|
||||
"openid": URL.Query()["openid"],
|
||||
"oauth_version": {"2.a"},
|
||||
"scope": {"all"},
|
||||
}
|
||||
r, err := http.Get(s.reqUrl + "?" + urls.Encode())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Body.Close()
|
||||
if err = json.NewDecoder(r.Body).Decode(&data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &BasicUserInfo{
|
||||
Identity: data.Data.Id,
|
||||
Name: data.Data.Name,
|
||||
Email: data.Data.Email,
|
||||
}, nil
|
||||
}
|
|
@ -5,12 +5,9 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/auth"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
|
@ -19,75 +16,6 @@ import (
|
|||
"github.com/gogits/gogs/modules/middleware"
|
||||
)
|
||||
|
||||
func Dashboard(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Dashboard"
|
||||
ctx.Data["PageIsUserDashboard"] = true
|
||||
repos, err := models.GetRepositories(&models.User{Id: ctx.User.Id})
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Dashboard", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["MyRepos"] = repos
|
||||
|
||||
feeds, err := models.GetFeeds(ctx.User.Id, 0, false)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Dashboard", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Feeds"] = feeds
|
||||
ctx.HTML(200, "user/dashboard")
|
||||
}
|
||||
|
||||
func Profile(ctx *middleware.Context, params martini.Params) {
|
||||
ctx.Data["Title"] = "Profile"
|
||||
|
||||
// TODO: Need to check view self or others.
|
||||
user, err := models.GetUserByName(params["username"])
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile", err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Data["Owner"] = user
|
||||
|
||||
tab := ctx.Query("tab")
|
||||
ctx.Data["TabName"] = tab
|
||||
|
||||
switch tab {
|
||||
case "activity":
|
||||
feeds, err := models.GetFeeds(user.Id, 0, true)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Feeds"] = feeds
|
||||
default:
|
||||
repos, err := models.GetRepositories(user)
|
||||
if err != nil {
|
||||
ctx.Handle(500, "user.Profile", err)
|
||||
return
|
||||
}
|
||||
ctx.Data["Repos"] = repos
|
||||
}
|
||||
|
||||
ctx.Data["PageIsUserProfile"] = true
|
||||
ctx.HTML(200, "user/profile")
|
||||
}
|
||||
|
||||
func Email2User(ctx *middleware.Context) {
|
||||
u, err := models.GetUserByEmail(ctx.Query("email"))
|
||||
if err != nil {
|
||||
if err == models.ErrUserNotExist {
|
||||
ctx.Handle(404, "user.Email2User", err)
|
||||
} else {
|
||||
ctx.Handle(500, "user.Email2User(GetUserByEmail)", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Redirect("/user/" + u.Name)
|
||||
}
|
||||
|
||||
func SignIn(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Log In"
|
||||
|
||||
|
@ -329,117 +257,6 @@ func DeletePost(ctx *middleware.Context) {
|
|||
ctx.Redirect("/user/delete")
|
||||
}
|
||||
|
||||
const (
|
||||
TPL_FEED = `<i class="icon fa fa-%s"></i>
|
||||
<div class="info"><span class="meta">%s</span><br>%s</div>`
|
||||
)
|
||||
|
||||
func Feeds(ctx *middleware.Context, form auth.FeedsForm) {
|
||||
actions, err := models.GetFeeds(form.UserId, form.Page*20, false)
|
||||
if err != nil {
|
||||
ctx.JSON(500, err)
|
||||
}
|
||||
|
||||
feeds := make([]string, len(actions))
|
||||
for i := range actions {
|
||||
feeds[i] = fmt.Sprintf(TPL_FEED, base.ActionIcon(actions[i].OpType),
|
||||
base.TimeSince(actions[i].Created), base.ActionDesc(actions[i]))
|
||||
}
|
||||
ctx.JSON(200, &feeds)
|
||||
}
|
||||
|
||||
func Issues(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = "Your Issues"
|
||||
ctx.Data["ViewType"] = "all"
|
||||
|
||||
page, _ := base.StrTo(ctx.Query("page")).Int()
|
||||
repoId, _ := base.StrTo(ctx.Query("repoid")).Int64()
|
||||
|
||||
ctx.Data["RepoId"] = repoId
|
||||
|
||||
var posterId int64 = 0
|
||||
if ctx.Query("type") == "created_by" {
|
||||
posterId = ctx.User.Id
|
||||
ctx.Data["ViewType"] = "created_by"
|
||||
}
|
||||
|
||||
// Get all repositories.
|
||||
repos, err := models.GetRepositories(ctx.User)
|
||||
if err != nil {
|
||||
ctx.Handle(200, "user.Issues(get repositories)", err)
|
||||
return
|
||||
}
|
||||
|
||||
showRepos := make([]models.Repository, 0, len(repos))
|
||||
|
||||
isShowClosed := ctx.Query("state") == "closed"
|
||||
var closedIssueCount, createdByCount, allIssueCount int
|
||||
|
||||
// Get all issues.
|
||||
allIssues := make([]models.Issue, 0, 5*len(repos))
|
||||
for i, repo := range repos {
|
||||
issues, err := models.GetIssues(0, repo.Id, posterId, 0, page, isShowClosed, false, "", "")
|
||||
if err != nil {
|
||||
ctx.Handle(200, "user.Issues(get issues)", err)
|
||||
return
|
||||
}
|
||||
|
||||
allIssueCount += repo.NumIssues
|
||||
closedIssueCount += repo.NumClosedIssues
|
||||
|
||||
// Set repository information to issues.
|
||||
for j := range issues {
|
||||
issues[j].Repo = &repos[i]
|
||||
}
|
||||
allIssues = append(allIssues, issues...)
|
||||
|
||||
repos[i].NumOpenIssues = repo.NumIssues - repo.NumClosedIssues
|
||||
if repos[i].NumOpenIssues > 0 {
|
||||
showRepos = append(showRepos, repos[i])
|
||||
}
|
||||
}
|
||||
|
||||
showIssues := make([]models.Issue, 0, len(allIssues))
|
||||
ctx.Data["IsShowClosed"] = isShowClosed
|
||||
|
||||
// Get posters and filter issues.
|
||||
for i := range allIssues {
|
||||
u, err := models.GetUserById(allIssues[i].PosterId)
|
||||
if err != nil {
|
||||
ctx.Handle(200, "user.Issues(get poster): %v", err)
|
||||
return
|
||||
}
|
||||
allIssues[i].Poster = u
|
||||
if u.Id == ctx.User.Id {
|
||||
createdByCount++
|
||||
}
|
||||
|
||||
if repoId > 0 && repoId != allIssues[i].Repo.Id {
|
||||
continue
|
||||
}
|
||||
|
||||
if isShowClosed == allIssues[i].IsClosed {
|
||||
showIssues = append(showIssues, allIssues[i])
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["Repos"] = showRepos
|
||||
ctx.Data["Issues"] = showIssues
|
||||
ctx.Data["AllIssueCount"] = allIssueCount
|
||||
ctx.Data["ClosedIssueCount"] = closedIssueCount
|
||||
ctx.Data["OpenIssueCount"] = allIssueCount - closedIssueCount
|
||||
ctx.Data["CreatedByCount"] = createdByCount
|
||||
ctx.HTML(200, "issue/user")
|
||||
}
|
||||
|
||||
func Pulls(ctx *middleware.Context) {
|
||||
ctx.HTML(200, "user/pulls")
|
||||
}
|
||||
|
||||
func Stars(ctx *middleware.Context) {
|
||||
ctx.HTML(200, "user/stars")
|
||||
}
|
||||
|
||||
func Activate(ctx *middleware.Context) {
|
||||
code := ctx.Query("code")
|
||||
if len(code) == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue