Ejemplo n.º 1
0
        public async Task <IHttpActionResult> CreatePassword(CreatePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var            user         = UserManager.FindByName(model.Email);
            IdentityResult resultRemove = await UserManager.RemovePasswordAsync(user.Id);

            if (resultRemove.Succeeded)
            {
                IdentityResult result = await UserManager.AddPasswordAsync(user.Id, model.Password);

                if (!result.Succeeded)
                {
                    return(GetErrorResult(result));
                }
            }
            else
            {
                return(GetErrorResult(resultRemove));
            }

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreatePassword(CreatePasswordViewModel model, string senhaAtual, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                ViewBag.Mensagem = "Algumas informações não parecem estar consistentes!";
                ViewBag.ReturUrl = returnUrl;
                return(View(model));
            }

            using (UserModel user = await _userManager.GetUserAsync(User))
            {
                IdentityResult result = await _userManager.ChangePasswordAsync(user, senhaAtual, model.Senha);

                if (!result.Succeeded)
                {
                    ViewBag.Mensagem = "Não foi possível cadastrar sua senha!";
                    ViewBag.ReturUrl = returnUrl;
                    return(View(model));
                }

                try
                {
                    user.PrimeiroAcesso = false;
                    user.Salvar(_connection, null);
                    return(RedirectToLocal(returnUrl));
                } catch
                {
                    ViewBag.Mensagem = "Ocorreu um erro ao cadastrar sua senha!";
                    ViewBag.ReturUrl = returnUrl;
                    return(View(model));
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> CreatePassword(CreatePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await _userManager.FindByIdAsync(TempData["UserID"].ToString());

            if (user != null)
            {
                var result = await _userManager.AddPasswordAsync(user, model.NewPassword);

                if (result.Succeeded)
                {
                    var url = _env.IsDevelopment() ? Configuration["HostSettings:FrontEndUrl"] : Configuration["HostSettings:RemoteFrontEndUrl"];

                    return(Redirect(url + "/home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
                return(View(model));
            }
            return(View(model));
        }
        public void GeneratePronounceablePasswordCommandTest()
        {
            // Arrange
            CreatePasswordViewModel cpvmPronounceable2Words = new CreatePasswordViewModel(null, null);

            cpvmPronounceable2Words.HowManyWords = "2";

            CreatePasswordViewModel cpvmPronounceable9Words = new CreatePasswordViewModel(null, null);

            cpvmPronounceable9Words.HowManyWords = "9";

            // Act
            cpvmPronounceable2Words.GeneratePronounceablePasswordCommand.Execute(null);
            string password2Words = cpvmPronounceable2Words.GeneratedPronounceablePassword;

            cpvmPronounceable9Words.GeneratePronounceablePasswordCommand.Execute(null);
            string password9Words = cpvmPronounceable9Words.GeneratedPronounceablePassword;

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(password2Words));
            Assert.Greater(password2Words.Length, 5);

            Assert.IsFalse(string.IsNullOrEmpty(password9Words));
            Assert.Greater(password9Words.Length, 21);

            Assert.AreNotEqual(password2Words, password9Words);
        }
Ejemplo n.º 5
0
        public async Task <ActionResult> CreatePassword(CreatePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await UserManager.FindByNameAsync(model.Email);

            if (user == null)
            {
                ViewBag.ErrorMsg = "You shouldn't be seeing this page. Ask your administrator for assistance.";
                return(View("Error"));
            }

            var result = await UserManager.AddPasswordAsync(user.Id, model.Password);

            if (result.Succeeded)
            {
                UserManager.FindByEmail(model.Email).EmailConfirmed = true;
                UserManager.Update(user);
                var employee = UnitOfWork.EmployeeRepository.Get(e => e.Email.Equals(model.Email));
                if (employee != null)
                {
                    employee.First().EmailConfirmed = true;
                    UnitOfWork.Save();
                }
                return(RedirectToAction("CreatePasswordConfirmation", "Account"));
            }

            AddErrors(result);
            return(View());
        }
Ejemplo n.º 6
0
        public async Task <string> SendEmailCreateTokenAsync(string userID) //, string subject, string bdy)
        {
            var url = new UrlHelper(HttpContext.Current.Request.RequestContext);

            //Forgery check
            string code = await UserManager.GeneratePasswordResetTokenAsync(userID);

            //The link sent to the Transferees for access to reset password
            var callbackUrl = url.Action("CreatePassword", "Account", new { userID, code = code }, protocol: HttpContext.Current.Request.Url.Scheme);

            var user = await UserManager.FindByIdAsync(userID);

            //transferee's email address
            var eml  = user.Email;
            var name = user.FirstName + " " + user.LastName;

            var    subject            = "Create Password";
            var    templateFolderPath = HttpContext.Current.Server.MapPath(@"~\Views\Mailers\");
            string template           = System.IO.File.ReadAllText(templateFolderPath + "CreatePassword.cshtml");
            var    logoUrl            = new Uri(HttpContext.Current.Request.Url, url.Content("~/Content/Images/dwellworks_icon.png")).ToString();
            var    vm = new CreatePasswordViewModel()
            {
                Name = name, CreateUrl = callbackUrl, LogoUrl = logoUrl
            };
            var body = Engine.Razor.RunCompile(template, "Create Password", null, vm);

            //send the email, specify the content mime type
            var response = _emailHelper.SendEmail_SG(eml, subject, body, SendGrid.MimeType.Html);

            return(response);
        }
Ejemplo n.º 7
0
 public IActionResult CreatePassword(CreatePasswordViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(View(model));
     }
     return(View());
 }
Ejemplo n.º 8
0
        public async Task Then_View_is_returned_with_identical_ViewModel(string password, string confirmPassword)
        {
            var createPasswordViewModel = new CreatePasswordViewModel()
            {
                Password = password, ConfirmPassword = confirmPassword
            };
            var result = await _controller.Post(createPasswordViewModel);

            result.Should().BeOfType <ViewResult>();
            ((ViewResult)result).ViewName.Should().Be("CreatePassword");
            ((ViewResult)result).Model.Should().BeOfType <CreatePasswordViewModel>();
            ((CreatePasswordViewModel)((ViewResult)result).Model).Should().BeSameAs(createPasswordViewModel);
        }
        public void GeneratePasswordCommandShortTest()
        {
            // Arrange
            CreatePasswordViewModel cpvmShort = new CreatePasswordViewModel(null, null);

            cpvmShort.PasswordLength = "8";

            // Act
            cpvmShort.GeneratePasswordCommand.Execute(null);
            string passwordShort = cpvmShort.GeneratedPassword;

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(passwordShort));
            Assert.AreEqual(int.Parse(cpvmShort.PasswordLength), passwordShort.Length);
        }
        public async Task <ActionResult> Post(CreatePasswordViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View("CreatePassword", vm));
            }

            var invitation = await Mediator.Send(new GetInvitationByIdRequest(vm.InvitationId));

            if (invitation == null)
            {
                return(BadRequest("Invitation does not exist"));
            }

            SetViewBagClientId(invitation.ClientId);

            if (vm.Password == vm.ConfirmPassword)
            {
                var response = await Mediator.Send(new CreatePasswordRequest { InvitationId = vm.InvitationId, Password = vm.Password });

                if (response.PasswordValid)
                {
                    return(RedirectToAction("Get", "SignUpComplete", new { id = vm.InvitationId }));
                }

                ModelState.AddModelError("Password", "Password does not meet minimum complexity requirements");

                return(View("CreatePassword",
                            new CreatePasswordViewModel()
                {
                    InvitationId = vm.InvitationId,
                    Password = vm.Password,
                    ConfirmPassword = vm.ConfirmPassword
                }));
            }

            ModelState.AddModelError("Password", "Passwords should match");

            return(View("CreatePassword", new CreatePasswordViewModel()
            {
                InvitationId = vm.InvitationId,
                Password = vm.Password,
                ConfirmPassword = vm.ConfirmPassword
            }));
        }
        public void GeneratePasswordCommandDefaultTest()
        {
            // Arrange
            CreatePasswordViewModel cpvmDefault1 = new CreatePasswordViewModel(null, null);
            CreatePasswordViewModel cpvmDefault2 = new CreatePasswordViewModel(null, null);

            // Act
            cpvmDefault1.GeneratePasswordCommand.Execute(null);
            string passwordDefault1 = cpvmDefault1.GeneratedPassword;

            cpvmDefault2.GeneratePasswordCommand.Execute(null);
            string passwordDefault2 = cpvmDefault2.GeneratedPassword;

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(passwordDefault1));
            Assert.AreEqual(int.Parse(cpvmDefault1.PasswordLength), passwordDefault1.Length);

            Assert.AreNotEqual(passwordDefault1, passwordDefault2);
        }
Ejemplo n.º 12
0
        public async Task <IActionResult> CreatePassword(CreatePasswordViewModel model)
        {
            User user = await _userManager.GetUserAsync(HttpContext.User);

            IdentityResult result =
                await _userManager.ChangePasswordAsync(user, "temporary", model.NewPassword);

            if (result.Succeeded)
            {
                return(RedirectToAction("Actual", "Lots"));
            }
            else
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }
            return(View(model));
        }
        public void GeneratePasswordCommandDigitsTest()
        {
            // Arrange
            CreatePasswordViewModel cpvmOnlyDigits = new CreatePasswordViewModel(null, null);

            cpvmOnlyDigits.IncludeUpperCaseLatinLetters = false;
            cpvmOnlyDigits.IncludeLowerCaseLatinLetters = false;
            cpvmOnlyDigits.IncludeDigits = true;
            cpvmOnlyDigits.IncludeSpecialCharactersASCII = false;
            cpvmOnlyDigits.IncludeEmojis = false;

            // Act
            cpvmOnlyDigits.GeneratePasswordCommand.Execute(null);
            string passwordDigits = cpvmOnlyDigits.GeneratedPassword;

            // Assert
            Assert.IsFalse(string.IsNullOrEmpty(passwordDigits));
            Assert.AreEqual(int.Parse(cpvmOnlyDigits.PasswordLength), passwordDigits.Length);

            Assert.IsTrue(passwordDigits.All(c => char.IsDigit(c)));
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> CreatePassword(CreatePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await UserManager.FindByIdAsync(model.UserId);

            if (user == null)
            {
                // Don't reveal that the user does not exist
                return(RedirectToAction("Error"));
            }

            var result = await UserManager.ResetPasswordAsync(user.Id, model.Code, model.Password);

            if (result.Succeeded)
            {
                return(RedirectToAction("Login", "Account"));
            }

            AddErrors(result);
            return(View());
        }
 public CreatePasswordWindow(Action <string> passwordCallback)
 {
     InitializeComponent();
     DataContext = new CreatePasswordViewModel(this.OkClose, passwordCallback);
 }