Exemplo n.º 1
0
        public static bool TryGetAuthenticatedLogin(CSSDataContext db, string username, string password, out Login login, out LoginStatus loginStatus)
        {
            loginStatus = LoginStatus.Authenticated;

            login = Login.FindLoginByUsernameOrCallsign(db, username);

            if (login == null)
            {
                loginStatus = LoginStatus.InvalidCredentials;
            }
            else if (login.IsBanned)
            {
                loginStatus = LoginStatus.AccountLocked;
            }
            else
            {
                CssMembershipProvider provider = new CssMembershipProvider();
                if (provider.ValidateUser(login.Username, password) == false)
                {
                    loginStatus = LoginStatus.InvalidCredentials;
                }
                else
                {
                    loginStatus = LoginStatus.Authenticated;
                }
            }

            return(loginStatus == LoginStatus.Authenticated);
        }
Exemplo n.º 2
0
        public static bool HasVoted(CSSDataContext db, int optionId, string username)
        {
            var identId = Login.FindLoginByUsernameOrCallsign(db, username).IdentityId;
            var pollId  = db.PollOptions.FirstOrDefault(po => po.Id == optionId).PollId;
            var options = db.PollOptions.Where(po => po.PollId == pollId);

            foreach (PollOption option in options)
            {
                if (db.PollVotes.Any(pv => pv.PollOptionId == option.Id && pv.Login.IdentityId == identId))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 3
0
        static public List <IMessage> GetPrivateMessages(CSSDataContext db, string alias)
        {
            var id       = Login.FindLoginByUsernameOrCallsign(db, alias).Id;
            var messages = db.PersonalMessages
                           .Where(pm => pm.LoginId == id && pm.DateViewed == null &&
                                  pm.DateToSend < DateTime.Now).ToList();

            foreach (var msg in messages)
            {
                msg.DateViewed = DateTime.Now;
            }

            db.SubmitChanges();

            //return messages.Select(p => p as BaseMessage).ToList();
            return(messages.Select(p => p as IMessage).ToList());
        }
Exemplo n.º 4
0
        public static List <Alias> ListAliases(CSSDataContext db, string callsignOrUsername)
        {
            Login login = Login.FindLoginByUsernameOrCallsign(db, callsignOrUsername);

            if (login != null)
            {
                // If you want to show all aliases for this account and associated linked accounts, use this line:
                //var allAliases = login.Identity.Logins.SelectMany(p => p.Aliases);

                var allAliases = login.Aliases;
                return(allAliases.ToList());
            }
            else
            {
                return(new List <Alias>());
            }
        }
Exemplo n.º 5
0
        public static List <Poll> FindActivePolls(string alias)
        {
            using (var db = new CSSDataContext())
            {
                var options = new DataLoadOptions();
                options.LoadWith <Poll>(p => p.PollOptions);
                db.LoadOptions = options;

                var ident = Login.FindLoginByUsernameOrCallsign(db, alias).Identity;

                var polls = from p in db.Polls
                            where DateTime.Now < p.DateExpires &&
                            !p.PollOptions.Any(q => q.PollVotes.Any(w => w.Login.Identity == ident))
                            select p;

                return(polls.ToList());
            }
        }
Exemplo n.º 6
0
        public static List <Alias> ListDecoratedAliases(CSSDataContext db, string callsignOrUsername, bool useAliasLimit)
        {
            List <Alias> allAliases = ListAliases(db, callsignOrUsername);

            if (useAliasLimit == true)
            {
                Login login      = Login.FindLoginByUsernameOrCallsign(db, callsignOrUsername);
                int   aliasLimit = GetAliasLimit(db, login);

                allAliases = allAliases.OrderBy(p => p.DateCreated).Take(aliasLimit).ToList();
            }

            List <Alias> decoratedAliases = new List <Alias>();

            foreach (Alias alias in allAliases)
            {
                decoratedAliases.Add(alias);

                foreach (Group_Alias_GroupRole gagr in alias.Group_Alias_GroupRoles)
                {
                    string decoratedAlias;
                    if (String.IsNullOrEmpty(gagr.Group.Tag) == false)
                    {
                        decoratedAlias = String.Format("{0}{1}@{2}", gagr.GroupRole.Token, alias.Callsign, gagr.Group.Tag);
                    }
                    else
                    {
                        decoratedAlias = String.Format("{0}{1}", gagr.GroupRole.Token, alias.Callsign);
                    }

                    decoratedAliases.Add(new Alias()
                    {
                        Id          = alias.Id,
                        LoginId     = alias.Id,
                        Callsign    = decoratedAlias,
                        IsDefault   = false,
                        IsActive    = true,
                        DateCreated = alias.DateCreated
                    });
                }
            }

            return(decoratedAliases);
        }
Exemplo n.º 7
0
        public static IQueryable <DataAccess.Group> GetGroupsForLogin(CSSDataContext db, string username, bool squadsOnly)
        {
            var login = Login.FindLoginByUsernameOrCallsign(db, username);

            if (login != null)
            {
                var groups = db.Groups.Where(
                    p => (squadsOnly == false || p.IsSquad == true) &&
                    db.Group_Alias_GroupRoles.Where(
                        q => q.GroupId == p.Id &&
                        db.Alias.Where(
                            r => r.Id == q.AliasId &&
                            r.LoginId == login.Id
                            ).Count() > 0
                        ).Count() > 0
                    );

                return(groups);
            }

            return(new List <DataAccess.Group>().AsQueryable());
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public static int GetAliasCount(CSSDataContext db, string username)
        {
            Login login = Login.FindLoginByUsernameOrCallsign(db, username);

            return(GetAliasCount(db, login));
        }