Esempio n. 1
0
        /// <summary>
        /// Verifies that the specified user name and password exist in the data source.
        /// </summary>
        /// <param name="username">The name of the user to validate.</param>
        /// <param name="password">The password for the specified user.</param>
        /// <returns>true if the specified username and password are valid; otherwise, false.</returns>
        public override bool ValidateUser(string username, string password)
        {
            //var md5Hash = GetMd5Hash(password);
            var usersContext = new UsersContexts();
            var requiredUser = usersContext.GetUser(username, password);

            if (requiredUser != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user.
        /// </summary>
        /// <param name="username">The name of the user to get information for.</param>
        /// <param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.</param>
        /// <returns>A MembershipUser object populated with the specified user's information from the data source.</returns>
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            var usersContext = new UsersContexts();
            var user         = usersContext.GetUser(username);

            if (user != null)
            {
                var memUser = new MembershipUser("BlogCustomMembershipProvider", username, user.UserID, user.EmailTxt.ToString(),
                                                 string.Empty, string.Empty,
                                                 true, false, DateTime.MinValue,
                                                 DateTime.MinValue,
                                                 DateTime.MinValue,
                                                 DateTime.Now, DateTime.Now);
                return(memUser);
            }   //  user.UserEmailAddress
            return(null);
        }
Esempio n. 3
0
        ///// <summary>
        ///// Gets information from the data source for a user. Provides an option to update the last-activity date/time stamp for the user.
        ///// </summary>
        ///// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
        ///// <param name="userIsOnline">true to update the last-activity date/time stamp for the user; false to return user information without updating the last-activity date/time stamp for the user.</param>
        ///// <returns>A MembershipUser object populated with the specified user's information from the data source.</returns>
        public override MembershipUser GetUser(object providerUserKey, bool userIsOnline)
        {
            db_KISDEntities objContext   = new db_KISDEntities();
            var             username     = (from u in objContext.Users where u.UserID == (long)providerUserKey select u.UserNameTxt).SingleOrDefault();
            var             usersContext = new UsersContexts();
            var             user         = usersContext.GetUser(username);

            if (user != null)
            {
                var memUser = new MembershipUser("BlogCustomMembershipProvider", username, user.UserID, user.EmailTxt.ToString(),
                                                 string.Empty, string.Empty,
                                                 true, false, DateTime.MinValue,
                                                 DateTime.MinValue,
                                                 DateTime.MinValue,
                                                 DateTime.Now, DateTime.Now);
                return(memUser);
            }   //  user.UserEmailAddress
            return(null);
        }
Esempio n. 4
0
        /// <summary>
        /// To override the CreateUser functionality of the MembershipProvider and implement of its own.
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="username">The user name for the new user.</param>
        /// <param name="password">The password for the new user.</param>
        /// <param name="email">The e-mail address for the new user.</param>
        /// <param name="passwordQuestion">The password question for the new user.</param>
        /// <param name="passwordAnswer">The password answer for the new user.</param>
        /// <param name="isApproved">Whether or not the new user is approved to be validated.</param>
        /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
        /// <param name="status">A MembershipCreateStatus enumeration value indicating whether the user was created successfully.</param>
        /// <returns>A MembershipUser object populated with the information for the newly created user.</returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            var args = new ValidatePasswordEventArgs(username, password, true);

            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return(null);
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return(null);
            }

            var user = GetUser(username, true);

            if (user == null)
            {
                var userObj = new UsersModel {
                    UserNameTxt = username, Password = GetMd5Hash(password), EmailTxt = email
                };

                var usersContext = new UsersContexts();

                usersContext.AddUser(userObj);


                status = MembershipCreateStatus.Success;

                return(GetUser(username, true));
            }
            status = MembershipCreateStatus.DuplicateUserName;

            return(null);
        }