Skip to main content

LoginManager

A class in Root.Township, the global namespace.

Logs the client in to the Alta API: automatic login at startup, or username (or email) and password. Raises static events and runs queued actions after login. Get it with SingletonBehaviour<LoginManager>.Instance.

Constructors​

MemberWhat it is
LoginManager()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

4 private and internal fields
MemberWhat it is
private static readonly Logger loggerNLog logger for this class.
private ILoginPreferences loginPreferencesSaved login settings and credentials, injected.
private readonly List<Action> postLoginActionsActions waiting for the next successful login.
private IUserService userServiceInjected user service used for automatic login.

Properties​

MemberWhat it is
static bool IsLoggedIn { get; }True when the API client has logged-in user info.
static bool IsLoggedInWithOculusAccount { get; set; }Set when logging in on Quest. Marked obsolete.
ILoginPreferences Preferences { get; }Saved login preferences (username, remember details, credentials).

Events​

MemberWhat it is
static event Action AttemptingLoginRaised when an automatic or manual login starts.
static event Action LoggedInRaised after a successful login, once post-login actions have run.
static event Action LoggedOutRaised after Logout.
static event Action<string> LoginAttemptFailedRaised with the error message when a login fails.

Methods​

MemberWhat it is
void AddPostLoginAction(Action action)Runs the action now if already logged in, otherwise queues it to run after the next successful login.
async Task<IResult> LoginAsync(string username, string password)Logs in with a hashed password. Email logins return success without running post-login actions or raising LoggedIn.
IResult Logout()Logs out, clears saved credentials and raises LoggedOut. On Android it opens the registration scene.
void ProcessSuccessfulLogin()Saves credentials, runs queued post-login actions and raises LoggedIn.
protected override void Awake()Hooks automatic login to application startup.
protected void Inject(IUserService userService, ILoginPreferences loginPreferences)Receives the user service and login preferences from dependency injection.
3 private and internal methods
MemberWhat it is
private async void AutoLoginAsync()Runs when the app has started: tries an automatic login through the user service and handles success or failure.
private void ExecutePostLoginActions()Runs and clears the actions queued with AddPostLoginAction, and marks Quest logins as Oculus.
private async Task ProcessAutoLoginFailed(IResult loginResult)Raises LoginAttemptFailed and, on Android, loads the registration scene.