|
|
@ -5,14 +5,14 @@ |
|
|
|
package user |
|
|
|
package user |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
// "encoding/json"
|
|
|
|
"fmt" |
|
|
|
"fmt" |
|
|
|
"net/url" |
|
|
|
"net/url" |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
"code.google.com/p/goauth2/oauth" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// "code.google.com/p/goauth2/oauth"
|
|
|
|
"github.com/go-martini/martini" |
|
|
|
"github.com/go-martini/martini" |
|
|
|
"github.com/martini-contrib/oauth2" |
|
|
|
// "github.com/martini-contrib/oauth2"
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/models" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
|
"github.com/gogits/gogs/modules/auth" |
|
|
@ -78,41 +78,41 @@ func Profile(ctx *middleware.Context, params martini.Params) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// github && google && ...
|
|
|
|
// github && google && ...
|
|
|
|
func SocialSignIn(tokens oauth2.Tokens) { |
|
|
|
// func SocialSignIn(tokens oauth2.Tokens) {
|
|
|
|
transport := &oauth.Transport{} |
|
|
|
// transport := &oauth.Transport{}
|
|
|
|
transport.Token = &oauth.Token{ |
|
|
|
// transport.Token = &oauth.Token{
|
|
|
|
AccessToken: tokens.Access(), |
|
|
|
// AccessToken: tokens.Access(),
|
|
|
|
RefreshToken: tokens.Refresh(), |
|
|
|
// RefreshToken: tokens.Refresh(),
|
|
|
|
Expiry: tokens.ExpiryTime(), |
|
|
|
// Expiry: tokens.ExpiryTime(),
|
|
|
|
Extra: tokens.ExtraData(), |
|
|
|
// Extra: tokens.ExtraData(),
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Github API refer: https://developer.github.com/v3/users/
|
|
|
|
// // Github API refer: https://developer.github.com/v3/users/
|
|
|
|
// FIXME: need to judge url
|
|
|
|
// // FIXME: need to judge url
|
|
|
|
type GithubUser struct { |
|
|
|
// type GithubUser struct {
|
|
|
|
Id int `json:"id"` |
|
|
|
// Id int `json:"id"`
|
|
|
|
Name string `json:"login"` |
|
|
|
// Name string `json:"login"`
|
|
|
|
Email string `json:"email"` |
|
|
|
// Email string `json:"email"`
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
// Make the request.
|
|
|
|
// // Make the request.
|
|
|
|
scope := "https://api.github.com/user" |
|
|
|
// scope := "https://api.github.com/user"
|
|
|
|
r, err := transport.Client().Get(scope) |
|
|
|
// r, err := transport.Client().Get(scope)
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
log.Error("connect with github error: %s", err) |
|
|
|
// log.Error("connect with github error: %s", err)
|
|
|
|
// FIXME: handle error page
|
|
|
|
// // FIXME: handle error page
|
|
|
|
return |
|
|
|
// return
|
|
|
|
} |
|
|
|
// }
|
|
|
|
defer r.Body.Close() |
|
|
|
// defer r.Body.Close()
|
|
|
|
|
|
|
|
|
|
|
|
user := &GithubUser{} |
|
|
|
// user := &GithubUser{}
|
|
|
|
err = json.NewDecoder(r.Body).Decode(user) |
|
|
|
// err = json.NewDecoder(r.Body).Decode(user)
|
|
|
|
if err != nil { |
|
|
|
// if err != nil {
|
|
|
|
log.Error("Get: %s", err) |
|
|
|
// log.Error("Get: %s", err)
|
|
|
|
} |
|
|
|
// }
|
|
|
|
log.Info("login: %s", user.Name) |
|
|
|
// log.Info("login: %s", user.Name)
|
|
|
|
// FIXME: login here, user email to check auth, if not registe, then generate a uniq username
|
|
|
|
// // FIXME: login here, user email to check auth, if not registe, then generate a uniq username
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
func SignIn(ctx *middleware.Context, form auth.LogInForm) { |
|
|
|
func SignIn(ctx *middleware.Context, form auth.LogInForm) { |
|
|
|
ctx.Data["Title"] = "Log In" |
|
|
|
ctx.Data["Title"] = "Log In" |
|
|
|