Ejemplo n.º 1
0
        public override string GetUserNameByEmail(string email)
        {
            MembershipUser user = MembershipUserUtility.FindUserByPredicate(p =>
                                                                            p.Email == email.Trim());

            if (user != null)
            {
                return(user.UserName);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public override System.Web.Security.MembershipUser GetUser(string username, bool userIsOnline)
        {
            // TODO: (Optional) if userIsOnline is true, then the user's last action timestamp may be updated.
            // the current db schema does not support this column.

            MembershipUser returnValue = MembershipUserUtility.FindUserByPredicate(p => p.Username == username);

            if (returnValue == null)
            {
                using (CSSDataContext db = new CSSDataContext())
                {
                    var login = Login.FindLoginByUsernameOrCallsign(db, username);

                    if (login != null)
                    {
                        returnValue = MembershipUserUtility.FindUserByPredicate(p => p.Username == login.Username);
                    }
                }
            }

            return(returnValue);
        }
Ejemplo n.º 5
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)
        {
            DataAccess.Identity identity = null;

            var connect = new Connect();

            using (var db = new DataAccess.CSSDataContext())
            {
                if (DataAccess.Login.FindLoginByUsernameOrCallsign(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 (Settings.Default.UseIPConverge == true)
                {
                    if (connect.CheckEmail(email) == false)
                    {
                        status = MembershipCreateStatus.DuplicateEmail;
                        return(null);
                    }

                    if (connect.CheckUsername(username) == false)
                    {
                        status = MembershipCreateStatus.DuplicateUserName;
                        return(null);
                    }
                }

                status = DataAccess.Identity.TryCreateIdentity(db, username, password, email, out identity);

                if (status == MembershipCreateStatus.Success)
                {
                    if (Settings.Default.UseIPConverge == true)
                    {
                        string ipAddress = "127.0.0.1";
                        if (HttpContext.Current != null)
                        {
                            ipAddress = HttpContext.Current.Request.UserHostAddress;
                        }

                        // TODO: If IP Converge is to be used ever, then working around IPC's MD5 password hashs will need to be done.
                        //if (connect.AddMember(email, username, passwordHash, ipAddress) == false)
                        //{
                        //    status = MembershipCreateStatus.ProviderError;
                        //    return null;
                        //}
                    }
                }

                db.SubmitChanges();

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

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

                        if (memebershipUser != null)
                        {
                            SendWelcomeEmail(memebershipUser);
                        }

                        return(memebershipUser);
                    }
                }
            }

            status = System.Web.Security.MembershipCreateStatus.ProviderError;
            return(null);
        }
Ejemplo n.º 6
0
 public override System.Web.Security.MembershipUser GetUser(object providerUserKey, bool userIsOnline)
 {
     // TODO: (Optional) if userIsOnline is true, then the user's last action timestamp may be updated.
     // the current db schema does not support this column.
     return(MembershipUserUtility.FindUserByPredicate(p => p.Id == Convert.ToInt32(providerUserKey)));
 }
Ejemplo n.º 7
0
 public override System.Web.Security.MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords)
 {
     return(MembershipUserUtility.FindUsersByPredicate(p => true == true, pageIndex, pageSize, out totalRecords));
 }
Ejemplo n.º 8
0
 public override System.Web.Security.MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
 {
     return(MembershipUserUtility.FindUsersByPredicate(p => SqlMethods.Like(p.Username, usernameToMatch.Trim()), pageIndex, pageSize, out totalRecords));
 }