Esempio n. 1
0
        /// <summary>
        /// Determines whether there exists a local account (as opposed to OAuth account) with the specified userId.
        /// </summary>
        /// <param name="userId">The user id to check for local account.</param>
        /// <returns>
        ///   <c>true</c> if there is a local account with the specified user id]; otherwise, <c>false</c>.
        /// </returns>
        public static bool HasLocalAccount(int userId)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this
            return(provider.HasLocalAccount(userId));
        }
Esempio n. 2
0
 public static bool IsAccountLockedOut(
     this ExtendedMembershipProvider provider, string userName, int allowedPasswordAttempts, TimeSpan interval)
 {
     return(provider.GetUser(userName, false) != null &&
            provider.GetPasswordFailuresSinceLastSuccess(userName) > allowedPasswordAttempts &&
            provider.GetLastPasswordFailureDate(userName).Add(interval) > DateTime.UtcNow);
 }
Esempio n. 3
0
        public static bool ResetPassword(string passwordResetToken, string newPassword)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this
            return(provider.ResetPasswordWithToken(passwordResetToken, newPassword));
        }
Esempio n. 4
0
        public static bool ConfirmAccount(string userName, string accountConfirmationToken)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this
            return(provider.ConfirmAccount(userName, accountConfirmationToken));
        }
Esempio n. 5
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    ExtendedMembershipProvider extendedMembershipProvider = Membership.Provider as ExtendedMembershipProvider;
                    //WebSecurity.InitializeDatabaseConnection("DefaultConnection", "webReg", "UserId", "Username", autoCreateTables: true);

                    //extendedMembershipProvider.CreateUserAndAccount(model.UserName, model.Password);
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password);

                    WebSecurity.Login(model.UserName, model.Password);
                    return(RedirectToAction("Index", "Home"));
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Esempio n. 6
0
        public static bool IsAccountLockedOut(string userName, int allowedPasswordAttempts, TimeSpan interval)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(IsAccountLockedOutInternal(provider, userName, allowedPasswordAttempts, interval));
        }
Esempio n. 7
0
        public static bool IsConfirmed(string userName)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(provider.IsConfirmed(userName));
        }
Esempio n. 8
0
        public static int GetUserIdFromPasswordResetToken(string token)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(provider.GetUserIdFromPasswordResetToken(token));
        }
Esempio n. 9
0
        public static string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow = 1440)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(provider.GeneratePasswordResetToken(userName, tokenExpirationInMinutesFromNow));
        }
Esempio n. 10
0
        public static string CreateAccount(string userName, string password, bool requireConfirmationToken = false)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(provider.CreateAccount(userName, password, requireConfirmationToken));
        }
Esempio n. 11
0
        public static DateTime GetLastPasswordFailureDate(string userName)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(provider.GetLastPasswordFailureDate(userName));
        }
Esempio n. 12
0
        public static int GetPasswordFailuresSinceLastSuccess(string userName)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            return(provider.GetPasswordFailuresSinceLastSuccess(userName));
        }
Esempio n. 13
0
        /// <summary>
        /// Creates or update the account with the specified provider, provider user id and associate it with the specified user name.
        /// </summary>
        /// <param name="providerName">Name of the provider.</param>
        /// <param name="providerUserId">The provider user id.</param>
        /// <param name="userName">The user name.</param>
        public static void CreateOrUpdateAccount(
            string providerName,
            string providerUserId,
            string userName
            )
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            provider.CreateOrUpdateOAuthAccount(providerName, providerUserId, userName);
        }
Esempio n. 14
0
        private static ExtendedMembershipProvider VerifyProvider()
        {
            ExtendedMembershipProvider provider = Membership.Provider as ExtendedMembershipProvider;

            if (provider == null)
            {
                throw new InvalidOperationException(WebDataResources.Security_NoExtendedMembershipProvider);
            }
            provider.VerifyInitialized(); // Have the provider verify that it's initialized (only our SimpleMembershipProvider does anything here)
            return(provider);
        }
Esempio n. 15
0
        /// <summary>
        /// Gets all OAuth &amp; OpenID accounts which are associted with the specified user name.
        /// </summary>
        /// <param name="userName">The user name.</param>
        public static ICollection <OAuthAccount> GetAccountsFromUserName(string userName)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentException(
                          String.Format(CultureInfo.CurrentCulture, WebResources.Argument_Cannot_Be_Null_Or_Empty, "userName"),
                          "userName");
            }

            ExtendedMembershipProvider provider = VerifyProvider();

            return(provider.GetAccountsForUser(userName).Select(p => new OAuthAccount(p.Provider, p.ProviderUserId)).ToList());
        }
        public string GetUserNameFromOpenAuth(string openAuthProvider, string openAuthId)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            int userId = provider.GetUserIdFromOAuth(openAuthProvider, openAuthId);

            if (userId == -1)
            {
                return(null);
            }

            return(provider.GetUserNameFromId(userId));
        }
Esempio n. 17
0
        /// <summary>
        /// Delete the specified OAuth &amp; OpenID account
        /// </summary>
        /// <param name="providerName">Name of the provider.</param>
        /// <param name="providerUserId">The provider user id.</param>
        public static bool DeleteAccount(string providerName, string providerUserId)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            string username = GetUserName(providerName, providerUserId);

            if (String.IsNullOrEmpty(username))
            {
                // account doesn't exist
                return(false);
            }

            provider.DeleteOAuthAccount(providerName, providerUserId);
            return(true);
        }
Esempio n. 18
0
        public static string CreateUserAndAccount(string userName, string password, object propertyValues = null, bool requireConfirmationToken = false)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            Debug.Assert(provider != null); // VerifyProvider checks this

            IDictionary <string, object> values = null;

            if (propertyValues != null)
            {
                values = new RouteValueDictionary(propertyValues);
            }

            return(provider.CreateUserAndAccount(userName, password, requireConfirmationToken, values));
        }
Esempio n. 19
0
        public string GetUserNameFromOpenAuth(string openAuthProvider, string openAuthId)
        {
            ExtendedMembershipProvider provider = VerifyProvider();

            if (openAuthProvider.Equals("trello", StringComparison.OrdinalIgnoreCase))
            {
                return(openAuthId);
            }

            int userId = provider.GetUserIdFromOAuth(openAuthProvider, openAuthId);

            if (userId == -1)
            {
                return(null);
            }

            return(provider.GetUserNameFromId(userId));
        }
Esempio n. 20
0
        protected BaseNotificate(IRepository repository)
        {
            RoleProvider = new MongoRoleProvider();
            Membership   = new MongoMembership();
            var config = new NameValueCollection();

            config["applicationName"]  = "InvestProject";
            config["connectionString"] = WebConfigurationManager.AppSettings["mongoServer"];
            config["database"]         = WebConfigurationManager.AppSettings["mongoBase"];
            RoleProvider.Initialize("roles", config);
            Membership = new MongoMembership();
            Membership.Initialize("MongoMembership", config);
            _protalNotification = new PortalNotificationHub();
            Client = new SmtpClient
            {
                Host                  = "smtp.gmail.com",
                Port                  = 587,
                EnableSsl             = true,
                UseDefaultCredentials = false,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                Credentials           = new NetworkCredential("*****@*****.**", "p0iuytrewq")
            };
            Repository = repository;
        }
Esempio n. 21
0
 public static bool IsAccountLockedOut(
     this ExtendedMembershipProvider provider, string userName, int allowedPasswordAttempts, int intervalSeconds)
 {
     return(IsAccountLockedOut(
                provider, userName, allowedPasswordAttempts, TimeSpan.FromSeconds(intervalSeconds)));
 }