public static async Task <AccountDataItem> CreateAccountLocally(string username, string localToken, string token, long accountId, int deviceId, bool needsInitialSync) { try { AccountDataItem account = account = await AccountsManager.CreateAccount(username, localToken, token, accountId, deviceId, true, true, true, needsInitialSync); return(account); } catch (AccountsManager.UsernameExistsLocallyException) { AlertUsernameExistsLocally?.Invoke(); } catch (AccountsManager.UsernameInvalidException) { AlertInvalidUsername?.Invoke(); } catch (AccountsManager.UsernameWasEmptyException) { AlertUsernameEmpty?.Invoke(); } catch (Exception ex) { TelemetryExtension.Current?.TrackException(ex, "UnknownCreateAccountLocallyError"); ShowMessage("Unknown error occurred. Your error has been sent to the developer.\n\n" + ex.ToString(), "Error"); } return(null); }
public async Task Initialize() { AccountDataItem account = await AccountsManager.CreateAccount("andrewbares", "andrew", null, 0, 0, true, true, true, false); LocalAccountId = account.LocalAccountId; await InitializeAfterAccount(); }
public async Task TestCreatingAccount() { AccountDataItem account = await AccountsManager.CreateAccount("andrewbares", "andrew", null, 0, 0, true, true, true); LoginViewModel accountsViewModel = await LoginViewModel.Load(); Assert.AreEqual(1, accountsViewModel.Accounts.Count); Assert.AreEqual("andrewbares", accountsViewModel.Accounts.First().Username); account = await AccountsManager.GetOrLoad(account.LocalAccountId); Assert.AreEqual("andrew", account.Password); }
public ActionResult SignUp(SignUpModel model) { // Validate the token if (!string.IsNullOrWhiteSpace(model.Token) && model.Token == InviteTokenCreator.Create()) { // Check for "admin" in the username if (model.Username.ToLower().Contains("admin")) { return(CreateValidationError("Username", "Invalid username")); } // Check if the username and email exists if (AccountsManager.UsernameExists(model.Username)) { return(CreateValidationError("Username", "The username does already exist.")); } if (AccountsManager.EmailExists(model.Email)) { return(CreateValidationError("Email", "The email address does already exist.")); } // Create the account bool ok = AccountsManager.CreateAccount(model.Username.Trim().ToLower(), model.Email.Trim().ToLower(), model.Password); if (!ok) { return(CreateValidationError("Failed to create the user")); } // Set the authentication cookie FormsAuthentication.SetAuthCookie(model.Username, true); // OK return(JsonOK()); } else { // Invalid token, show error on client return(CreateValidationError("Invalid token")); } }