Refactor and migrate more functions out of api into app package (#5063)
Этот коммит содержится в:
коммит произвёл
Harrison Healey
родитель
97558f6a6e
Коммит
0e2b321e6f
34
api/oauth.go
34
api/oauth.go
@@ -250,32 +250,6 @@ func getAuthorizedApps(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
func RevokeAccessToken(token string) *model.AppError {
|
||||
|
||||
session, _ := app.GetSession(token)
|
||||
schan := app.Srv.Store.Session().Remove(token)
|
||||
|
||||
if result := <-app.Srv.Store.OAuth().GetAccessData(token); result.Err != nil {
|
||||
return model.NewLocAppError("RevokeAccessToken", "api.oauth.revoke_access_token.get.app_error", nil, "")
|
||||
}
|
||||
|
||||
tchan := app.Srv.Store.OAuth().RemoveAccessData(token)
|
||||
|
||||
if result := <-tchan; result.Err != nil {
|
||||
return model.NewLocAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_token.app_error", nil, "")
|
||||
}
|
||||
|
||||
if result := <-schan; result.Err != nil {
|
||||
return model.NewLocAppError("RevokeAccessToken", "api.oauth.revoke_access_token.del_session.app_error", nil, "")
|
||||
}
|
||||
|
||||
if session != nil {
|
||||
app.RemoveAllSessionsForUserId(session.UserId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func GetAuthData(code string) *model.AuthData {
|
||||
if result := <-app.Srv.Store.OAuth().GetAuthData(code); result.Err != nil {
|
||||
l4g.Error(utils.T("api.oauth.get_auth_data.find.error"), code)
|
||||
@@ -311,7 +285,11 @@ func completeOAuth(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
action := props["action"]
|
||||
switch action {
|
||||
case model.OAUTH_ACTION_SIGNUP:
|
||||
CreateOAuthUser(c, w, r, service, body, teamId)
|
||||
if user, err := app.CreateOAuthUser(service, body, teamId); err != nil {
|
||||
c.Err = err
|
||||
} else {
|
||||
doLogin(c, w, r, user, "")
|
||||
}
|
||||
if c.Err == nil {
|
||||
http.Redirect(w, r, GetProtocol(r)+"://"+r.Host, http.StatusTemporaryRedirect)
|
||||
}
|
||||
@@ -931,7 +909,7 @@ func deauthorizeOAuthApp(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
accessData := result.Data.([]*model.AccessData)
|
||||
|
||||
for _, a := range accessData {
|
||||
if err := RevokeAccessToken(a.Token); err != nil {
|
||||
if err := app.RevokeAccessToken(a.Token); err != nil {
|
||||
c.Err = err
|
||||
return
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user