Exemplo n.º 1
0
        //
        // GET: /Manage/VerifyPhoneNumber
        public async Task <ActionResult> VerifyPhoneNumber(string phoneNumber)
        {
            var code = await UserManager.GenerateChangePhoneNumberTokenAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), phoneNumber);

            // Send an SMS through the SMS provider to verify the phone number
            return(phoneNumber == null?View("Error") : View(new VerifyPhoneNumberViewModel {
                PhoneNumber = phoneNumber
            }));
        }
Exemplo n.º 2
0
        private bool HasPhoneNumber()
        {
            var user = UserManager.FindById(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

            if (user != null)
            {
                return(user.PhoneNumber != null);
            }
            return(false);
        }
Exemplo n.º 3
0
        //
        // GET: /Manage/LinkLoginCallback
        public async Task <ActionResult> LinkLoginCallback()
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity).ToString());

            if (loginInfo == null)
            {
                return(RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }));
            }
            var result = await UserManager.AddLoginAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), loginInfo.Login);

            return(result.Succeeded ? RedirectToAction("ManageLogins") : RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> DisableTwoFactorAuthentication()
        {
            await UserManager.SetTwoFactorEnabledAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), false);

            var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
            }
            return(RedirectToAction("Index", "Manage"));
        }
Exemplo n.º 5
0
        //
        // GET: /Manage/RemovePhoneNumber
        public async Task <ActionResult> RemovePhoneNumber()
        {
            var result = await UserManager.SetPhoneNumberAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), null);

            if (!result.Succeeded)
            {
                return(RedirectToAction("Index", new { Message = ManageMessageId.Error }));
            }
            var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

            if (user != null)
            {
                await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
            }
            return(RedirectToAction("Index", new { Message = ManageMessageId.RemovePhoneSuccess }));
        }
Exemplo n.º 6
0
        public async Task <ActionResult> RemoveLogin(string loginProvider, string providerKey)
        {
            ManageMessageId?message;
            var             result = await UserManager.RemoveLoginAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), new UserLoginInfo(loginProvider, providerKey));

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                message = ManageMessageId.RemoveLoginSuccess;
            }
            else
            {
                message = ManageMessageId.Error;
            }
            return(RedirectToAction("ManageLogins", new { Message = message }));
        }
Exemplo n.º 7
0
        public async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var _retVal = await UserManager.ChangePasswordAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), model.OldPassword, model.NewPassword);

            if (_retVal.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(_retVal);
            return(View(model));
        }
Exemplo n.º 8
0
        public async Task <ActionResult> SetPassword(SetPasswordViewModel model)
        {
            if (ModelState.IsValid)
            {
                var result = await UserManager.AddPasswordAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), model.NewPassword);

                if (result.Succeeded)
                {
                    var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

                    if (user != null)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                    }
                    return(RedirectToAction("Index", new { Message = ManageMessageId.SetPasswordSuccess }));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Exemplo n.º 9
0
        public async Task <ActionResult> VerifyPhoneNumber(VerifyPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await UserManager.ChangePhoneNumberAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), model.PhoneNumber, model.Code);

            if (result.Succeeded)
            {
                var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

                if (user != null)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.AddPhoneSuccess }));
            }
            // If we got this far, something failed, redisplay form
            ModelState.AddModelError("", "Failed to verify phone");
            return(View(model));
        }
Exemplo n.º 10
0
        public ActionResult AddPhoneNumber(AddPhoneNumberViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // Generate token...
            try
            {
                if (this.SendOTP2Phone(UserManager, RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity), model.Number))
                {
                    return(RedirectToAction("VerifyPhoneNumber", new { PhoneNumber = model.Number }));
                }
            }
            catch (Exception ex)
            {
                AddErrors(new IdentityResult(ex.Message));
            }
            // If we reach this point, something failed, redisplay form displaying error message(s)...
            return(View(model));
        }
Exemplo n.º 11
0
        //
        // GET: /Manage/Index
        public async Task <ActionResult> Index(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var userId = RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity);
            var model  = new IndexViewModel
            {
                HasPassword       = HasPassword(),
                PhoneNumber       = await UserManager.GetPhoneNumberAsync(userId),
                TwoFactor         = await UserManager.GetTwoFactorEnabledAsync(userId),
                Logins            = await UserManager.GetLoginsAsync(userId),
                BrowserRemembered = await AuthenticationManager.TwoFactorBrowserRememberedAsync(userId.ToString())
            };

            return(View(model));
        }
Exemplo n.º 12
0
        //
        // GET: /Manage/ManageLogins
        public async Task <ActionResult> ManageLogins(ManageMessageId?message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed."
                : message == ManageMessageId.Error ? "An error has occurred."
                : "";
            var user = await UserManager.FindByIdAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

            if (user == null)
            {
                return(View("Error"));
            }
            var userLogins = await UserManager.GetLoginsAsync(RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity));

            var otherLogins = AuthenticationManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList();

            ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1;
            return(View(new ManageLoginsViewModel
            {
                CurrentLogins = userLogins,
                OtherLogins = otherLogins
            }));
        }
Exemplo n.º 13
0
 public ActionResult LinkLogin(string provider)
 {
     // Request a redirect to the external login provider to link a login for the current user
     return(new AccountController.ChallengeResult(provider, Url.Action("LinkLoginCallback", "Manage"), RBAC_ExtendedMethods_4_Principal.GetUserId(User.Identity).ToString()));
 }