Exemplo n.º 1
0
        public async Task <ActionResult> FirstLogin(FirstLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByEmailAsync(model.Email);

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

                        if (result.Succeeded)
                        {
                            await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                            return(RedirectToAction <HomeController>(c => c.Index()));
                        }

                        AddErrors(result);
                    }
                }
            }
            return(View(model));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> SetPassword(string userId)
        {
            if (userId == null)
            {
                return(View("Error"));
            }

            var user = await UserManager.FindByIdAsync(userId);

            FirstLoginViewModel vm = new FirstLoginViewModel();

            vm.Email = user.Email;

            return(View("FirstLogin", vm));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> FirstLogin(FirstLoginViewModel model)
        {
            ViewBag.Translate     = new Translate();
            ViewBag.HideMenuLogin = true;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var user = await userManager.FindByNameAsync(model.Email);

            if (user == null || IsDemoUser(user))
            {
                // Don't reveal that the user does not exist
                ModelState.AddModelError("", "The email do not match the registered email address or you have been logged in for the first time.");
                return(View());
            }
            var result = await userManager.ResetPasswordAsync(user, model.Code, model.Password);

            if (result.Succeeded)
            {
                await AutoConfirmEmail(user);

                await signInManager.SignInAsync(user, isPersistent : true);

                return(RedirectToAction("Index", "A"));
            }

            foreach (var error in result.Errors)
            {
                if (error.Code.Equals("InvalidToken", StringComparison.InvariantCultureIgnoreCase))
                {
                    ModelState.AddModelError("", "The email do not match the registered email address or you have been logged in for the first time.");
                }
                else
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> FirstLogin(string userId, string code)
        {
            if (userId == null || code == null)
            {
                return(View("Error"));
            }

            var result = await UserManager.ConfirmEmailAsync(userId, code);

            if (!result.Succeeded)
            {
                return(View("Error"));
            }

            var user = await UserManager.FindByIdAsync(userId);

            FirstLoginViewModel vm = new FirstLoginViewModel();

            vm.Email = user.Email;

            return(View(vm));
        }
 public FirstLogin(string username, string password)
 {
     InitializeComponent();
     DataContext = new FirstLoginViewModel(this, username, password);
 }