mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
[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
This commit is contained in:
@@ -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,7 +105,25 @@ 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
|
||||
}
|
||||
|
||||
// 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
|
||||
@@ -109,40 +131,3 @@ func (m *Module) AccountCreatePOSTHandler(c *gin.Context) {
|
||||
|
||||
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
|
||||
}
|
||||
form.Locale = locale
|
||||
|
||||
return validate.SignUpReason(form.Reason, config.GetAccountsReasonRequired())
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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.
|
||||
|
@@ -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"`
|
||||
|
Reference in New Issue
Block a user