UserController
struct UserController : APIRouteCollectionThe collection of /api/v3/user/* route endpoints and handler functions related
to a user’s own data.
Separating these from the endpoints related to users in general helps make for a
cleaner collection, since use of User.parameter in the paths here can be avoided
entirely.
- 
                  
                  An array of words used to generate random phrases. DeclarationSwift static let words: [String]
- 
                  
                  Required. Registers routes to the incoming router. DeclarationSwift 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. DeclarationSwift func createHandler(_ req: Request) async throws -> ResponseParametersrequestBodyReturn ValueCreatedUserDatacontaining 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.DeclarationSwift func verifyHandler(_ req: Request) async throws -> HTTPStatusParametersrequestBodyReturn ValueHTTP 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. DeclarationSwift func addHandler(_ req: Request) async throws -> ResponseParametersrequestBodyReturn ValueAddedUserDatacontaining 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.DeclarationSwift func whoamiHandler(_ req: Request) throws -> CurrentUserDataReturn ValueCurrentUserDatacontaining the current user’s ID, username and logged in status.
- 
                  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.DeclarationSwift func passwordHandler(_ req: Request) async throws -> HTTPStatusParametersrequestBodyUserPasswordDatastruct containing the user’s desired password.Return Value201 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.DeclarationSwift func usernameHandler(_ req: Request) async throws -> HTTPStatusParametersrequestBodyUserUsernameDatacontaining the user’s desired new username.Return Value201 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. DeclarationSwift func imageHandler(_ req: Request) async throws -> UserHeaderParametersrequestBodyImageUploadDatapayload in the HTTP body.Return ValueUserHeadercontaining 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.DeclarationSwift func imageRemoveHandler(_ req: Request) async throws -> HTTPStatusParametersuserIDin URL path. Only for the third form of the URL path, which is moderator-only. Return Value204 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. DeclarationSwift func profileHandler(_ req: Request) async throws -> ProfilePublicDataReturn ValueProfilePublicDatacontaining 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. DeclarationSwift func profileUpdateHandler(_ req: Request) async throws -> ProfilePublicDataParametersuserIDin URL path. Only for the second form of the URL path, which is moderator-only. requestBodyReturn ValueProfilePublicDatacontaining 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.DeclarationSwift func alertwordsAddHandler(_ req: Request) async throws -> KeywordDataParametersSTRINGIn URL path. The alert word to watch for. Return ValueAlertKeywordDatacontaining 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.DeclarationSwift func alertwordsHandler(_ req: Request) async throws -> KeywordDataReturn ValueAlertKeywordDatacontaining 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.DeclarationSwift func alertwordsRemoveHandler(_ req: Request) async throws -> KeywordDataParametersSTRINGIn URL path. The alert word to remove from the alertword list. Return ValueAlertKeywordDatacontaining 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.DeclarationSwift func mutewordsAddHandler(_ req: Request) async throws -> KeywordDataParametersSTRINGIn URL path. The muteword to add. Return ValueMuteKeywordDatacontaining 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.DeclarationSwift func mutewordsHandler(_ req: Request) async throws -> KeywordDataReturn ValueMuteKeywordDatacontaining 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.DeclarationSwift func mutewordsRemoveHandler(_ req: Request) async throws -> KeywordDataParametersSTRINGIn URL path. The muteword to remove. Return ValueMuteKeywordDatacontaining 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.DeclarationSwift func notesHandler(_ req: Request) async throws -> [NoteData]Return ValueAn 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.DeclarationSwift static func generateRecoveryKey(on req: Request) throws -> StringParametersreqThe incoming Request, provided automatically.Return ValueA recoveryKey string. 
 View on GitHub
            View on GitHub
           UserController Structure Reference
      UserController Structure Reference