From 7d7fcf8038b038ea02e9ad4990870067e2bb5c76 Mon Sep 17 00:00:00 2001 From: tsmethurst Date: Tue, 12 Oct 2021 15:35:02 +0200 Subject: [PATCH] add user to processor --- internal/processing/processor.go | 7 +++++++ internal/processing/user.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 internal/processing/user.go diff --git a/internal/processing/processor.go b/internal/processing/processor.go index 5732ad092..8b60ee81b 100644 --- a/internal/processing/processor.go +++ b/internal/processing/processor.go @@ -39,6 +39,7 @@ import ( mediaProcessor "github.com/superseriousbusiness/gotosocial/internal/processing/media" "github.com/superseriousbusiness/gotosocial/internal/processing/status" "github.com/superseriousbusiness/gotosocial/internal/processing/streaming" + "github.com/superseriousbusiness/gotosocial/internal/processing/user" "github.com/superseriousbusiness/gotosocial/internal/stream" "github.com/superseriousbusiness/gotosocial/internal/timeline" "github.com/superseriousbusiness/gotosocial/internal/typeutils" @@ -173,6 +174,9 @@ type Processor interface { // OpenStreamForAccount opens a new stream for the given account, with the given stream type. OpenStreamForAccount(ctx context.Context, account *gtsmodel.Account, streamType string) (*stream.Stream, gtserror.WithCode) + // UserChangePassword changes the password for the given user, with the given form. + UserChangePassword(ctx context.Context, authed *oauth.Auth, form *apimodel.PasswordChangeRequest) gtserror.WithCode + /* FEDERATION API-FACING PROCESSING FUNCTIONS These functions are intended to be called when the federating client needs an immediate (ie., synchronous) reply @@ -247,6 +251,7 @@ type processor struct { statusProcessor status.Processor streamingProcessor streaming.Processor mediaProcessor mediaProcessor.Processor + userProcessor user.Processor } // NewProcessor returns a new Processor that uses the given federator @@ -259,6 +264,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f accountProcessor := account.New(db, tc, mediaHandler, oauthServer, fromClientAPI, federator, config) adminProcessor := admin.New(db, tc, mediaHandler, fromClientAPI, config) mediaProcessor := mediaProcessor.New(db, tc, mediaHandler, storage, config) + userProcessor := user.New(db, tc, config, fromClientAPI) return &processor{ fromClientAPI: fromClientAPI, @@ -279,6 +285,7 @@ func NewProcessor(config *config.Config, tc typeutils.TypeConverter, federator f statusProcessor: statusProcessor, streamingProcessor: streamingProcessor, mediaProcessor: mediaProcessor, + userProcessor: userProcessor, } } diff --git a/internal/processing/user.go b/internal/processing/user.go new file mode 100644 index 000000000..a5fca53dd --- /dev/null +++ b/internal/processing/user.go @@ -0,0 +1,31 @@ +/* + GoToSocial + Copyright (C) 2021 GoToSocial Authors admin@gotosocial.org + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . +*/ + +package processing + +import ( + "context" + + apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model" + "github.com/superseriousbusiness/gotosocial/internal/gtserror" + "github.com/superseriousbusiness/gotosocial/internal/oauth" +) + +func (p *processor) UserChangePassword(ctx context.Context, authed *oauth.Auth, form *apimodel.PasswordChangeRequest) gtserror.WithCode { + return p.userProcessor.ChangePassword(ctx, authed.User, form.OldPassword, form.NewPassword) +}