Esempio n. 1
0
        static public List <IMessage> GetGroupMessages(CSSDataContext db, string callsign)
        {
            var messages = new List <IMessage>();
            var aliases  = Alias.ListAliases(db, callsign);

            foreach (var alias in aliases)
            {
                messages.AddRange(
                    alias.GroupMessage_Alias.Where(p => p.DateViewed == null).Select(p => (IMessage)p.GroupMessage).ToList()
                    );

                //messages.AddRange(alias.GroupMessages
                //    .Where(
                //        p => p.DateExpires <=  DateTime.Now
                //        &&	p.DateToSend >= DateTime.Now
                //        && p.GroupMessage_Alias
                //            .FirstOrDefault(r => r.Alias == alias && r.DateViewed == null) != null)
                //    .Select(q => (IMessage)q).ToList());

                foreach (var gma in alias.GroupMessage_Alias.Where(p => p.DateViewed == null && messages.Select(q => q.Id).Contains(p.GroupMessageId)))
                {
                    //if (messages.FirstOrDefault(p => p.Id == gma.GroupMessageId) != null)
                    gma.DateViewed = DateTime.Now;
                }

                db.SubmitChanges();
            }

            return(messages);
        }
        public static System.Web.Security.MembershipCreateStatus TryCreateIdentity(CSSDataContext db, string username, string password, string email, out Identity createdIdentity)
        {
            createdIdentity = null;

            if (BadWords.ContainsBadWord(username) == true)
            {
                return(System.Web.Security.MembershipCreateStatus.UserRejected);
            }

            foreach (char letter in username.ToArray())
            {
                if (Char.IsLetterOrDigit(letter) == false && letter != '_')
                {
                    return(System.Web.Security.MembershipCreateStatus.UserRejected);
                }
            }

            if (username.Length < 3 || username.Length > 17)
            {
                return(System.Web.Security.MembershipCreateStatus.UserRejected);
            }

            Identity newIdentity = new Identity();

            newIdentity.DateLastLogin             = DateTime.Now;
            newIdentity.LastGlobalMessageDelivery = DateTime.Now;

            // See if the login belongs to this user.
            var login = Login.FindLoginByUsernameOrCallsign(db, username, password);

            if (login == null)
            {
                // See if the login belongs to any user.
                if (db.Logins.FirstOrDefault(p => p.Username == username) != null)
                {
                    return(System.Web.Security.MembershipCreateStatus.DuplicateUserName);
                }

                if (db.Alias.FirstOrDefault(p => p.Callsign == username) != null)
                {
                    return(System.Web.Security.MembershipCreateStatus.DuplicateUserName);
                }

                // login is available, create a new one.
                login = new Login()
                {
                    Username    = username,
                    Password    = PasswordHash.CreateHash(password),
                    Email       = email,
                    DateCreated = DateTime.Now
                };
            }

            string callsignWithTags    = username;
            Alias  existingAlias       = null;
            var    aliasValidateResult = Alias.ValidateUsage(db, login, false, password, ref callsignWithTags, out existingAlias);

            if (aliasValidateResult == CheckAliasResult.InvalidLegacyPassword)
            {
                return(System.Web.Security.MembershipCreateStatus.InvalidPassword);
            }

            else if (Alias.ValidateUsage(db, login, false, password, ref callsignWithTags, out existingAlias) != CheckAliasResult.Available)
            {
                return(System.Web.Security.MembershipCreateStatus.InvalidUserName);
            }

            List <Alias> aliases = Alias.ListAliases(db, username);

            // Make sure no one else has this username as an alias.
            if (aliases.Count > 0)
            {
                return(System.Web.Security.MembershipCreateStatus.DuplicateUserName);
            }

            var alias = new Alias()
            {
                Callsign    = username,
                DateCreated = DateTime.Now,
                IsDefault   = true,
                IsActive    = true
            };

            login.Aliases.Add(alias);
            newIdentity.Logins.Add(login);
            login.Lobby_Logins.Add(new Lobby_Login()
            {
                Lobby = db.Lobbies.First(p => p.Name == "Production")
            });

            db.Identities.InsertOnSubmit(newIdentity);

            // Must be done by the caller.
            //db.SubmitChanges();

            createdIdentity = newIdentity;

            return(System.Web.Security.MembershipCreateStatus.Success);
        }