Ejemplo n.º 1
0
 public void DiscordGuildConnected(object s, DiscordGuildConnectedEventArgs e)
 {
     if (e.Guild.Id == Config.DiscordServer.GuildId)
     {
         foreach (var channel in e.Guild.Channels)
         {
             var link = Config.DiscordServer.ChannelMapping.FirstOrDefault(x => x.Discord == channel.Id);
             if (link != null)
             {
                 var users = channel.Users;
                 foreach (var user in users.Where(x => !x.Roles.Select(y => y.Name).Intersect(Config.DiscordServer.IgnoredUserRoles).Any()))
                 {
                     JoinDiscordUserToIrcChannel(user, link);
                 }
             }
         }
         foreach (var user in e.Guild.Users)
         {
             if (!DiscordUserConsideredOnline(user.Status) && UserLinks.ContainsKey(user.Username))
             {
                 UserLink thisLink = UserLinks[user.Username];
                 IrcLink.SetAway(thisLink.IrcUid, true);
             }
         }
     }
 }
Ejemplo n.º 2
0
        public UserLinks GetLinkUsers(string userKey)
        {
            UserLinks         links = new UserLinks();
            DataRowCollection rows  = getLinks(userKey, 1).Rows;

            foreach (DataRow row in rows)
            {
                object[] item   = row.ItemArray;
                UserLink usrLnk = new UserLink()
                {
                    LinkId = int.Parse(item[0].ToString()),
                    Id     = int.Parse(item[5].ToString()),
                    Key    = item[6].ToString(),
                    Name   = item[7].ToString(),
                    Status = int.Parse(item[4].ToString())
                };
                try
                {
                    Geolocation loc = new Geolocation()
                    {
                        Lat = double.Parse(item[8].ToString()),
                        Lng = double.Parse(item[9].ToString())
                    };
                    usrLnk.At = loc;
                }
                catch { }
                try
                {
                    usrLnk.On = DateTime.Parse(item[11].ToString());
                }
                catch { }
                links.Users.Add(usrLnk);
            }
            return(links);
        }
Ejemplo n.º 3
0
            protected void AddRoleIDsToUserLink()
            {
                UserLinks             linkToAdd = UserLinks.User;
                List <RoleIdentifier> RoleIDs   = new List <RoleIdentifier> {
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.Agency, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.Agency, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.SubStateRegion, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.SubStateRegion, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMSRegional, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMS, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMS, true)
                };

                LinkAccessList.Add(new LinkAccess
                {
                    RoleIdentifiers      = RoleIDs,
                    DescriptorExceptions =
                        new List <Descriptor>
                    {
                        Descriptor.OtherStaff_SHIP,
                        Descriptor.OtherStaff_NPR
                    },
                    DescriptorsAllowed = null,
                    Link = linkToAdd
                });
            }
Ejemplo n.º 4
0
 public string Post([FromBody] object uKey)
 {
     if (uKey == null)
     {
         return(Helpers.JsonSerialize(new Payload()
         {
             Rst = -1
         }));
     }
     try
     {
         UserLocLite currLogin = (UserLocLite)Helpers.JsonDesrialize(uKey.ToString(), typeof(UserLocLite));
         LinkContext dbUser    = new LinkContext();
         UserLinks   usrs      = dbUser.GetLinkUsers(currLogin.k);
         if (usrs != null)
         {
             usrs.Rst = 1;
             var output = Helpers.JsonSerialize(usrs);
             return(output);
         }
         return(Helpers.JsonSerialize(new Payload()
         {
             Rst = 0
         }));
     }
     catch (Exception ex)
     {
         return(Helpers.JsonSerialize(new Payload()
         {
             Rst = -1
         }));
     }
 }
Ejemplo n.º 5
0
        public IHttpActionResult GetProfile(int id)
        {
            User user = UserRepo.Get(id);

            user.links = UserLinks.getLinks(id, 2);
            return(Ok(user));
        }
Ejemplo n.º 6
0
            protected void AddRoleIDsToPAMFormLink()
            {
                UserLinks             linkToAdd = UserLinks.PAMForm;
                List <RoleIdentifier> RoleIDs   = new List <RoleIdentifier> {
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.Agency, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.Agency, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.SubStateRegion, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.SubStateRegion, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMS, true)
                };

                LinkAccessList.Add(new LinkAccess
                {
                    RoleIdentifiers    = RoleIDs,
                    DescriptorsAllowed = new List <Descriptor>
                    {
                        Descriptor.PresentationAndMediaStaff,
                        Descriptor.DataSubmitter,
                        Descriptor.DataEditor_Reviewer
                    },
                    DescriptorExceptions = null,
                    Link = linkToAdd
                });
            }
Ejemplo n.º 7
0
 private void PartDiscordUserFromIrcChannel(SocketGuildUser user, Channel link)
 {
     if (UserLinks.ContainsKey(user.Username))
     {
         var thisLink = UserLinks[user.Username];
         IrcLink.PartChannel(thisLink.IrcUserName, link.IRC);
         UserLinks.Remove(user.Username);
     }
 }
Ejemplo n.º 8
0
        protected bool CanViewLink(UserLinks LinkItem)
        {
            bool result = false;

            if (IsAuthenticated())
            {
                //Verify access
                var LinkAccessObject = LinkAccessBuilder.Instance.GetLinkAccessConfiguration(LinkItem);

                //Role identifier for User.
                var RoleIdentityForUser = RoleIdentifierList.Instance.GetRoleIdentifier(this.AccountInfo);

                //Get Descriptors for User
                var DescriptorsForUser = UserBLL.GetDescriptorsForUser(this.AccountInfo.UserId, null);


                //Check if the RoleIdentifiers for the Link contains RoleIdentity of the User
                var RoleIdentifersForLink = LinkAccessObject.RoleIdentifiers;
                var DescriptorsNOTAllowed = LinkAccessObject.DescriptorExceptions;
                var DescriptorsAllowed    = LinkAccessObject.DescriptorsAllowed;
                if (RoleIdentifersForLink.Contains(RoleIdentityForUser))
                {
                    //Initially, granted access because the RoleIdentity of the User
                    //DOES match the authorized RoleIdentifiers for the requested link.
                    result = true;

                    //If Descriptors that are NOT ALLOWED contains one of the the User's descriptor
                    //do not show the link
                    if (DescriptorsNOTAllowed != null)
                    {
                        foreach (var descriptor in DescriptorsNOTAllowed)
                        {
                            if (DescriptorsForUser.Contains(descriptor.EnumValue <int>()))
                            {
                                return(false);
                            }
                        }
                    }

                    //If User Descriptors
                    if (DescriptorsAllowed != null)
                    {
                        foreach (var descriptor in DescriptorsAllowed)
                        {
                            if (DescriptorsForUser.Contains(descriptor.EnumValue <int>()))
                            {
                                return(true);
                            }
                        }
                        result = false;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 9
0
        public UserLink FindUserLink(string username)
        {
            if (!UserLinks.ContainsKey(username))
            {
                // I don't know if this will ever happen, but I would like to investigate what to do here if it ever does.
                throw new System.InvalidOperationException("Discord<->Irc UserLink not established for message sender");
            }
            var thisLink = UserLinks[username];

            return(thisLink);
        }
        public IHttpActionResult Get(int id)
        {
            var user = ProductRepo.Get(id);

            if (user == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }

            user.links = UserLinks.getLinks(id, 2);
            return(Ok(ProductRepo.Get(id)));
        }
Ejemplo n.º 11
0
        public IHttpActionResult Get(int id)
        {
            var user = UserRepo.Get(id);

            if (user == null)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            //User user = UserRepo.Get(id);
            user.links = UserLinks.getLinks(id, 1);
            //return Ok(user);
            return(Ok(UserRepo.Get(id)));
        }
Ejemplo n.º 12
0
            protected void AddRoleIDsToShipProfileLink()
            {
                UserLinks             linkToAdd = UserLinks.ShipProfile;
                List <RoleIdentifier> RoleIDs   = new List <RoleIdentifier> {
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMS, true)
                };

                LinkAccessList.Add(new LinkAccess {
                    RoleIdentifiers = RoleIDs, DescriptorExceptions = null, DescriptorsAllowed = null, Link = linkToAdd
                });
            }
Ejemplo n.º 13
0
            protected void AddRoleIDsToNPRReportsLink()
            {
                UserLinks             linkToAdd = UserLinks.NPRReports;
                List <RoleIdentifier> RoleIDs   = new List <RoleIdentifier> {
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.Agency, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.Agency, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.SubStateRegion, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.SubStateRegion, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.State, false),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMS, true),
                    RoleIdentifierList.Instance.GetRoleIdentifier(Scope.CMS, false)
                };

                LinkAccessList.Add(new LinkAccess {
                    RoleIdentifiers = RoleIDs, DescriptorExceptions = null, DescriptorsAllowed = null, Link = linkToAdd
                });
            }
Ejemplo n.º 14
0
 public User(string id, DateTimeOffset updatedAt, string username, string name, string firstName, string lastName, string twitterUsername, Uri portfolioUrl, string bio, string location, UserLinks links, ProfileImage profileImage, string instagramUsername, int totalCollections, int totalLikes, int totalPhotos, bool acceptedTos)
 {
     Id                = id;
     UpdatedAt         = updatedAt;
     Username          = username;
     Name              = name;
     FirstName         = firstName;
     LastName          = lastName;
     TwitterUsername   = twitterUsername;
     PortfolioUrl      = portfolioUrl;
     Bio               = bio;
     Location          = location;
     Links             = links;
     ProfileImage      = profileImage;
     InstagramUsername = instagramUsername;
     TotalCollections  = totalCollections;
     TotalLikes        = totalLikes;
     TotalPhotos       = totalPhotos;
     AcceptedTos       = acceptedTos;
 }
Ejemplo n.º 15
0
        private void JoinDiscordUserToIrcChannel(SocketGuildUser user, Channel link)
        {
            UserLink thisLink;

            if (UserLinks.ContainsKey(user.Username))
            {
                thisLink = UserLinks[user.Username];
            }
            else
            {
                thisLink = new UserLink(Config.IRCServer.NicknameSuffix)
                {
                    BaseUserName    = user.Username,
                    DiscordUserName = user.Username,
                    DiscordUserId   = user.Id
                };
                thisLink.IrcUid = IrcLink.RegisterNick(thisLink.IrcUserName);
                UserLinks.Add(user.Username, thisLink);
            }

            IrcLink.JoinChannel(thisLink.IrcUserName, link.IRC);
        }
Ejemplo n.º 16
0
 public LinkAccess GetLinkAccessConfiguration(UserLinks linkToFind)
 {
     return(LinkAccessList.Where(l => l.Link == linkToFind).FirstOrDefault());
 }
Ejemplo n.º 17
0
 public User()
 {
     Attributes = new UserAttributes();
     Links      = new UserLinks();
 }