Class SelfServiceService
- Namespace
- FishMMO.ControlPanel.Services
- Assembly
- FishMMO-ControlPanel.dll
Account operations a signed-in player performs on their own account: changing a password or email, and managing two-factor enrolment.
public sealed class SelfServiceService
- Inheritance
-
SelfServiceService
- Inherited Members
Remarks
Everything here has an in-game counterpart or is deliberately web-only because the game client has nowhere sensible to put it. What it does NOT contain is anything that creates or destroys a character — that is in-game only, by decision, and the panel's character surface is read-only.
Constructors
SelfServiceService(IAccountService, ITwoFactorRecoveryCodeService, IEmailQueueService, IAuthTokenService, IUnitOfWorkService, TotpKeyProvider, ILogger<SelfServiceService>)
public SelfServiceService(IAccountService accounts, ITwoFactorRecoveryCodeService recoveryCodes, IEmailQueueService emailQueue, IAuthTokenService authTokens, IUnitOfWorkService unitOfWork, TotpKeyProvider totpKeys, ILogger<SelfServiceService> log)
Parameters
accountsIAccountServicerecoveryCodesITwoFactorRecoveryCodeServiceemailQueueIEmailQueueServiceauthTokensIAuthTokenServiceunitOfWorkIUnitOfWorkServicetotpKeysTotpKeyProviderlogILogger<SelfServiceService>
Methods
BeginTwoFactorSetupAsync(string, CancellationToken)
Generates fresh two-factor enrolment material and STAGES it: nothing sign-in reads changes until ConfirmTwoFactorAsync(string, PendingCheck, CancellationToken).
public Task<SelfServiceService.TwoFactorSetup> BeginTwoFactorSetupAsync(string username, CancellationToken cancellationToken = default)
Parameters
usernamestringcancellationTokenCancellationToken
Returns
Remarks
The new secret goes into the account's pending column and the new recovery codes in as pending codes, beside the live ones. Confirming with a code from the new authenticator promotes both at once; abandoning the setup leaves the account exactly as it was. This used to write the live secret and replace the live codes here, so a re-enrolment the player did not finish — a scan that never happened, a closed tab — left them with an authenticator that no longer worked and codes they may never have saved (issue #267).
A first enrolment is staged the same way; confirming it is what turns two-factor on. A
re-enrolment still needs a fresh step-up to start: whoever confirms holds the new
authenticator, so without it a borrowed signed-in browser could swap the owner's for its
own. See AccountController.BeginTwoFactorSetup.
ChangeEmailAsync(string, string, CancellationToken)
Changes the contact email and starts verification again.
public Task<SelfServiceService.EmailChange> ChangeEmailAsync(string username, string email, CancellationToken cancellationToken = default)
Parameters
usernamestringemailstringcancellationTokenCancellationToken
Returns
Remarks
The account drops back to unverified, because an unverified address is exactly what it
now has. PersistEmailAsync clears the verified flag and the pending code as one
statement, then a fresh code is issued and queued.
ChangePasswordAsync(string, string, string, CancellationToken)
Replaces the account's SRP credentials after its current password has been proved.
public Task<SelfServiceService.PasswordChange> ChangePasswordAsync(string username, string newSalt, string newVerifier, CancellationToken cancellationToken = default)
Parameters
usernamestringnewSaltstringnewVerifierstringcancellationTokenCancellationToken
Returns
Remarks
The proof is the caller's job — the panel runs a full SRP exchange against the stored verifier first, because a plaintext password exists nowhere on this side to check. Every game token and every panel session is revoked afterwards: a password change that leaves the old sessions alive is not a password change.
ConfirmTwoFactorAsync(string, PendingCheck, CancellationToken)
Promotes the staged authenticator and recovery codes once a code from the new authenticator verifies, and turns two-factor on.
public Task<SelfServiceService.Outcome> ConfirmTwoFactorAsync(string username, TwoFactorService.PendingCheck pending, CancellationToken cancellationToken = default)
Parameters
usernamestringThe signed-in account.
pendingTwoFactorService.PendingCheckThe outcome of
TwoFactorService.VerifyPendingAsyncfor the submitted code.cancellationTokenCancellationTokenCancellation token.
Returns
Remarks
The secret and the codes go live in one transaction, or neither does: a live secret with the old codes, or new codes with the old secret, would leave one of the two unusable.
CountRemainingRecoveryCodesAsync(string, CancellationToken)
How many unused recovery codes an account has left.
public Task<int> CountRemainingRecoveryCodesAsync(string username, CancellationToken cancellationToken = default)
Parameters
usernamestringcancellationTokenCancellationToken
Returns
DisableTwoFactorAsync(string, CancellationToken)
Turns two-factor off and invalidates every recovery code with it.
public Task<SelfServiceService.Outcome> DisableTwoFactorAsync(string username, CancellationToken cancellationToken = default)
Parameters
usernamestringcancellationTokenCancellationToken
Returns
Remarks
ClearTotpAsync resets the secret, the enabled flag, the verified timestamp and
the replay window atomically. The recovery codes are a separate table and have to go
separately, or codes for a secret that no longer exists would linger.
EnrolAsync(string, bool, CancellationToken)
Replaces the account's authenticator secret and recovery codes in ONE transaction, and
turns two-factor on in the same one when enable is set.
public Task<SelfServiceService.TwoFactorSetup> EnrolAsync(string username, bool enable, CancellationToken cancellationToken = default)
Parameters
usernamestringenableboolcancellationTokenCancellationToken
Returns
Remarks
One transaction because every partial state is worse than none. These writes used to be separate, each failing on its own: a delete of the old recovery codes whose result was discarded left codes for a discarded authenticator still opening the account, and a failed insert of the new ones still handed the player ten codes that existed nowhere. Now the account either has the new secret and exactly the new codes, or it has what it had before, and the caller is told which.
Registration uses this with enable set, so a new account never ends up
with a stored secret but two-factor off, or two-factor on with codes that were not saved.
RegenerateRecoveryCodesAsync(string, CancellationToken)
Issues a fresh set of recovery codes, discarding the previous ones.
public Task<SelfServiceService.TwoFactorSetup> RegenerateRecoveryCodesAsync(string username, CancellationToken cancellationToken = default)
Parameters
usernamestringcancellationTokenCancellationToken
Returns
Remarks
The delete and the insert are one transaction. Apart, a failed insert after a good delete left the account with no codes at all while the player was told they "could not be replaced" — and so still believed the old ones worked.