summaryrefslogtreecommitdiff
path: root/internal/processing/user
diff options
context:
space:
mode:
Diffstat (limited to 'internal/processing/user')
-rw-r--r--internal/processing/user/email.go (renamed from internal/processing/user/emailconfirm.go)7
-rw-r--r--internal/processing/user/email_test.go (renamed from internal/processing/user/emailconfirm_test.go)6
-rw-r--r--internal/processing/user/password.go (renamed from internal/processing/user/changepassword.go)3
-rw-r--r--internal/processing/user/password_test.go (renamed from internal/processing/user/changepassword_test.go)6
-rw-r--r--internal/processing/user/user.go19
5 files changed, 15 insertions, 26 deletions
diff --git a/internal/processing/user/emailconfirm.go b/internal/processing/user/email.go
index 3bc889024..349e27f47 100644
--- a/internal/processing/user/emailconfirm.go
+++ b/internal/processing/user/email.go
@@ -35,7 +35,8 @@ import (
var oneWeek = 168 * time.Hour
-func (p *processor) SendConfirmEmail(ctx context.Context, user *gtsmodel.User, username string) error {
+// EmailSendConfirmation sends an email address confirmation request email to the given user.
+func (p *Processor) EmailSendConfirmation(ctx context.Context, user *gtsmodel.User, username string) error {
if user.UnconfirmedEmail == "" || user.UnconfirmedEmail == user.Email {
// user has already confirmed this email address, so there's nothing to do
return nil
@@ -84,7 +85,9 @@ func (p *processor) SendConfirmEmail(ctx context.Context, user *gtsmodel.User, u
return nil
}
-func (p *processor) ConfirmEmail(ctx context.Context, token string) (*gtsmodel.User, gtserror.WithCode) {
+// EmailConfirm processes an email confirmation request, usually initiated as a result of clicking on a link
+// in a 'confirm your email address' type email.
+func (p *Processor) EmailConfirm(ctx context.Context, token string) (*gtsmodel.User, gtserror.WithCode) {
if token == "" {
return nil, gtserror.NewErrorNotFound(errors.New("no token provided"))
}
diff --git a/internal/processing/user/emailconfirm_test.go b/internal/processing/user/email_test.go
index a13a130d0..f66b7987c 100644
--- a/internal/processing/user/emailconfirm_test.go
+++ b/internal/processing/user/email_test.go
@@ -41,7 +41,7 @@ func (suite *EmailConfirmTestSuite) TestSendConfirmEmail() {
user.ConfirmationSentAt = time.Time{}
user.ConfirmationToken = ""
- err := suite.user.SendConfirmEmail(context.Background(), user, "the_mighty_zork")
+ err := suite.user.EmailSendConfirmation(context.Background(), user, "the_mighty_zork")
suite.NoError(err)
// zork should have an email now
@@ -78,7 +78,7 @@ func (suite *EmailConfirmTestSuite) TestConfirmEmail() {
suite.NoError(err)
// confirm with the token set above
- updatedUser, errWithCode := suite.user.ConfirmEmail(ctx, "1d1aa44b-afa4-49c8-ac4b-eceb61715cc6")
+ updatedUser, errWithCode := suite.user.EmailConfirm(ctx, "1d1aa44b-afa4-49c8-ac4b-eceb61715cc6")
suite.NoError(errWithCode)
// email should now be confirmed and token cleared
@@ -106,7 +106,7 @@ func (suite *EmailConfirmTestSuite) TestConfirmEmailOldToken() {
suite.NoError(err)
// confirm with the token set above
- updatedUser, errWithCode := suite.user.ConfirmEmail(ctx, "1d1aa44b-afa4-49c8-ac4b-eceb61715cc6")
+ updatedUser, errWithCode := suite.user.EmailConfirm(ctx, "1d1aa44b-afa4-49c8-ac4b-eceb61715cc6")
suite.Nil(updatedUser)
suite.EqualError(errWithCode, "ConfirmEmail: confirmation token expired")
}
diff --git a/internal/processing/user/changepassword.go b/internal/processing/user/password.go
index 03b8c4525..3475e005e 100644
--- a/internal/processing/user/changepassword.go
+++ b/internal/processing/user/password.go
@@ -27,7 +27,8 @@ import (
"golang.org/x/crypto/bcrypt"
)
-func (p *processor) ChangePassword(ctx context.Context, user *gtsmodel.User, oldPassword string, newPassword string) gtserror.WithCode {
+// PasswordChange processes a password change request for the given user.
+func (p *Processor) PasswordChange(ctx context.Context, user *gtsmodel.User, oldPassword string, newPassword string) gtserror.WithCode {
if err := bcrypt.CompareHashAndPassword([]byte(user.EncryptedPassword), []byte(oldPassword)); err != nil {
return gtserror.NewErrorUnauthorized(err, "old password was incorrect")
}
diff --git a/internal/processing/user/changepassword_test.go b/internal/processing/user/password_test.go
index 74676b323..a02581b5b 100644
--- a/internal/processing/user/changepassword_test.go
+++ b/internal/processing/user/password_test.go
@@ -35,7 +35,7 @@ type ChangePasswordTestSuite struct {
func (suite *ChangePasswordTestSuite) TestChangePasswordOK() {
user := suite.testUsers["local_account_1"]
- errWithCode := suite.user.ChangePassword(context.Background(), user, "password", "verygoodnewpassword")
+ errWithCode := suite.user.PasswordChange(context.Background(), user, "password", "verygoodnewpassword")
suite.NoError(errWithCode)
err := bcrypt.CompareHashAndPassword([]byte(user.EncryptedPassword), []byte("verygoodnewpassword"))
@@ -54,7 +54,7 @@ func (suite *ChangePasswordTestSuite) TestChangePasswordOK() {
func (suite *ChangePasswordTestSuite) TestChangePasswordIncorrectOld() {
user := suite.testUsers["local_account_1"]
- errWithCode := suite.user.ChangePassword(context.Background(), user, "ooooopsydoooopsy", "verygoodnewpassword")
+ errWithCode := suite.user.PasswordChange(context.Background(), user, "ooooopsydoooopsy", "verygoodnewpassword")
suite.EqualError(errWithCode, "crypto/bcrypt: hashedPassword is not the hash of the given password")
suite.Equal(http.StatusUnauthorized, errWithCode.Code())
suite.Equal("Unauthorized: old password was incorrect", errWithCode.Safe())
@@ -72,7 +72,7 @@ func (suite *ChangePasswordTestSuite) TestChangePasswordIncorrectOld() {
func (suite *ChangePasswordTestSuite) TestChangePasswordWeakNew() {
user := suite.testUsers["local_account_1"]
- errWithCode := suite.user.ChangePassword(context.Background(), user, "password", "1234")
+ errWithCode := suite.user.PasswordChange(context.Background(), user, "password", "1234")
suite.EqualError(errWithCode, "password is only 11% strength, try including more special characters, using lowercase letters, using uppercase letters or using a longer password")
suite.Equal(http.StatusBadRequest, errWithCode.Code())
suite.Equal("Bad Request: password is only 11% strength, try including more special characters, using lowercase letters, using uppercase letters or using a longer password", errWithCode.Safe())
diff --git a/internal/processing/user/user.go b/internal/processing/user/user.go
index 5ce8cd803..fce628d0c 100644
--- a/internal/processing/user/user.go
+++ b/internal/processing/user/user.go
@@ -19,33 +19,18 @@
package user
import (
- "context"
-
"github.com/superseriousbusiness/gotosocial/internal/db"
"github.com/superseriousbusiness/gotosocial/internal/email"
- "github.com/superseriousbusiness/gotosocial/internal/gtserror"
- "github.com/superseriousbusiness/gotosocial/internal/gtsmodel"
)
-// Processor wraps a bunch of functions for processing user-level actions.
-type Processor interface {
- // ChangePassword changes the specified user's password from old => new,
- // or returns an error if the new password is too weak, or the old password is incorrect.
- ChangePassword(ctx context.Context, user *gtsmodel.User, oldPassword string, newPassword string) gtserror.WithCode
- // SendConfirmEmail sends a 'confirm-your-email-address' type email to a user.
- SendConfirmEmail(ctx context.Context, user *gtsmodel.User, username string) error
- // ConfirmEmail confirms an email address using the given token.
- ConfirmEmail(ctx context.Context, token string) (*gtsmodel.User, gtserror.WithCode)
-}
-
-type processor struct {
+type Processor struct {
emailSender email.Sender
db db.DB
}
// New returns a new user processor
func New(db db.DB, emailSender email.Sender) Processor {
- return &processor{
+ return Processor{
emailSender: emailSender,
db: db,
}