public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            AccountModel result = Db.Accounts.Where(m => m.EmailAddress == model.EmailAddress).FirstOrDefault();

            if (result != null)
            {
                return(View(model));
            }

            AccountModel Account = new AccountModel();

            Account.FirstName    = model.FirstName;
            Account.LastName     = model.LastName;
            Account.Nickname     = model.Nickname;
            Account.EmailAddress = model.EmailAddress;
            Account.Password     = PasswordSecurity.CreateHash(model.Password);
            Account.DateCreated  = DateTime.Now;

            await Db.Accounts.AddAsync(Account);

            await Db.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Example #2
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (HasBrokenRules())
            {
                return;
            }

            try
            {
                UserAccountItem.DisplayName = txtName.Text;
                UserAccountItem.Username    = txtUsername.Text;

                var hash = PasswordSecurity.CreateHash(txtPassword.Text);
                if (hash != UserAccountItem.Password)
                {
                    UserAccountItem.Password = hash;
                }

                UserAccountItem.SecurityLevel = chkAdmin.Checked ? "Admin" : "User";
                UserAccountItem.Active        = !chkDisabled.Checked;

                if (UserAccountItem.Save(AppSession.CurrentUser.Username))
                {
                    DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }
Example #3
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            AccountModel result = Db.Accounts.Where(m => m.EmailAddress == model.EmailAddress).FirstOrDefault();

            if (result != null)
            {
                return(View(model));
            }

            AccountModel Account = new AccountModel()
            {
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                Nickname     = model.Nickname,
                EmailAddress = model.EmailAddress,
                Password     = PasswordSecurity.CreateHash(model.Password),
                Role         = AccountRoles.Customer,
                Status       = AccountStatus.Enabled,
                DateCreated  = DateTime.Now
            };

            await Db.Accounts.AddAsync(Account);

            await Db.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
Example #4
0
        private bool HasBrokenRules()
        {
            var oldHash = PasswordSecurity.CreateHash(txtOldPassword.Text);

            if (AppSession.CurrentUser.Password != oldHash)
            {
                return(ShowValidationError(txtPassword, "Old Password is INVALID"));
            }


            if (string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                return(ShowValidationError(txtPassword, "Password is required"));
            }

            if (txtPassword.Text != txtRePassword.Text)
            {
                return(ShowValidationError(txtRePassword, "Passwords do NOT match!"));
            }

            return(false);
        }
Example #5
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            if (HasBrokenRules())
            {
                return;
            }

            try
            {
                var user = AppSession.CurrentUser;

                user.Password = PasswordSecurity.CreateHash(txtPassword.Text);
                user.Save(AppSession.CurrentUser.Username);

                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n" + ex.StackTrace);
            }
        }