Ejemplo n.º 1
0
        public virtual async Task <ActionResult> Roles(int roleId)
        {
            var user = await CustomUser.FindByIdAsync(User.Identity.GetUserId());

            await CustomUser.AddToRoleAsync(user.Id, Enum.GetName(typeof(DTO.Constants.RolesEnum), roleId));

            await CustomUser.AddClaimAsync(user.Id, new Claim(ClaimTypes.Role, roleId.ToString()));

            await CustomSignIn.SignInAsync(user, false, false);

            return(RedirectToAction(Mvc.Manage.Roles()));
        }
Ejemplo n.º 2
0
        public virtual async Task <ActionResult> ChangePassword(ChangePasswordViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var result = await CustomUser.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);

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

                if (user != null)
                {
                    await CustomSignIn.SignInAsync(user, isPersistent : false, rememberBrowser : false);
                }
                return(RedirectToAction("Index", new { Message = ManageMessageId.ChangePasswordSuccess }));
            }
            AddErrors(result);
            return(View(model));
        }
Ejemplo n.º 3
0
        public virtual async Task <ActionResult> VerifyCode(VerifyCodeViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // The following code protects for brute force attacks against the two factor codes.
            // If a user enters incorrect codes for a specified amount of time then the user account
            // will be locked out for a specified amount of time.
            // You can configure the account lockout settings in IdentityConfig
            var result = await CustomSignIn.TwoFactorSignInAsync(model.Provider, model.Code, isPersistent : model.RememberMe, rememberBrowser : model.RememberBrowser);

            switch (result)
            {
            case SignInStatus.Success:
                var userId = await CustomSignIn.GetVerifiedUserIdAsync().WithCurrentCulture();

                var accountBL = ServiceLocator.Current.GetInstance <IAccountBL>();
                await accountBL.ApproveVerification(Convert.ToInt32(userId));

                AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                var user = await CustomUser.FindByIdAsync(userId);

                await CustomSignIn.SignInAsync(user, model.RememberMe, model.RememberBrowser);

                return(RedirectToLocal(model.ReturnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.Failure:
            default:
                ModelState.AddModelError("", "Invalid code.");
                return(View(model));
            }
        }