UserController
struct UserController : APIRouteCollection
The collection of /api/v3/user/* route endpoints and handler functions related to a user’s own data.
UserController is only for methods that modify the user’s own data. See UsersController for methods that interact with other users.
-
An array of words used to generate random phrases.
Declaration
Swift
static let words: [String] -
Required. Registers routes to the incoming router.
Declaration
Swift
func registerRoutes(_ app: Application) throws
-
createHandler(_:Asynchronous) POST /api/v3/user/createCreates a new
Useraccount. Does not log the new user in. Route is open access.A
CreatedUserDatastructure is returned on success, containing the new user’s ID, username and a generated recovery key.Note
The
CreatedUserData.recoveryKeyis a random phrase used to recover an account in the case of a forgotten password. While it can be stored by a client, that essentially defeats its purpose (presumably the password would also already be stored). The intended client use is that it is displayed to the user upon successful creation, and the user is encouraged to take a screenshot or write it down before proceeding.Throws
400 error if the username is an invalid format. 409 errpr if the username is not available.
Declaration
Swift
func createHandler(_ req: Request) async throws -> ResponseParameters
requestBodyReturn Value
CreatedUserDatacontaining the newly created user’s ID, username, and a recovery key string.
-
verifyHandler(_:Asynchronous) POST /api/v3/user/verifyChanges a
User.accessLevelfrom.unverifiedto.verifiedon successful submission of a registration code. User must be logged in.NOTE: previously it was possible to create an account and NOT provide a Registration Code, creating an account with an access level of .unverified. We now require a registration code to create an account and all accounts are therefore already verified at creation time, meaning this method is not currently useful.
Throws
400 error if the user is already verified or the registration code is not a valid one. 409 error if the registration code has already been allocated to another user.Declaration
Swift
func verifyHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyReturn Value
HTTP status 200 on success.
-
addHandler(_:Asynchronous) POST /api/v3/user/addAdds a new
Usersub-account to the current user’s primary account. You can create a new sub account while logged in on a sub account, but the new account is an sub of the primary account–there’s no nesting or tree structure.This method does not log in the newly created user. Users are limited to
Settings.shared.maxAlternateAccountsalts, which is 6 by default.An
AddedUserDatastructure is returned on success, containing the new user’s ID and username.Note
API v3 supports a sub-account model, rather than the creation of individual accounts for multiple identities in prior versions. A sub-account inherits its parent user’s
.accessLevel,.recoveryKeyand.verificationvalues. EachUserrequires use of its own Bearer Authentication token and must log in individually; multiple accounts can all be simultaneously logged in.Throws
400 error if the username is an invalid format or password is not at least 6 characters. 403 error if the user is banned or currently quarantined. 409 errpr if the username is not available.
Declaration
Swift
func addHandler(_ req: Request) async throws -> ResponseParameters
requestBodyReturn Value
AddedUserDatacontaining the newly created user’s ID and username. -
GET /api/v3/user/whoamiReturns the current user’s
.id,.usernameand whether they’re currently logged in.Declaration
Swift
func whoamiHandler(_ req: Request) throws -> CurrentUserDataReturn Value
CurrentUserDatacontaining the current user’s ID, username, logged in status, access level, and roles. -
passwordHandler(_:Asynchronous) POST /api/v3/user/passwordUpdates a user’s password to the supplied value, encrypted.
Throws
400 error if the supplied password is not at least 6 characters. 403 error if the user is a.client.Declaration
Swift
func passwordHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyUserPasswordDatastruct containing the user’s desired password.Return Value
201 Created on success.
-
usernameHandler(_:Asynchronous) POST /api/v3/user/usernamePOST /api/v3/user/:userID/username– moderator useChanges a user’s username to the supplied value, if possible.
/api/v3/user/usernameallows a user to change their own username, while/api/v3/user/:userID/usernameallows moderators to change the username of the indicated user.Throws
400 error if the username is an invalid format. 403 error if you change username more than once per 20 hours (to prevent abuse). Or if the user is a.client. 409 error if the username is not available.Declaration
Swift
func usernameHandler(_ req: Request) async throws -> HTTPStatusParameters
requestBodyUserUsernameDatacontaining the user’s desired new username.Return Value
201 Created on success.
-
imageHandler(_:Asynchronous) POST /api/v3/user/imageSets the user’s profile image to the
ImageUploadDatauploaded in the HTTP body.- If the
ImageUploadDatacontains image data in theimagemember, that data is processed, saved, and set to user’s new image - If the
ImageUploadDatacontains a filename in thefilenamemember, the user’s avatar is set to that image file on the server. We don’t check whether the file exists. If both members are nil, the user’s avatar image is set to nil, which will cause the default image be returned.
Throws
A 5xx response should be reported as a likely bug, please and thank you.
Declaration
Swift
func imageHandler(_ req: Request) async throws -> UserHeaderParameters
requestBodyImageUploadDatapayload in the HTTP body.Return Value
UserHeadercontaining the generated image identifier string. - If the
-
imageRemoveHandler(_:Asynchronous) POST /api/v3/user/image/removeDELETE /api/v3/user/imageDELETE /api/v3/user/:userID/imageRemoves the user’s profile image from their
Userobject. This generally reverts their user avatar image to a default or auto-generated image.The third form, that takes a userID in the URL path, is for moderators only.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func imageRemoveHandler(_ req: Request) async throws -> HTTPStatusParameters
userIDin URL path. Only for the third form of the URL path, which is moderator-only.
Return Value
204 No Content on success.
-
profileHandler(_:Asynchronous) GET /api/v3/user/profileRetrieves the user’s own profile data for editing, as a
ProfilePublicDataobject.Note
The
.header.usernameand.header.displayNameproperties of the returned object are for display convenience only. A username must be changed using thePOST /api/v3/user/usernameendpoint.Throws
403 error if the user is banned. A 5xx response should be reported as a likely bug, please and thank you.
Declaration
Swift
func profileHandler(_ req: Request) async throws -> ProfilePublicDataReturn Value
ProfilePublicDatacontaining the editable properties of the profile. -
profileUpdateHandler(_:Asynchronous) POST /api/v3/user/profilePOST /api/v3/user/:userID/profile- for moderator useUpdates the user’s profile.
Note
All fields of the
UserProfileUploadDatastructure being submitted must be present. While the properties of the profile itself are optional, the submitted values all replace the existing propety values. Submitting a value of""resets its respective profile property tonil.Throws
403 error if the user is banned.
Declaration
Swift
func profileUpdateHandler(_ req: Request) async throws -> ProfilePublicDataParameters
userIDin URL path. Only for the second form of the URL path, which is moderator-only.
requestBodyReturn Value
ProfilePublicDatacontaining the updated editable properties of the profile.
-
alertwordsAddHandler(_:Asynchronous) POST /api/v3/user/alertwords/add/:alertword_stringAdds a string to the user’s “Alert Keywords” barrel. The string is lowercased and stripped of punctuation before being added.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func alertwordsAddHandler(_ req: Request) async throws -> KeywordDataParameters
STRINGIn URL path. The alert word to watch for.
Return Value
AlertKeywordDatacontaining the updated contents of the barrel. -
alertwordsHandler(_:Asynchronous) GET /api/v3/user/alertwordsReturns a list of the user’s current alert keywords in
AlertKeywordDatabarrel format.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func alertwordsHandler(_ req: Request) async throws -> KeywordDataReturn Value
AlertKeywordDatacontaining the current alert keywords as an array of strings. -
alertwordsRemoveHandler(_:Asynchronous) POST /api/v3/user/alertwords/remove/STRINGRemoves a string from the user’s “Alert Keywords” barrel.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func alertwordsRemoveHandler(_ req: Request) async throws -> KeywordDataParameters
STRINGIn URL path. The alert word to remove from the alertword list.
Return Value
AlertKeywordDatacontaining the updated contents of the barrel.
-
mutewordsAddHandler(_:Asynchronous) POST /api/v3/user/mutewords/add/STRINGAdds a string to the user’s “Muted Keywords” barrel.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func mutewordsAddHandler(_ req: Request) async throws -> KeywordDataParameters
STRINGIn URL path. The muteword to add.
Return Value
MuteKeywordDatacontaining the updated contents of the barrel. -
mutewordsHandler(_:Asynchronous) GET /api/v3/user/mutewordsReturns a list of the user’s currently muted keywords in named-list
MuteKeywordDataformat.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func mutewordsHandler(_ req: Request) async throws -> KeywordDataReturn Value
MuteKeywordDatacontaining the current muting keywords as an array of strings. -
mutewordsRemoveHandler(_:Asynchronous) POST /api/v3/user/mutewords/remove/STRINGRemoves a string from the user’s “Muted Keywords” barrel.
Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func mutewordsRemoveHandler(_ req: Request) async throws -> KeywordDataParameters
STRINGIn URL path. The muteword to remove.
Return Value
MuteKeywordDatacontaining the updated contents of the barrel. -
notesHandler(_:Asynchronous) GET /api/v3/user/notesRetrieves all
UserNote>s owned by the current user, as an array ofNoteData` objects.The
NoteDataobject is intended to be display friendly, including fields for potential sorting, the ID of the profile which can be linked to, and the profile’s user in the familiar .displayedName format. The .noteID is included as well to support editing of notes outside of a profile-viewing context.Throws
A 5xx response should be reported as a likely bug, please and thank you.Declaration
Swift
func notesHandler(_ req: Request) async throws -> [NoteData]Return Value
An array of
NoteDatacontaining all of the user’s notes.
-
Generates a recovery key of 3 words randomly chosen from
wordsarray.Throws
500 error if the randomizer fails.Declaration
Swift
static func generateRecoveryKey(on req: Request) throws -> StringParameters
reqThe incoming
Request, provided automatically.Return Value
A recoveryKey string.
View on GitHub