public async Task <ActionResult> Register(AppUserRegisterVm appUserRegisterVm)
        {
            var result = View();

            // If registerVm is null, then return the empty registration form
            if (appUserRegisterVm == null)
            {
                return(result);
            }
            if (appUserRegisterVm.AcceptTermsOfService == false)
            {
                ModelState.AddModelSummaryError("You need to read and accept the Terms of Service.");
            }

            // If model is valid, continue with the registration
            if (ModelState.IsValid)
            {
                // Register the user through the service.
                var stggResult = await Managers.UserAccountManager.RegisterAsync(appUserRegisterVm);

                if (stggResult.Status == StggResultStatus.Succeeded)
                {
                    StggSecurityContext.SetCurrentUser(stggResult.Value);
                    return(RedirectToAction("EmailConfirmTokenSent"));
                }
                else
                {
                    ModelState.AddModelSummaryError(stggResult.Errors);
                }
            }

            // Model is invalid, bring the user back to the page.
            return(View(appUserRegisterVm));
        }
        public async Task <ActionResult> Login(AppUserLoginVm appUserLoginVm)
        {
            // Initialize the view.
            var result = View();

            // If AppUserLoginVm is null return the form.
            if (appUserLoginVm == null)
            {
                return(result);
            }

            // If model is valid, continue with the authentication
            if (ModelState.IsValid)
            {
                // Validate username and password.
                var stggResult = await Managers.UserAccountManager.LoginAsync(appUserLoginVm);

                var appUserVm = stggResult.Value;

                switch (appUserVm.SignInStatus)
                {
                case SignInStatus.Success:
                    // Set the current application user.
                    StggSecurityContext.SetCurrentUser(appUserVm, appUserLoginVm.RememberMe);
                    // User passed the login challenge, redirect to the homepage.
                    return(RedirectToAction("Index", "Home"));

                case SignInStatus.RequiresVerification:
                    // User passed the login challenge but needs to verify email.
                    return(RedirectToAction("EmailConfirmTokenSent"));

                case SignInStatus.LockedOut:
                    // User is currently locked out.
                    return(RedirectToAction("LockedOut"));

                default:
                    // Invalid username or password
                    ModelState.AddModelSummaryError("Username or password is invalid.");
                    break;
                }
            }

            result = View(appUserLoginVm);

            return(result);
        }