Example #1
0
        public Stream GetUserInfo(string sitename, string identityusername)
        {
            var userNameType = QueryStringHelper.GetQueryParameterAsString("idtype", string.Empty).ToUpper();
            ISite site = GetSite(sitename);
            BBC.Dna.Users.User userInfo = new BBC.Dna.Users.User(readerCreator, dnaDiagnostic, cacheManager);
            bool foundUser = false;
            try
            {
                if (userNameType == "DNAUSERID")
                {
                    int dnaUserId = 0;
                    try
                    {
                        dnaUserId = Convert.ToInt32(identityusername);
                    }
                    catch (Exception)
                    {
                        throw ApiException.GetError(ErrorType.UserNotFound);
                    }
                    foundUser = userInfo.CreateUserFromDnaUserID(dnaUserId, site.SiteID);
                }
                else if (userNameType == "IDENTITYUSERID")
                {
                    foundUser = userInfo.CreateUserFromIdentityUserID(identityusername, site.SiteID);
                }
                else //identityusername
                {
                    foundUser = userInfo.CreateUserFromIdentityUserName(identityusername, site.SiteID);
                }

                if (!foundUser)
                {
                    throw ApiException.GetError(ErrorType.UserNotFound);
                }

            }
            catch (ApiException ex)
            {
                throw new DnaWebProtocolException(ex);
            }

            return GetOutputStream(userInfo);
        }
Example #2
0
        private User CreateTwitterUser(int siteId, string twitterUserID, string twitterScreenName, bool hasRows)
        {
            var cache = _mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains("")).Constraints(Is.Anything()).Return(false);

            var readerMembers = _mocks.DynamicMock<IDnaDataReader>();
            readerMembers.Stub(x => x.Read()).Return(true);
            readerMembers.Stub(x => x.HasRows).Return(hasRows);
            readerMembers.Stub(x => x.GetString("twitterscreenname")).Return(twitterScreenName);
            readerMembers.Stub(x => x.GetInt32("siteid")).Return(siteId);
            readerMembers.Stub(x => x.GetString("twitteruserid")).Return(twitterUserID);

            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("createnewuserfromtwitteruserid")).Return(readerMembers);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var user = new User(creator, diag, cache);
            return user;
        }
Example #3
0
        public void UserHasPrimarySiteHavingVisitedMultipleSites()
        {
            UserGroup g = new UserGroup();
            int primarySiteId = 60;
            var cache = _mocks.DynamicMock<ICacheManager>();
            cache.Stub(x => x.Contains("")).Constraints(Is.Anything()).Return(false);

            var readerMembers = _mocks.DynamicMock<IDnaDataReader>();
            readerMembers.Stub(x => x.Read()).Return(true);
            readerMembers.Stub(x => x.HasRows).Return(true);
            readerMembers.Stub(x => x.GetInt32NullAsZero("PrimarySiteId")).Return(60);

            var creator = _mocks.DynamicMock<IDnaDataReaderCreator>();
            creator.Stub(x => x.CreateDnaDataReader("finduserfromid")).Return(readerMembers);

            var diag = _mocks.DynamicMock<IDnaDiagnostics>();
            _mocks.ReplayAll();

            var user = new User(creator, diag, cache, null);
            user.CreateUserFromDnaUserID(1090501859, 60);

            

            Assert.AreEqual(primarySiteId, user.PrimarySiteId);
        }
Example #4
0
        /// <summary>
        /// With the returned data set generate the XML for the Solo Guide Entries page
        /// </summary>
        /// <param name="dataReader">Data set to turn into XML</param>
        /// <param name="skip">Number of items to skip</param>
        /// <param name="show">Number of items to show</param>
        /// <param name="action">Number of items to skip</param>
        /// <param name="userID">User ID</param>
        /// <param name="oldGroupID"></param>
        /// <param name="newGroupID"></param>
        /// <param name="refreshGroups"></param>
        private void GenerateSoloGuideEntriesXml(IDnaDataReader dataReader, int skip, int show, string action, int userID, int oldGroupID, int newGroupID, int refreshGroups)
        {
            int count = 0;

            XmlElement soloGuideEntriesUserList = AddElementTag(RootElement, "SOLOGUIDEENTRIES");
            AddAttribute(soloGuideEntriesUserList, "SKIP", skip);
            AddAttribute(soloGuideEntriesUserList, "SHOW", show);
            
            XmlElement actionXml = AddElementTag(soloGuideEntriesUserList, "ACTION");
            AddTextTag(actionXml, "ACTION", action);
            AddIntElement(actionXml, "USERID", userID);
            AddIntElement(actionXml, "OLDGROUPID", oldGroupID);
            AddIntElement(actionXml, "NEWGROUPID", newGroupID);
            AddIntElement(actionXml, "REFRESHGROUPS", refreshGroups);

            if (dataReader.HasRows)
            {
                if (dataReader.Read())
                {
                    XmlElement users = AddElementTag(soloGuideEntriesUserList, "SOLOUSERS");

                    do
                    {
                        int soloUserID = dataReader.GetInt32NullAsZero("UserID");
                        XmlElement soloEditedEntryUser = AddElementTag(users, "SOLOUSER");
                        User user = new User(InputContext);
                        user.AddUserXMLBlock(dataReader, soloUserID, soloEditedEntryUser);
                        AddIntElement(soloEditedEntryUser, "ENTRY-COUNT", dataReader.GetInt32NullAsZero("Count"));

                        count++;

                    } while (count < show && dataReader.Read());
                    if (dataReader.Read())
                    {
                        AddAttribute(soloGuideEntriesUserList, "MORE", 1);
                    }
                }
            }

            AddAttribute(soloGuideEntriesUserList, "COUNT", count);
        }
Example #5
0
        /// <summary>
        /// Generates XML for ModeratorManagement page.
        /// </summary>
        public void GenerateXml(  string groupName, int foundUserid )
        {
            XmlElement modList = AddElementTag(RootElement,"MODERATOR-LIST");
            AddAttribute(modList, "GROUPNAME", groupName);
            XmlElement sites = null;
            XmlElement classes = null;
            using ( IDnaDataReader dataReader = InputContext.CreateDnaDataReader("getfullmoderatorlist") )
            {
                dataReader.AddParameter("groupname", groupName);
                dataReader.AddParameter("userid", InputContext.ViewingUser.UserID);
                dataReader.AddParameter("founduserid", foundUserid);
                dataReader.Execute();

                int userId = 0;
                int classId = -1;
                int siteId = -1;
                while ( dataReader.Read() )
                {
                    if ( userId != dataReader.GetInt32NullAsZero("userid") )
                    {
                        userId = dataReader.GetInt32NullAsZero("userid");

                        XmlElement moderator = AddElementTag(modList, "MODERATOR");
                        User user = new User(InputContext);
                        user.AddUserXMLBlock(dataReader, userId,moderator);

                        sites = AddElementTag(moderator, "SITES");
                        classes = AddElementTag(moderator, "CLASSES");
                        classId = -1;
                        siteId = -1;
                    }

                    if ( !dataReader.IsDBNull("modclassid") )
                    {
                        // User is assigned to moderation class
                        if (classId != dataReader.GetInt32NullAsZero("modclassid"))
                        {
                            classId = dataReader.GetInt32NullAsZero("modclassid");
                            AddIntElement(classes, "CLASSID", classId);
                        }
                    }
                    else if ( !dataReader.IsDBNull("siteid") && siteId != dataReader.GetInt32NullAsZero("siteid") )
                    {
                        // User is assigned to a specific site
                        siteId = dataReader.GetInt32NullAsZero("siteid");
                        XmlElement site = AddElementTag(sites, "SITE");
                        AddAttribute(site, "SITEID", siteId);
                    }
                }
            }

            AddModerationClasses();
        }
Example #6
0
 /// <summary>
 /// Find user from email.
 /// </summary>
 /// <param name="foundUsers"></param>
 /// <param name="email"></param>
 private int FindUserFromEmail(XmlElement foundUsers, String email)
 {
     int userId = 0;
     using (IDnaDataReader reader = InputContext.CreateDnaDataReader("finduserfromemail"))
     {
         reader.AddParameter("email", email);
         reader.Execute();
         while (reader.Read())
         {
             User find = new User(InputContext);
             find.AddUserXMLBlock(reader, reader.GetInt32NullAsZero("userid"), foundUsers);
             userId = reader.GetInt32NullAsZero("userid");
         }
     }
     return userId;
 }
Example #7
0
        /// <summary>
        /// Find a user from userid.
        /// </summary>
        /// <param name="foundUsers"></param>
        /// <param name="email"></param>
        private int FindUserFromUserId(XmlElement foundUsers, String email)
        {
            int userId;
            //Search for user by userid.
            using (IDnaDataReader reader = InputContext.CreateDnaDataReader("finduserfromidwithorwithoutmasthead"))
            {
                
                if (Int32.TryParse(email, out userId))
                {
                    reader.AddParameter("userid", userId);
                    reader.AddParameter("siteid", InputContext.CurrentSite.SiteID);
                    reader.Execute();

                    while (reader.Read())
                    {
                        User find = new User(InputContext);
                        find.AddUserXMLBlock(reader, userId, foundUsers);
                        userId = reader.GetInt32NullAsZero("userid");
                    }
                }
            }
            return userId;
        }