Ejemplo n.º 1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new VerificationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await userManager.CreateAsync(user, model.Password);

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

                    user.VerificationCode = RandomString(10, true);
                    await userManager.UpdateAsync(user);

                    return(RedirectToAction("index", "home"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View(model));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Login(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                VerificationUser verificationUser = await userManager.GetUserAsync(User);

                if (verificationUser.VerificationCode == model.VerificationCode)
                {
                    verificationUser.EmailConfirmed = true;
                }
                else
                {
                    verificationUser.EmailConfirmed = false;
                }
                await userManager.UpdateAsync(verificationUser);

                var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, true, false);

                if (result.Succeeded)
                {
                    //var finalresult = await signInManager.TwoFactorAuthenticatorSignInAsync(model.VerificationCode, false,false)
                    //if(verificationUser.IsUpdated == true)
                    //{
                    //    return RedirectToAction("UserInfoReadOnly", "Account");
                    //}
                    return(RedirectToAction("UserDetails", "Account"));
                }

                ModelState.AddModelError(string.Empty, "Invalid Login Attempt");
            }
            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> UserDetails(UserDetailsViewModel model)
        {
            if (ModelState.IsValid)
            {
                //var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
                //var userName = User.FindFirstValue(ClaimTypes.Name);
                VerificationUser verificationUser = await userManager.GetUserAsync(User);

                verificationUser.FirstName          = model.FirstName;
                verificationUser.LastName           = model.LastName;
                verificationUser.AddressLine1       = model.AddressLine1;
                verificationUser.AddressLine2       = model.AddressLine2;
                verificationUser.City               = model.City;
                verificationUser.State              = model.State;
                verificationUser.IsPromotionsEnable = model.IsPromotionsEnable;
                verificationUser.IsUpdated          = true;

                var result = await userManager.UpdateAsync(verificationUser);

                if (!result.Succeeded)
                {
                    ModelState.AddModelError(string.Empty, "Update Failed");
                }
            }
            return(View(model));
        }