예제 #1
0
        public async Task <IActionResult> ForgotPassword(ForgotPasswordViewModel forgotPasswordVM)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            GolfioUser golfioUser = await _golfioUser.FindByEmailAsync(forgotPasswordVM.Email);

            if (golfioUser == null)
            {
                TempData["MessageTitle"] = "Invalid Email";
                TempData["Message"]      = "Please ensure the email is correct and you've already registered";
                return(RedirectToAction("Login"));
            }

            if (!golfioUser.EmailConfirmed)
            {
                TempData["MessageTitle"] = "Email Not Confirmed";
                TempData["Message"]      = "You have not confirmed your email yet";
                return(RedirectToAction("Login"));
            }

            string token = await _golfioUser.GeneratePasswordResetTokenAsync(golfioUser);

            var passwordResetLink = Url.Action("ResetPassword", "Account", new { email = forgotPasswordVM.Email, token = token }, Request.Scheme);

            _email.EmailToken(golfioUser, passwordResetLink, EmailType.PasswordReset);

            TempData["MessageTitle"] = "Email Sent";
            TempData["Message"]      = "Please check your email for password reset link";

            return(RedirectToAction("Login"));
        }
예제 #2
0
        public async Task <IActionResult> Login(LoginViewModel loginVM, string returnUrl)
        {
            GolfioUser   golfioUser = new GolfioUser();
            bool         isValidLogin;
            SignInResult signInResult;

            if (!ModelState.IsValid)
            {
                return(View(loginVM));
            }

            golfioUser = await _golfioUser.GetUserAsync(loginVM.Email);

            if (golfioUser == null)
            {
                TempData["MessageTitle"] = "Login Failed";
                TempData["Message"]      = "Invalid Login Attempt";
                return(View(loginVM));
            }

            isValidLogin = await _golfioUser.IsValidLoginAsync(golfioUser, loginVM.Password);

            if (!isValidLogin)
            {
                TempData["MessageTitle"] = "Login Failed";
                TempData["Message"]      = "Invalid Login Attempt";
                return(View(loginVM));
            }

            signInResult = await _golfioUser.SignInUserAsync(loginVM);

            if (!signInResult.Succeeded)
            {
                TempData["MessageTitle"] = "Login Failed";
                TempData["Message"]      = "Invalid Login Attempt";
                return(View(loginVM));
            }

            HttpContext.Session.SetString("FullName", golfioUser.FullName);

            if (!string.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
            {
                return(Redirect(returnUrl));
            }
            else
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
예제 #3
0
        public async Task <IActionResult> Register(RegisterViewModel registerViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            IdentityResult result = await _golfioUser.RegisterAsync(registerViewModel);

            if (result.Succeeded)
            {
                GolfioUser golfioUser = await _golfioUser.GetUserAsync(registerViewModel.Email);

                var token = await _golfioUser.CreateEmailConfirmationToken(golfioUser);

                var tokenLink = Url.Action("ConfirmEmail", "Account", new { userId = golfioUser.Id, token = token }, Request.Scheme);

                // _email.EmailToken(golfioUser, tokenLink, EmailType.EmailConfirmation);
                _logger.Log(LogLevel.Warning, tokenLink);

                TempData["MessageTitle"] = "Registration Success";
                TempData["Message"]      = "Please check your email for confirmation link";

                return(RedirectToAction("Login"));
            }
            else
            {
                Dictionary <string, string> errors = new Dictionary <string, string>();

                foreach (var error in result.Errors)
                {
                    errors.Add(error.Code, error.Description);
                }

                ViewBag.Errors = errors;
                // return Json(errors);
                return(View());
            }
        }
예제 #4
0
        public async Task <IActionResult> ConfirmEmail(string userId, string token)
        {
            if (userId == null || token == null)
            {
                TempData["MessageTitle"] = "Error";
                TempData["Message"]      = "The email confirmation token link is invalid";

                return(RedirectToAction("Login"));
            }

            GolfioUser golfioUser = await _golfioUser.GetUserAsync(userId);

            if (golfioUser == null)
            {
                TempData["MessageTitle"] = "Error";
                TempData["Message"]      = "No user found";

                return(RedirectToAction("Login"));
            }

            IdentityResult result = await _golfioUser.ConfirmEmailTokenAsync(golfioUser, token);

            if (result.Succeeded)
            {
                TempData["MessageTitle"] = "Email Confirmed";
                TempData["Message"]      = "You may now login";

                return(RedirectToAction("Login"));
            }
            else
            {
                TempData["MessageTitle"] = "Error";
                TempData["Message"]      = "Something went wrong while confirming the email token";

                return(RedirectToAction("Login"));
            }
        }
예제 #5
0
 public UserEditViewModel()
 {
     GolfioUser = new GolfioUser();
 }