Beispiel #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UserStoreMultiHost{TUser, TKey}"/> class.
        /// </summary>
        /// <param name="context">The <c>DbContext</c>.</param>
        /// <param name="hostId">The default host id.</param>
        public UserStoreMultiHost(DbContext context, TKey systemHostId, TKey hostId)
            : base(context)
        {
            Contract.Requires <ArgumentNullException>(context != null, "context");
            Contract.Requires <ArgumentNullException>(!systemHostId.Equals(default(TKey)), "systemHostId");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");

            this.HostId       = hostId;
            this.SystemHostId = systemHostId;
            this.UserManager  = CreateUserManager();
        }
Beispiel #2
0
        protected override void Dispose(bool disposing)
        {
            if (!this.disposed)
            {
                if (disposing)
                {
                    // TODO: cache references? if so, release them here
                    UserManager = null;

                    this.disposed = true;
                }
            }

            base.Dispose(disposing);
        }
        /// <summary>
        /// Find a user by email
        /// </summary>
        /// <typeparam name="TUser">The type of the user.</typeparam>
        /// <typeparam name="TRole">The type of the role.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TUserLogin">The type of the user login.</typeparam>
        /// <typeparam name="TUserRole">The type of the user role.</typeparam>
        /// <typeparam name="TUserClaim">The type of the user claim.</typeparam>
        /// <param name="manager">The manager.</param>
        /// <param name="hostId">The host identifier.</param>
        /// <param name="email">The email.</param>
        /// <returns></returns>
        public static TUser FindByEmail <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>(this UserManagerMultiHost <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim> manager, TKey hostId, string email)
            where TUser : IdentityUserMultiHost <TKey, TUserLogin, TUserRole, TUserClaim>, new()
            where TRole : IdentityRoleMultiHost <TKey, TUserRole>, IRoleMultiHost <TKey>, new()
            where TKey : IEquatable <TKey>
            where TUserLogin : IdentityUserLoginMultiHost <TKey>, IUserLoginMultiHost <TKey>, new()
            where TUserRole : IdentityUserRoleMultiHost <TKey>, IUserRoleMultiHost <TKey>, new()
            where TUserClaim : IdentityUserClaimMultiHost <TKey>, IUserClaimMultiHost <TKey>, new()
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");
            Contract.Requires <ArgumentNullException>(!email.IsNullOrWhiteSpace(), "email");

            return(AsyncHelper.RunSync(() => manager.FindByEmailAsync(hostId, email)));
        }
        /// <summary>
        /// Returns true if the user is in the specified role
        /// </summary>
        /// <typeparam name="TUser">The type of the user.</typeparam>
        /// <typeparam name="TRole">The type of the role.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TUserLogin">The type of the user login.</typeparam>
        /// <typeparam name="TUserRole">The type of the user role.</typeparam>
        /// <typeparam name="TUserClaim">The type of the user claim.</typeparam>
        /// <param name="manager">The manager.</param>
        /// <param name="hostId">The host identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <param name="role">The role.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">manager</exception>
        public static bool IsInRole <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>(this UserManagerMultiHost <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim> manager, TKey hostId, TKey userId, string roleName)
            where TUser : IdentityUserMultiHost <TKey, TUserLogin, TUserRole, TUserClaim>, new()
            where TRole : IdentityRoleMultiHost <TKey, TUserRole>, IRoleMultiHost <TKey>, new()
            where TKey : IEquatable <TKey>
            where TUserLogin : IdentityUserLoginMultiHost <TKey>, IUserLoginMultiHost <TKey>, new()
            where TUserRole : IdentityUserRoleMultiHost <TKey>, IUserRoleMultiHost <TKey>, new()
            where TUserClaim : IdentityUserClaimMultiHost <TKey>, IUserClaimMultiHost <TKey>, new()
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");
            Contract.Requires <ArgumentNullException>(!userId.Equals(default(TKey)), "userId");
            Contract.Requires <ArgumentNullException>(!roleName.IsNullOrWhiteSpace(), "roleName");

            return(AsyncHelper.RunSync(() => manager.IsInRoleAsync(userId, roleName)));
        }
        /// <summary>
        /// Get a users's roles
        /// </summary>
        /// <typeparam name="TUser">The type of the user.</typeparam>
        /// <typeparam name="TRole">The type of the role.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TUserLogin">The type of the user login.</typeparam>
        /// <typeparam name="TUserRole">The type of the user role.</typeparam>
        /// <typeparam name="TUserClaim">The type of the user claim.</typeparam>
        /// <param name="manager">The manager.</param>
        /// <param name="hostId">The host identifier.</param>
        /// <param name="userId">The user identifier.</param>
        /// <returns></returns>
        public static IList <string> GetRoles <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>(this UserManagerMultiHost <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim> manager, TKey hostId, TKey userId)
            where TUser : IdentityUserMultiHost <TKey, TUserLogin, TUserRole, TUserClaim>, new()
            where TRole : IdentityRoleMultiHost <TKey, TUserRole>, IRoleMultiHost <TKey>, new()
            where TKey : IEquatable <TKey>
            where TUserLogin : IdentityUserLoginMultiHost <TKey>, IUserLoginMultiHost <TKey>, new()
            where TUserRole : IdentityUserRoleMultiHost <TKey>, IUserRoleMultiHost <TKey>, new()
            where TUserClaim : IdentityUserClaimMultiHost <TKey>, IUserClaimMultiHost <TKey>, new()
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");
            Contract.Requires <ArgumentNullException>(!userId.Equals(default(TKey)), "userId");

            return(AsyncHelper.RunSync(() => manager.GetRolesAsync(hostId, userId)));
        }
        /// <summary>
        /// Sync extension
        /// </summary>
        /// <typeparam name="TUser">The type of the user.</typeparam>
        /// <typeparam name="TRole">The type of the role.</typeparam>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <typeparam name="TUserLogin">The type of the user login.</typeparam>
        /// <typeparam name="TUserRole">The type of the user role.</typeparam>
        /// <typeparam name="TUserClaim">The type of the user claim.</typeparam>
        /// <param name="manager">The manager.</param>
        /// <param name="hostId">The host identifier.</param>
        /// <param name="login">The login.</param>
        /// <returns></returns>
        public static TUser Find <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim>(this UserManagerMultiHost <TUser, TRole, TKey, TUserLogin, TUserRole, TUserClaim> manager, TKey hostId, UserLoginInfo login)
            where TUser : IdentityUserMultiHost <TKey, TUserLogin, TUserRole, TUserClaim>, new()
            where TRole : IdentityRoleMultiHost <TKey, TUserRole>, IRoleMultiHost <TKey>, new()
            where TKey : IEquatable <TKey>
            where TUserLogin : IdentityUserLoginMultiHost <TKey>, IUserLoginMultiHost <TKey>, new()
            where TUserRole : IdentityUserRoleMultiHost <TKey>, IUserRoleMultiHost <TKey>, new()
            where TUserClaim : IdentityUserClaimMultiHost <TKey>, IUserClaimMultiHost <TKey>, new()
        {
            Contract.Requires <ArgumentNullException>(manager != null, "manager");
            Contract.Requires <ArgumentNullException>(!hostId.Equals(default(TKey)), "hostId");
            Contract.Requires <ArgumentNullException>(login != null, "login");

            return(AsyncHelper.RunSync(() => manager.FindAsync(hostId, login)));
        }