public HostCollection FetchAll()
 {
     HostCollection coll = new HostCollection();
     Query qry = new Query(Host.Schema);
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
示例#2
0
        public void SetUp()
        {
            userWithEmail = new User("already_exists", "123", "*****@*****.**", PasswordHashAlgorithms.Default)
            {
                Id = 123
            };
            userWithoutEmail = new User("no_email", "222", string.Empty, PasswordHashAlgorithms.Default)
            {
                Id = 321
            };
            repository = new FakeUserRepository(userWithEmail, userWithoutEmail);
            repository.Add(userWithEmail.Options);
            permissionContext   = new FakePermissionContext(new UserWithPermissionsContract(userWithEmail, ContentLanguagePreference.Default));
            stopForumSpamClient = new FakeStopForumSpamClient();
            mailer = new FakeUserMessageMailer();
            data   = new UserQueries(repository, permissionContext, new FakeEntryLinkFactory(), stopForumSpamClient, mailer,
                                     new FakeUserIconFactory(), null, new InMemoryImagePersister(), new FakeObjectCache(), new Model.Service.BrandableStrings.BrandableStringsManager(), new EnumTranslations());
            softBannedIPs = new HostCollection();

            request = new PasswordResetRequest(userWithEmail)
            {
                Id = Guid.NewGuid()
            };
            repository.Add(request);
        }
        private static DataTable GetHostNameDataTable()
        {
            try
            {
                BtsCatalogExplorer explorer = CreateBtsCatalogExplorer();

                HostCollection hosts = explorer.Hosts;

                DataTable  dt = new DataTable();
                DataColumn dc = new DataColumn();
                dc.ColumnName = "HostName";
                dt.Columns.Add(dc);

                foreach (Host item in hosts)
                {
                    DataRow dr = dt.NewRow();
                    dr["HostName"] = item.Name;
                    dt.Rows.Add(dr);
                }

                return(dt);
            }
            catch (Exception)
            {
                throw;
            }
        }
示例#4
0
        public HostCollection FetchByQuery(Query qry)
        {
            HostCollection coll = new HostCollection();

            coll.LoadAndCloseReader(qry.ExecuteReader());
            return(coll);
        }
示例#5
0
        public void SetUp()
        {
            var hashedPass = LoginManager.GetHashedPass("already_exists", "123", 0);

            userWithEmail = new User("already_exists", hashedPass, "*****@*****.**", 0)
            {
                Id = 123
            };
            userWithoutEmail = new User("no_email", "222", string.Empty, 321)
            {
                Id = 321
            };
            repository = new FakeUserRepository(userWithEmail, userWithoutEmail);
            repository.Add(userWithEmail.Options);
            permissionContext   = new FakePermissionContext(new UserWithPermissionsContract(userWithEmail, ContentLanguagePreference.Default));
            stopForumSpamClient = new FakeStopForumSpamClient();
            mailer        = new FakeUserMessageMailer();
            data          = new UserQueries(repository, permissionContext, new FakeEntryLinkFactory(), stopForumSpamClient, mailer, new FakeUserIconFactory(), new FakeObjectCache());
            softBannedIPs = new HostCollection();

            request = new PasswordResetRequest(userWithEmail)
            {
                Id = Guid.NewGuid()
            };
            repository.Add(request);
        }
示例#6
0
        public HostCollection FetchAll()
        {
            HostCollection coll = new HostCollection();
            Query          qry  = new Query(Host.Schema);

            coll.LoadAndCloseReader(qry.ExecuteReader());
            return(coll);
        }
        public void Add_ANewHost()
        {
            //ARRANGE
            DateTime DateOfBirth = new DateTime(1990, 06, 01);
            Host     newHost     = new Host("Oktay", "Çelik", DateOfBirth);
            HostCollection <Host> HostCollection = new HostCollection <Host>();
            int Expected = HostCollection.Length + 1;

            //ACT
            HostCollection.Add(newHost);
            int Actual = HostCollection.Length;

            //ASSERT
            Assert.AreEqual(Expected, Actual);
        }
        public void GetHostAt_GivenIndex0()
        {
            //ARRANGE
            DateTime DateOfBirth = new DateTime(1990, 06, 01);
            Host     newHost     = new Host("Oktay", "Çelik", DateOfBirth);
            HostCollection <Host> HostCollection = new HostCollection <Host>();

            HostCollection.Add(newHost);
            Host Expected = newHost;
            //ACT
            Host Actual = HostCollection.GetHostAt(0);

            //ASSERT
            Assert.AreEqual(Expected, Actual);
        }
 public HostCollection FetchByQuery(Query qry)
 {
     HostCollection coll = new HostCollection();
     coll.LoadAndCloseReader(qry.ExecuteReader());
     return coll;
 }
示例#10
0
 public HostCollection FetchByID(object HostID)
 {
     HostCollection coll = new HostCollection().Where("HostID", HostID).Load();
     return coll;
 }
示例#11
0
        /// <param name="name">User name. Must be unique. Cannot be null or empty.</param>
        /// <param name="pass">Password. Cannot be null or empty.</param>
        /// <param name="email">Email address. Must be unique if specified. Cannot be null.</param>
        /// <param name="hostname">Host name where the registration is from.</param>
        /// <param name="timeSpan">Time in which the user filled the registration form.</param>
        /// <param name="softbannedIPs">List of application's soft-banned IPs. Soft-banned IPs are cleared when the application restarts.</param>
        /// <param name="verifyEmailUrl">Email verification URL. Cannot be null.</param>
        /// <returns>Data contract for the created user. Cannot be null.</returns>
        /// <exception cref="InvalidEmailFormatException">If the email format was invalid.</exception>
        /// <exception cref="UserNameAlreadyExistsException">If the user name was already taken.</exception>
        /// <exception cref="UserEmailAlreadyExistsException">If the email address was already taken.</exception>
        /// <exception cref="TooFastRegistrationException">If the user registered too fast.</exception>
        public UserContract Create(string name, string pass, string email, string hostname, TimeSpan timeSpan,
                                   HostCollection softbannedIPs, string verifyEmailUrl)
        {
            ParamIs.NotNullOrEmpty(() => name);
            ParamIs.NotNullOrEmpty(() => pass);
            ParamIs.NotNull(() => email);

            if (timeSpan < TimeSpan.FromSeconds(5))
            {
                log.Warn(string.Format("Suspicious registration form fill time ({0}) from {1}.", timeSpan, hostname));

                if (timeSpan < TimeSpan.FromSeconds(2))
                {
                    softbannedIPs.Add(hostname);
                }

                throw new TooFastRegistrationException();
            }

            return(repository.HandleTransaction(ctx => {
                // Verification
                var lc = name.ToLowerInvariant();
                var existing = ctx.Query().FirstOrDefault(u => u.NameLC == lc);

                if (existing != null)
                {
                    throw new UserNameAlreadyExistsException();
                }

                if (!string.IsNullOrEmpty(email))
                {
                    ValidateEmail(email);

                    existing = ctx.Query().FirstOrDefault(u => u.Active && u.Email == email);

                    if (existing != null)
                    {
                        throw new UserEmailAlreadyExistsException();
                    }
                }

                // All ok, create user
                var sfsCheckResult = sfsClient.CallApi(hostname);
                var sfsStr = GetSFSCheckStr(sfsCheckResult);

                var salt = new Random().Next();
                var hashed = LoginManager.GetHashedPass(lc, pass, salt);
                var user = new User(name, hashed, email, salt);
                user.UpdateLastLogin(hostname);
                ctx.Save(user);

                if (sfsCheckResult != null && sfsCheckResult.Conclusion == SFSCheckResultType.Malicious)
                {
                    var report = new UserReport(user, UserReportType.MaliciousIP, null, hostname,
                                                string.Format("Confidence {0} %, Frequency {1}, Last seen {2}.",
                                                              sfsCheckResult.Confidence, sfsCheckResult.Frequency, sfsCheckResult.LastSeen.ToShortDateString()));

                    ctx.OfType <UserReport>().Save(report);

                    user.GroupId = UserGroupId.Limited;
                    ctx.Update(user);
                }

                if (!string.IsNullOrEmpty(user.Email))
                {
                    var subject = "Welcome to VocaDB, please verify your email.";
                    SendEmailVerificationRequest(ctx, user, verifyEmailUrl, subject);
                }

                ctx.AuditLogger.AuditLog(string.Format("registered from {0} in {1} (SFS check {2}).", MakeGeoIpToolLink(hostname), timeSpan, sfsStr), user);

                return new UserContract(user);
            }));
        }
示例#12
0
        public HostCollection FetchByID(object HostID)
        {
            HostCollection coll = new HostCollection().Where("HostID", HostID).Load();

            return(coll);
        }