예제 #1
0
        public static MembershipUser FindUserByPredicate(this Expression <Func <DataAccess.Login, bool> > predicate)
        {
            MembershipUser membershipUser = null;

            using (var db = new DataAccess.CSSDataContext())
            {
                var login = db.Logins.FirstOrDefault(predicate);

                if (login != null)
                {
                    membershipUser = MembershipUserUtility.CreateMembershipUserFromLogin(login);
                }
            }

            return(membershipUser);
        }
예제 #2
0
        public static MembershipUserCollection FindUsersByPredicate(this Expression <Func <DataAccess.Login, bool> > predicate, int pageIndex, int pageSize, out int totalRecords)
        {
            MembershipUserCollection returnValue = new MembershipUserCollection();

            totalRecords = 0;

            using (var db = new DataAccess.CSSDataContext())
            {
                var logins = db.Logins.Where(predicate);

                totalRecords = logins.Count();

                foreach (var login in logins.Skip(pageIndex * pageSize).Take(pageSize))
                {
                    returnValue.Add(MembershipUserUtility.CreateMembershipUserFromLogin(login));
                }
            }

            return(returnValue);
        }
예제 #3
0
        public override System.Web.Security.MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out System.Web.Security.MembershipCreateStatus status)
        {
            string passwordHash = Allegiance.CommunitySecuritySystem.Common.Utility.Encryption.SHA256Hash(password);

            DataAccess.Identity identity = null;

            using (var db = new DataAccess.CSSDataContext())
            {
                if (DataAccess.Login.FindLoginByUsername(db, username) != null)
                {
                    status = System.Web.Security.MembershipCreateStatus.DuplicateUserName;
                    return(null);
                }

                if (DataAccess.Alias.ListAliases(db, username).Count > 0)
                {
                    status = System.Web.Security.MembershipCreateStatus.UserRejected;
                    return(null);
                }

                if (DataAccess.Identity.TryCreateIdentity(db, username, passwordHash, email, out identity) == true)
                {
                    db.SubmitChanges();
                }

                if (identity != null)
                {
                    DataAccess.Login createdLogin = DataAccess.Login.FindLoginByUsername(db, username);

                    if (createdLogin != null)
                    {
                        status = System.Web.Security.MembershipCreateStatus.Success;
                        return(MembershipUserUtility.CreateMembershipUserFromLogin(createdLogin));
                    }
                }
            }

            status = System.Web.Security.MembershipCreateStatus.ProviderError;
            return(null);
        }