summaryrefslogtreecommitdiff
path: root/internal/api
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2024-04-11 11:45:53 +0200
committerLibravatar GitHub <noreply@github.com>2024-04-11 11:45:53 +0200
commit9fb8a78f91adffd5f4d28df1270e407c25a7a16e (patch)
treed68200744e28d07e75a52bb0c9f6593c86a38a91 /internal/api
parent[performance] massively improved ActivityPub delivery worker efficiency (#2812) (diff)
downloadgotosocial-9fb8a78f91adffd5f4d28df1270e407c25a7a16e.tar.xz
[feature] New user sign-up via web page (#2796)
* [feature] User sign-up form and admin notifs * add chosen + filtered languages to migration * remove stray comment * chosen languages schmosen schmanguages * proper error on local account missing
Diffstat (limited to 'internal/api')
-rw-r--r--internal/api/client/accounts/accountcreate.go63
-rw-r--r--internal/api/client/admin/reportsget_test.go12
-rw-r--r--internal/api/model/admin.go4
-rw-r--r--internal/api/model/notification.go15
4 files changed, 40 insertions, 54 deletions
diff --git a/internal/api/client/accounts/accountcreate.go b/internal/api/client/accounts/accountcreate.go
index 061c66b57..920b6d4d8 100644
--- a/internal/api/client/accounts/accountcreate.go
+++ b/internal/api/client/accounts/accountcreate.go
@@ -25,7 +25,6 @@ import (
"github.com/gin-gonic/gin"
apimodel "github.com/superseriousbusiness/gotosocial/internal/api/model"
apiutil "github.com/superseriousbusiness/gotosocial/internal/api/util"
- "github.com/superseriousbusiness/gotosocial/internal/config"
"github.com/superseriousbusiness/gotosocial/internal/gtserror"
"github.com/superseriousbusiness/gotosocial/internal/oauth"
"github.com/superseriousbusiness/gotosocial/internal/validate"
@@ -67,6 +66,11 @@ import (
// description: not found
// '406':
// description: not acceptable
+// '422':
+// description: >-
+// Unprocessable. Your account creation request cannot be processed
+// because either too many accounts have been created on this instance
+// in the last 24h, or the pending account backlog is full.
// '500':
// description: internal server error
func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
@@ -87,7 +91,7 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
return
}
- if err := validateNormalizeCreateAccount(form); err != nil {
+ if err := validate.CreateAccount(form); err != nil {
apiutil.ErrorHandler(c, gtserror.NewErrorBadRequest(err, err.Error()), m.processor.InstanceGetV1)
return
}
@@ -101,48 +105,29 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
}
form.IP = signUpIP
- ti, errWithCode := m.processor.Account().Create(c.Request.Context(), authed.Token, authed.Application, form)
+ // Create the new account + user.
+ ctx := c.Request.Context()
+ user, errWithCode := m.processor.Account().Create(
+ ctx,
+ authed.Application,
+ form,
+ )
if errWithCode != nil {
apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
return
}
- apiutil.JSON(c, http.StatusOK, ti)
-}
-
-// validateNormalizeCreateAccount checks through all the necessary prerequisites for creating a new account,
-// according to the provided account create request. If the account isn't eligible, an error will be returned.
-// Side effect: normalizes the provided language tag for the user's locale.
-func validateNormalizeCreateAccount(form *apimodel.AccountCreateRequest) error {
- if form == nil {
- return errors.New("form was nil")
- }
-
- if !config.GetAccountsRegistrationOpen() {
- return errors.New("registration is not open for this server")
- }
-
- if err := validate.Username(form.Username); err != nil {
- return err
- }
-
- if err := validate.Email(form.Email); err != nil {
- return err
- }
-
- if err := validate.Password(form.Password); err != nil {
- return err
- }
-
- if !form.Agreement {
- return errors.New("agreement to terms and conditions not given")
- }
-
- locale, err := validate.Language(form.Locale)
- if err != nil {
- return err
+ // Get a token for the new user.
+ ti, errWithCode := m.processor.Account().TokenForNewUser(
+ ctx,
+ authed.Token,
+ authed.Application,
+ user,
+ )
+ if errWithCode != nil {
+ apiutil.ErrorHandler(c, errWithCode, m.processor.InstanceGetV1)
+ return
}
- form.Locale = locale
- return validate.SignUpReason(form.Reason, config.GetAccountsReasonRequired())
+ apiutil.JSON(c, http.StatusOK, ti)
}
diff --git a/internal/api/client/admin/reportsget_test.go b/internal/api/client/admin/reportsget_test.go
index f2b6ff62a..b20921b36 100644
--- a/internal/api/client/admin/reportsget_test.go
+++ b/internal/api/client/admin/reportsget_test.go
@@ -192,7 +192,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"domain": null,
"created_at": "2022-06-04T13:12:00.000Z",
"email": "tortle.dude@example.org",
- "ip": "118.44.18.196",
+ "ip": null,
"ips": [],
"locale": "en",
"invite_request": null,
@@ -249,7 +249,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"domain": null,
"created_at": "2022-05-17T13:10:59.000Z",
"email": "admin@example.org",
- "ip": "89.122.255.1",
+ "ip": null,
"ips": [],
"locale": "en",
"invite_request": null,
@@ -295,7 +295,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"domain": null,
"created_at": "2022-05-17T13:10:59.000Z",
"email": "admin@example.org",
- "ip": "89.122.255.1",
+ "ip": null,
"ips": [],
"locale": "en",
"invite_request": null,
@@ -354,7 +354,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetAll() {
"domain": null,
"created_at": "2022-06-04T13:12:00.000Z",
"email": "tortle.dude@example.org",
- "ip": "118.44.18.196",
+ "ip": null,
"ips": [],
"locale": "en",
"invite_request": null,
@@ -576,7 +576,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetCreatedByAccount() {
"domain": null,
"created_at": "2022-06-04T13:12:00.000Z",
"email": "tortle.dude@example.org",
- "ip": "118.44.18.196",
+ "ip": null,
"ips": [],
"locale": "en",
"invite_request": null,
@@ -798,7 +798,7 @@ func (suite *ReportsGetTestSuite) TestReportsGetTargetAccount() {
"domain": null,
"created_at": "2022-06-04T13:12:00.000Z",
"email": "tortle.dude@example.org",
- "ip": "118.44.18.196",
+ "ip": null,
"ips": [],
"locale": "en",
"invite_request": null,
diff --git a/internal/api/model/admin.go b/internal/api/model/admin.go
index 60036c19f..ca84ffd88 100644
--- a/internal/api/model/admin.go
+++ b/internal/api/model/admin.go
@@ -50,8 +50,8 @@ type AdminAccountInfo struct {
// The locale of the account. (ISO 639 Part 1 two-letter language code)
// example: en
Locale string `json:"locale"`
- // The reason given when requesting an invite.
- // Null if not known / remote account.
+ // The reason given when signing up.
+ // Null if no reason / remote account.
// example: Pleaaaaaaaaaaaaaaase!!
InviteRequest *string `json:"invite_request"`
// The current role of the account.
diff --git a/internal/api/model/notification.go b/internal/api/model/notification.go
index 6f9a31b07..7fccb0a2c 100644
--- a/internal/api/model/notification.go
+++ b/internal/api/model/notification.go
@@ -26,13 +26,14 @@ type Notification struct {
// The id of the notification in the database.
ID string `json:"id"`
// The type of event that resulted in the notification.
- // follow = Someone followed you
- // follow_request = Someone requested to follow you
- // mention = Someone mentioned you in their status
- // reblog = Someone boosted one of your statuses
- // favourite = Someone favourited one of your statuses
- // poll = A poll you have voted in or created has ended
- // status = Someone you enabled notifications for has posted a status
+ // follow = Someone followed you. `account` will be set.
+ // follow_request = Someone requested to follow you. `account` will be set.
+ // mention = Someone mentioned you in their status. `status` will be set. `account` will be set.
+ // reblog = Someone boosted one of your statuses. `status` will be set. `account` will be set.
+ // favourite = Someone favourited one of your statuses. `status` will be set. `account` will be set.
+ // poll = A poll you have voted in or created has ended. `status` will be set. `account` will be set.
+ // status = Someone you enabled notifications for has posted a status. `status` will be set. `account` will be set.
+ // admin.sign_up = Someone has signed up for a new account on the instance. `account` will be set.
Type string `json:"type"`
// The timestamp of the notification (ISO 8601 Datetime)
CreatedAt string `json:"created_at"`