Example #1
0
        public override string[] GetRolesForUser(string username)
        {
            string [] roles = new string[] { };

            MembershipPerson user = (MembershipPerson)HttpContext.Current.Cache[username];

            if (user != null)
            {
                if (user.Roles != null)
                {
                    roles = user.Roles.ToArray();
                }
            }
            else
            {
                using (var db = ConnectToDatabase())
                {
                    string sroles = db.SingleOrDefault <string>("SELECT u.roles from qb_users u WHERE u.id = @0", user.ProviderUserKey);
                    if (!string.IsNullOrEmpty(sroles))
                    {
                        roles = sroles.Split(new char[] { ',' });
                    }
                }
            }
            return(roles);
        }
        // для principal
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            MembershipPerson mp = null;

            using (var db = ConnectToDatabase())
            {
                Person        user  = null;
                List <Person> users = db.Fetch <Person, Userdb, Person>(new PersonRelator().Map, @"SELECT u.id, u.lastname, u.firstname, u.middlename, u.isadmin, u.serverlogin, u.theme, b.conn, b.auth FROM qb_users u 
                                                                                                 LEFT JOIN qb_bases b ON b.usercreate = u.id WHERE u.login = @0", username);
                if (users.Count > 0)
                {
                    user = users[0];

                    mp            = new MembershipPerson(this.Name, username, user.Id, true, user.LastLoginDate);
                    mp.IsAdmin    = user.IsAdmin;
                    mp.Lastname   = user.LastName;
                    mp.Firstname  = user.FirstName;
                    mp.Middlename = user.MiddleName;
                    mp.Theme      = user.Theme;

                    mp.Fio = user.LastName + " " + user.FirstName[0] + ".";
                    if (!string.IsNullOrEmpty(user.MiddleName))
                    {
                        mp.Fio += " " + user.MiddleName[0] + ".";
                    }

                    mp.Bases = user.Bases;

                    string roles = db.SingleOrDefault <string>("SELECT u.roles from qb_users u WHERE u.id = @0", user.Id);
                    if (!string.IsNullOrEmpty(roles))
                    {
                        mp.Roles = new List <string>(roles.Split(new char[] { ',' }));
                    }
                }
            }

            return(mp);
        }