示例#1
0
        public ActionResult CreateAccount(CreateAccountViewModel viewModel)
        {
            LocalAuthenticationController.RequireLocalAuthMode();
            if (!ModelState.IsValid)
            {
                return(ViewCreateAccount(viewModel));
            }
            var theSelectedOrganization = HttpRequestStorage.DatabaseEntities.Organizations.GetOrganization(viewModel.OrganizationID);

            Check.EnsureNotNull(theSelectedOrganization);

            var existingUser = HttpRequestStorage.DatabaseEntities.People.GetPersonByEmail(viewModel.Email, false);

            if (existingUser != null)
            {
                SetMessageForDisplay($"{existingUser.GetFullNameFirstLastAndOrgAsUrl(CurrentFirmaSession)} already has an account.");
                return(RedirectToAction(new SitkaRoute <UserController>(x => x.Detail(existingUser))));
            }

            var newUser = CreateNewFirmaPersonWithoutKeystone(theSelectedOrganization, viewModel);

            HttpRequestStorage.DatabaseEntities.SaveChanges();

            var saltAndHash        = PBKDF2PasswordHash.CreateHash(viewModel.Password);
            var personLoginAccount = new PersonLoginAccount(newUser, newUser.Email, DateTime.Now,
                                                            saltAndHash.PasswordHashed, saltAndHash.PasswordSalt, true, 0, 0);

            HttpRequestStorage.DatabaseEntities.AllPersonLoginAccounts.Add(personLoginAccount);
            HttpRequestStorage.DatabaseEntities.SaveChanges();


            SetMessageForDisplay($"{newUser.GetFullNameFirstLastAndOrgAsUrl(CurrentFirmaSession)} successfully added. You may want to assign them a role.");
            return(RedirectToAction(new SitkaRoute <UserController>(x => x.Detail(newUser))));
        }
示例#2
0
        public ActionResult CreateAccount()
        {
            LocalAuthenticationController.RequireLocalAuthMode();
            var viewModel = new CreateAccountViewModel();

            return(ViewCreateAccount(viewModel));
        }
示例#3
0
        public PartialViewResult ChangePassword(PersonPrimaryKey personPrimaryKey)
        {
            LocalAuthenticationController.RequireLocalAuthMode();
            var person    = personPrimaryKey.EntityObject;
            var viewModel = new ChangePasswordViewModel(person);

            return(ViewChangePassword(viewModel, CurrentFirmaSession));
        }
示例#4
0
        public PartialViewResult EditUser(PersonPrimaryKey personPrimaryKey)
        {
            LocalAuthenticationController.RequireLocalAuthMode();
            var person    = personPrimaryKey.EntityObject;
            var viewModel = new EditUserViewModel(person);

            return(ViewEditUser(viewModel));
        }
示例#5
0
        public ActionResult EditUser(PersonPrimaryKey personPrimaryKey, EditUserViewModel viewModel)
        {
            LocalAuthenticationController.RequireLocalAuthMode();
            var personBeingEdited = personPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewEditUser(viewModel));
            }

            viewModel.UpdateModel(personBeingEdited, CurrentFirmaSession);
            return(new ModalDialogFormJsonResult());
        }
示例#6
0
        public ActionResult ChangePassword(PersonPrimaryKey personPrimaryKey, ChangePasswordViewModel viewModel)
        {
            LocalAuthenticationController.RequireLocalAuthMode();
            var personBeingEdited = personPrimaryKey.EntityObject;

            if (!ModelState.IsValid)
            {
                return(ViewChangePassword(viewModel, CurrentFirmaSession));
            }

            var personAccount = personBeingEdited.PersonLoginAccount;

            var saltAndHash = PBKDF2PasswordHash.CreateHash(viewModel.NewPassword);

            personAccount.PasswordSalt = saltAndHash.PasswordSalt;
            personAccount.PasswordHash = saltAndHash.PasswordHashed;

            HttpRequestStorage.DatabaseEntities.SaveChanges();

            SetMessageForDisplay($"{personBeingEdited.GetFullNameFirstLast()}'s password had been updated.");
            return(new ModalDialogFormJsonResult());
        }