drop oauth2 feature support

This commit is contained in:
Unknwon 2015-09-17 16:11:44 -04:00
parent 562e47f31c
commit 3fb1b6a608
23 changed files with 17 additions and 811 deletions

View file

@ -114,8 +114,7 @@ func updateSystemStatus() {
type AdminOperation int
const (
CLEAN_UNBIND_OAUTH AdminOperation = iota + 1
CLEAN_INACTIVATE_USER
CLEAN_INACTIVATE_USER AdminOperation = iota + 1
CLEAN_REPO_ARCHIVES
GIT_GC_REPOS
SYNC_SSH_AUTHORIZED_KEY
@ -134,9 +133,6 @@ func Dashboard(ctx *middleware.Context) {
var success string
switch AdminOperation(op) {
case CLEAN_UNBIND_OAUTH:
success = ctx.Tr("admin.dashboard.clean_unbind_oauth_success")
err = models.CleanUnbindOauth()
case CLEAN_INACTIVATE_USER:
success = ctx.Tr("admin.dashboard.delete_inactivate_accounts_success")
err = models.DeleteInactivateUsers()
@ -197,12 +193,6 @@ func Config(ctx *middleware.Context) {
ctx.Data["Mailer"] = setting.MailService
}
ctx.Data["OauthEnabled"] = false
if setting.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["Oauther"] = setting.OauthService
}
ctx.Data["CacheAdapter"] = setting.CacheAdapter
ctx.Data["CacheInternal"] = setting.CacheInternal
ctx.Data["CacheConn"] = setting.CacheConn

View file

@ -39,11 +39,6 @@ func Home(ctx *middleware.Context) {
return
}
if setting.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["OauthService"] = setting.OauthService
}
ctx.Data["PageIsHome"] = true
ctx.HTML(200, HOME)
}

View file

@ -25,7 +25,6 @@ import (
"github.com/gogits/gogs/modules/mailer"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/social"
"github.com/gogits/gogs/modules/user"
)
@ -46,7 +45,6 @@ func checkRunMode() {
func NewServices() {
setting.NewServices()
mailer.NewContext()
social.NewOauthService()
}
// GlobalInit is for global configuration reload-able.

View file

@ -6,7 +6,6 @@ package user
import (
"net/url"
"strings"
"github.com/macaron-contrib/captcha"
@ -30,17 +29,6 @@ const (
func SignIn(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_in")
if _, ok := ctx.Session.Get("socialId").(int64); ok {
ctx.Data["IsSocialLogin"] = true
ctx.HTML(200, SIGNIN)
return
}
if setting.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["OauthService"] = setting.OauthService
}
// Check auto-login.
isSucceed, err := middleware.AutoSignIn(ctx)
if err != nil {
@ -63,14 +51,6 @@ func SignIn(ctx *middleware.Context) {
func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
ctx.Data["Title"] = ctx.Tr("sign_in")
sid, isOauth := ctx.Session.Get("socialId").(int64)
if isOauth {
ctx.Data["IsSocialLogin"] = true
} else if setting.OauthService != nil {
ctx.Data["OauthEnabled"] = true
ctx.Data["OauthService"] = setting.OauthService
}
if ctx.HasError() {
ctx.HTML(200, SIGNIN)
return
@ -93,20 +73,6 @@ func SignInPost(ctx *middleware.Context, form auth.SignInForm) {
setting.CookieRememberName, u.Name, days, setting.AppSubUrl)
}
// Bind with social account.
if isOauth {
if err = models.BindUserOauth2(u.Id, sid); err != nil {
if err == models.ErrOauth2RecordNotExist {
ctx.Handle(404, "GetOauth2ById", err)
} else {
ctx.Handle(500, "GetOauth2ById", err)
}
return
}
ctx.Session.Delete("socialId")
log.Trace("%s OAuth binded: %s -> %d", ctx.Req.RequestURI, form.UserName, sid)
}
ctx.Session.Set("uid", u.Id)
ctx.Session.Set("uname", u.Name)
if redirectTo, _ := url.QueryUnescape(ctx.GetCookie("redirect_to")); len(redirectTo) > 0 {
@ -129,25 +95,6 @@ func SignOut(ctx *middleware.Context) {
ctx.Redirect(setting.AppSubUrl + "/")
}
func oauthSignUp(ctx *middleware.Context, sid int64) {
ctx.Data["Title"] = ctx.Tr("sign_up")
if _, err := models.GetOauth2ById(sid); err != nil {
if err == models.ErrOauth2RecordNotExist {
ctx.Handle(404, "GetOauth2ById", err)
} else {
ctx.Handle(500, "GetOauth2ById", err)
}
return
}
ctx.Data["IsSocialLogin"] = true
ctx.Data["uname"] = strings.Replace(ctx.Session.Get("socialName").(string), " ", "", -1)
ctx.Data["email"] = ctx.Session.Get("socialEmail")
log.Trace("social ID: %v", ctx.Session.Get("socialId"))
ctx.HTML(200, SIGNUP)
}
func SignUp(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("sign_up")
@ -159,11 +106,6 @@ func SignUp(ctx *middleware.Context) {
return
}
if sid, ok := ctx.Session.Get("socialId").(int64); ok {
oauthSignUp(ctx, sid)
return
}
ctx.HTML(200, SIGNUP)
}
@ -177,12 +119,6 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
return
}
isOauth := false
sid, isOauth := ctx.Session.Get("socialId").(int64)
if isOauth {
ctx.Data["IsSocialLogin"] = true
}
if ctx.HasError() {
ctx.HTML(200, SIGNUP)
return
@ -204,7 +140,7 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
IsActive: !setting.Service.RegisterEmailConfirm || isOauth,
IsActive: !setting.Service.RegisterEmailConfirm,
}
if err := models.CreateUser(u); err != nil {
switch {
@ -237,18 +173,8 @@ func SignUpPost(ctx *middleware.Context, cpt *captcha.Captcha, form auth.Registe
}
}
// Bind social account.
if isOauth {
if err := models.BindUserOauth2(u.Id, sid); err != nil {
ctx.Handle(500, "BindUserOauth2", err)
return
}
ctx.Session.Delete("socialId")
log.Trace("%s OAuth binded: %s -> %d", ctx.Req.RequestURI, form.UserName, sid)
}
// Send confirmation e-mail, no need for social account.
if !isOauth && setting.Service.RegisterEmailConfirm && u.Id > 1 {
if setting.Service.RegisterEmailConfirm && u.Id > 1 {
mailer.SendActivateAccountMail(ctx.Context, u)
ctx.Data["IsSendRegisterMail"] = true
ctx.Data["Email"] = u.Email

View file

@ -324,31 +324,6 @@ func DeleteSSHKey(ctx *middleware.Context) {
})
}
func SettingsSocial(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsSocial"] = true
// Unbind social account.
remove, _ := com.StrTo(ctx.Query("remove")).Int64()
if remove > 0 {
if err := models.DeleteOauth2ById(remove); err != nil {
ctx.Handle(500, "DeleteOauth2ById", err)
return
}
ctx.Flash.Success(ctx.Tr("settings.unbind_success"))
ctx.Redirect(setting.AppSubUrl + "/user/settings/social")
return
}
socials, err := models.GetOauthByUserId(ctx.User.Id)
if err != nil {
ctx.Handle(500, "GetOauthByUserId", err)
return
}
ctx.Data["Socials"] = socials
ctx.HTML(200, SETTINGS_SOCIAL)
}
func SettingsApplications(ctx *middleware.Context) {
ctx.Data["Title"] = ctx.Tr("settings")
ctx.Data["PageIsSettingsApplications"] = true

View file

@ -1,95 +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"
"errors"
"fmt"
// "strings"
"time"
"github.com/macaron-contrib/oauth2"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/middleware"
"github.com/gogits/gogs/modules/setting"
"github.com/gogits/gogs/modules/social"
)
func SocialSignIn(ctx *middleware.Context) {
if setting.OauthService == nil {
ctx.Handle(404, "OAuth2 service not enabled", nil)
return
}
next := setting.AppSubUrl + "/user/login"
info := ctx.Session.Get(oauth2.KEY_TOKEN)
if info == nil {
ctx.Redirect(next)
return
}
name := ctx.Params(":name")
connect, ok := social.SocialMap[name]
if !ok {
ctx.Handle(404, "social login not enabled", errors.New(name))
return
}
tk := new(oauth2.Token)
if err := json.Unmarshal(info.([]byte), tk); err != nil {
ctx.Handle(500, "Unmarshal token", err)
return
}
ui, err := connect.UserInfo(tk, ctx.Req.URL)
if err != nil {
ctx.Handle(500, fmt.Sprintf("UserInfo(%s)", name), err)
return
}
if len(ui.Identity) == 0 {
ctx.Handle(404, "no identity is presented", errors.New(name))
return
}
log.Info("social.SocialSignIn(social login): %s", ui)
oa, err := models.GetOauth2(ui.Identity)
switch err {
case nil:
ctx.Session.Set("uid", oa.User.Id)
ctx.Session.Set("uname", oa.User.Name)
case models.ErrOauth2RecordNotExist:
raw, _ := json.Marshal(tk)
oa = &models.Oauth2{
Uid: -1,
Type: connect.Type(),
Identity: ui.Identity,
Token: string(raw),
}
log.Trace("social.SocialSignIn(oa): %v", oa)
if err = models.AddOauth2(oa); err != nil {
log.Error(4, "social.SocialSignIn(add oauth2): %v", err) // 501
return
}
case models.ErrOauth2NotAssociated:
next = setting.AppSubUrl + "/user/sign_up"
default:
ctx.Handle(500, "social.SocialSignIn(GetOauth2)", err)
return
}
oa.Updated = time.Now()
if err = models.UpdateOauth2(oa); err != nil {
log.Error(4, "UpdateOauth2: %v", err)
}
ctx.Session.Set("socialId", oa.Id)
ctx.Session.Set("socialName", ui.Name)
ctx.Session.Set("socialEmail", ui.Email)
log.Trace("social.SocialSignIn(social ID): %v", oa.Id)
ctx.Redirect(next)
}