Beispiel #1
0
        public AccountCreationResult TryCreateAccount(AccountCreationParameters parameters)
        {
            var rawEmail       = parameters.Email;
            var emailKey       = BuildEmailKey(rawEmail);
            var saltedPassword = passwordUtilities.CreateSaltedHash(parameters.HashedPassword);

            // atomically reserve email address and set accountid to -1
            if (!emailToAccountIdCache.Invoke(emailKey, new TryReserveEmailProcessor()))
            {
                return(new AccountCreationResult(SpecialAccountIds.kInvalidAccountId, AccountCreationErrorCodeFlags.EmailExists));
            }
            else
            {
                // atomically take unique accountId
                var accountId = accountIdCounter.TakeNextValue();

                // atomically assign accountId to emailToAccountId entry.
                if (!emailToAccountIdCache.Invoke(emailKey, new TryAssignAccountIdProcessor(accountId)))
                {
                    return(new AccountCreationResult(SpecialAccountIds.kInvalidAccountId, AccountCreationErrorCodeFlags.ServerError));
                }
                else
                {
                    // atomically create account information for given accountId.
                    if (!accountInfoByIdCache.Invoke(accountId, new AccountCreationProcessor(rawEmail, saltedPassword)))
                    {
                        return(new AccountCreationResult(SpecialAccountIds.kInvalidAccountId, AccountCreationErrorCodeFlags.ServerError));
                    }
                    return(new AccountCreationResult(accountId, AccountCreationErrorCodeFlags.Success));
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new Account in a modal dialog.
        /// </summary>
        public async Task CreateNewInModalDialog()
        {
            var accountParameters = new AccountCreationParameters();
            var parameters        = new ModalParameters();

            parameters.Add(nameof(ModalCreateNew <AccountCreationParameters> .Item), accountParameters);
            var options = new ModalOptions
            {
                DisableBackgroundCancel = true,
            };

            var modal  = this.modalService.Show <ModalCreateNew <AccountCreationParameters> >($"Create {typeof(Account).Name}", parameters, options);
            var result = await modal.Result;

            if (!result.Cancelled)
            {
                var item = this.playerContext.CreateNew <Account>();
                item.LoginName        = accountParameters.LoginName;
                item.PasswordHash     = BCrypt.Net.BCrypt.HashPassword(accountParameters.Password);
                item.EMail            = accountParameters.EMail;
                item.State            = accountParameters.State;
                item.SecurityCode     = accountParameters.SecurityCode;
                item.RegistrationDate = DateTime.Now;
                this.playerContext.SaveChanges();
                this.RaiseDataChanged();
            }
        }
        public string TryCreateAccount(string email, string hashedPassword)
        {
            var accountCreationParameters = new AccountCreationParameters(email, hashedPassword);
            var result = accountCache.TryCreateAccount(accountCreationParameters);
            var sb     = new StringBuilder();

            sb.AppendLine("AccountId: " + result.AccountId);
            sb.AppendLine("ErrorCodeFlags: " + result.ErrorCodeFlags);
            return(sb.ToString());
        }