예제 #1
0
        public virtual async Task <IdentityResult> ConfirmPhoneNumberAsync(string userId, string code)
        {
            ApplicationUser user = await FindByIdAsync(userId);

            if (user == null)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ApplicationMessages.UserIdNotFound));
            }

            IdentityResult identityResult;

            if (!AuthyApiClient.VerifyToken(user.AuthyUserId, code).Success)
            {
                identityResult = IdentityResult.Failed(ApplicationMessages.InvalidVerificationCode);
            }
            else
            {
                IUserPhoneNumberStore <ApplicationUser, string> store = (IUserPhoneNumberStore <ApplicationUser, string>)Store;

                await store.SetPhoneNumberConfirmedAsync(user, true);

                identityResult = await UpdateAsync(user);
            }
            return(identityResult);
        }
예제 #2
0
        private IUserPhoneNumberStore <User> GetPhoneNumberStore()
        {
            IUserPhoneNumberStore <User> store = this.Store as IUserPhoneNumberStore <User>;

            if (store != null)
            {
                return(store);
            }
            throw new NotSupportedException("StoreNotIUserPhoneNumberStore");
        }
예제 #3
0
        public DiTestController(
            // the Microsoft.AspNetCore.Identity User and Role Manager classes
            RoleManager <IdentityRole> roleManager,
            UserManager <ApplicationUser> userManager,

            IIdentityDatabaseContext <ApplicationUser, IdentityRole, string> identityDatabaseContext,

            // if want to use with SOLID and Interface Segregation Principle, then can just use the specific interface that need

            // these interfaces are all implemented by UserStore
            IUserStore <ApplicationUser> userStore,
            IUserLoginStore <ApplicationUser> userLoginStore,
            IUserRoleStore <ApplicationUser> userRoleStore,
            IUserClaimStore <ApplicationUser> userClaimStore,
            IUserPasswordStore <ApplicationUser> userPasswordStore,
            IUserSecurityStampStore <ApplicationUser> userSecurityStampStore,
            IUserEmailStore <ApplicationUser> userEmailStore,
            IUserLockoutStore <ApplicationUser> userLockoutStore,
            IUserPhoneNumberStore <ApplicationUser> userPhoneNumberStore,
            IUserTwoFactorStore <ApplicationUser> userTwoFactorStore,
            IQueryableUserStore <ApplicationUser> queryableUserStore,

            // these interfaces are all implemented by RoleStore
            IRoleStore <IdentityRole> roleStore,
            IRoleClaimStore <IdentityRole> roleClaimStore,
            IQueryableRoleStore <IdentityRole> queryableRoleStore
            )
        {
            _roleManager = roleManager;
            _userManager = userManager;

            _identityDatabaseContext = identityDatabaseContext;
            _userStore              = userStore;
            _userLoginStore         = userLoginStore;
            _userRoleStore          = userRoleStore;
            _userClaimStore         = userClaimStore;
            _userPasswordStore      = userPasswordStore;
            _userSecurityStampStore = userSecurityStampStore;
            _userEmailStore         = userEmailStore;
            _userLockoutStore       = userLockoutStore;
            _userPhoneNumberStore   = userPhoneNumberStore;
            _userTwoFactorStore     = userTwoFactorStore;
            _queryableUserStore     = queryableUserStore;

            _roleStore          = roleStore;
            _roleClaimStore     = roleClaimStore;
            _queryableRoleStore = queryableRoleStore;
        }