Esempio n. 1
0
        public void ValidateUserNameTest8()
        {
            UserBR target = CreateNewUserBR();
            BusinessRuleErrorList errors = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            bool throwIfErrors           = false;

            List <string> validUserNames = new List <string>();

            //validUserNames.Add("1Mohammad.Ali.Ghaderi"); // starts with number
            validUserNames.Add("Mohammad._Ali_Ghaderi"); // has two characters ._
            validUserNames.Add("Mohammad.Ali_.Ghaderi"); // has two characters _.
            validUserNames.Add("Mohammad1234.");         // ends with .
            validUserNames.Add(".Mohammad1234");         // starts with a symbol
            validUserNames.Add("_Mohammad1234");         // starts with a symbol
            validUserNames.Add("Mohammad!Ali");          // Contains invalid symbol
            validUserNames.Add("Mohammad Ali");          // Contains invalid symbol

            for (int i = 0; i < validUserNames.Count; i++)
            {
                bool isValid = target.ValidateUserName(validUserNames[i], null, errors, fnName, throwIfErrors);
                if (isValid)
                {
                    throw new Exception(validUserNames[i] + " shouldn't be a valid user name.");
                }
            }
        }
Esempio n. 2
0
 public void DeleteUserAlertMessages()
 {
     if (!KickUserProfile.IsGuest)
     {
         UserBR.RemoveUserAlertMessages(KickUserProfile.UserID);
     }
 }
Esempio n. 3
0
        protected void BanUser_Click(object sender, EventArgs e)
        {
            this.KickPage.DemandModeratorRole();

            //this._user.Ban(this.KickPage.KickUserProfile, this.KickPage.HostProfile);
            UserBR.BanUser(this._user.UserID, this.KickPage.KickUserProfile, this.KickPage.HostProfile);
            this.KickPage.Reload();
        }
Esempio n. 4
0
 public void AddFriend(int friendID)
 {
     UserFriend.Insert(this.UserID, friendID, DateTime.Now);
     UserBR.AddUserAlertMessage(friendID,
                                Incremental.Kick.Common.Enums.AlertMessageEnum.NewFriendRequest);
     UserCache.RemoveUser(this.UserID);
     UserCache.RemoveUser(friendID);
 }
Esempio n. 5
0
        public static IKickPrincipal GetPrincipal(string username, string password)
        {
            System.Diagnostics.Trace.WriteLine("GetPrincipal " + username + " : " + password);
            string    securityToken = UserBR.AuthenticateUser(username, password);
            IIdentity identity      = new ApiIdentity(username);

            return(new AuthenticatedKickPrincipal(identity, UserCache.GetUser(securityToken)));
        }
Esempio n. 6
0
        public void CheckRulesTest()
        {
            UserBR                target = CreateNewUserBR();
            User                  user   = CreateNewUserObject();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            BusinessRuleErrorList errors = new BusinessRuleErrorList();

            target.CheckRules(user, fnName, errors);
            Assert.IsTrue(errors.Count > 5);
        }
Esempio n. 7
0
 protected void CreateAccount_Click(object sender, EventArgs e)
 {
     if (Page.IsValid)
     {
         UserBR.CreateUser(Username.Text, Email.Text, ReceiveEmailNewsletter.Checked, KickPage.HostProfile, this.KickPage.IPAddress);
         KickPage.Caption      = "Thank you";
         RegisterPanel.Visible = false;
         SuccessPanel.Visible  = true;
     }
 }
Esempio n. 8
0
        public void ValidateEmailTest6()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "*****@*****.**";
            Nullable <long>       idValue = 2;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateEmail(value, idValue, errors, fnName, throwIfErrors);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 9
0
        public void ValidateEmailTest4()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "ایمیلدرزباندیگر@دامینزباندیگر.کام";
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Insert;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateEmail(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 10
0
        public void ValidateEmailTest2()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testemailstringwithoutdomain";
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Insert;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateEmail(value, idValue, errors, fnName, throwIfErrors);
            bool expected = false;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 11
0
        public void ValidateUserNameTest2()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = TestUtils.RandomUtils.RandomUserName();
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Insert;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 12
0
        public void ValidateUserNameTest5()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testExistingUserName";
            Nullable <long>       idValue = 1;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 13
0
        public void ValidateUserNameTest9()
        {
            UserBR target = CreateNewUserBR();
            BusinessRuleErrorList errors = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            bool throwIfErrors           = true;

            for (int i = 0; i < 100; i++)
            {
                string userName = TestUtils.RandomUtils.RandomUserName();
                target.ValidateUserName(userName, null, errors, fnName, throwIfErrors);
            }
        }
Esempio n. 14
0
        public void ValidateUserNameTest3()
        {
            // we want to change a user name of a registered existing id value
            UserBR                target  = CreateNewUserBR();
            string                value   = TestUtils.RandomUtils.RandomUserName();
            Nullable <long>       idValue = 1;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;
            bool actual   = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
Esempio n. 15
0
        public void CheckRulesTest2()
        {
            UserBR target = CreateNewUserBR();

            User user = CreateNewUserObject();

            user.Email    = "*****@*****.**";
            user.UserName = "******";

            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            BusinessRuleErrorList errors = new BusinessRuleErrorList();

            target.CheckRules(user, fnName, errors);
            Assert.IsTrue(errors.Count > 3);
        }
Esempio n. 16
0
        protected void TestMe_Click(object sender, EventArgs e)
        {
            Message.Text = "";

            List <string> answers = new List <string>();

            foreach (ListItem item in checkboxList.Items)
            {
                if (item.Selected)
                {
                    answers.Add(item.Value);
                }
            }

            bool isCorrect = true;

            if (answers.Count != 5)
            {
                Message.Text = "Please select 5 answers";
                isCorrect    = false;
            }
            else
            {
                List <string> correctAnswers = new List <string>();
                correctAnswers.Add("enum");
                correctAnswers.Add("private");
                correctAnswers.Add("namespace");
                correctAnswers.Add("class");
                correctAnswers.Add("decimal");

                foreach (string correctAnswer in correctAnswers)
                {
                    if (!answers.Contains(correctAnswer))
                    {
                        Message.Text = "Incorrect Answers";
                        isCorrect    = false;
                    }
                }

                if (isCorrect)
                {
                    UserBR.UserPassedTest(this.KickUserProfile, this.HostProfile);

                    Response.Redirect(UrlFactory.CreateUrl(UrlFactory.PageName.SubmitStory));
                }
            }
        }
Esempio n. 17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = this.Request.QueryString["username"];

            //if the username and hash are correct, send a generated password
            Incremental.Kick.Dal.User user = UserBR.GetUserByUsername(username);

            int hash         = int.Parse(this.Request.QueryString["hash"]);
            int expectedHash = user.LastActiveOn.Ticks.GetHashCode();

            if (hash != expectedHash)
            {
                throw new ApplicationException("Invalid hash for ResetPassword, [" + expectedHash.ToString() + "] was expected");
            }

            UserBR.ResetPassword(user.UserID, this.HostProfile);
        }
Esempio n. 18
0
        protected void ResetPassword_Click(object sender, EventArgs e)
        {
            //send an email to the user
            try
            {
                Incremental.Kick.Dal.User userTable = UserBR.GetUserByEmail(this.Email.Text.Trim());


                //send a mail to the user with a link to change the password
                UserBR.SendPasswordResetEmail(userTable.UserID, this.KickPage.HostProfile);
                ConfirmationMessageLabel.Text = "An email has been sent to " + this.Email.Text + ", please check your mail.";
            }
            catch (Exception)
            {
                ErrorMessageLabel.Text = "Sorry, we have no account with that email address";
            }
        }
Esempio n. 19
0
        protected void ChangePassword_Click(object sender, EventArgs e)
        {
            if (this.RequiresOldPassword)
            {
                //check if the old password matches
                try {
                    UserBR.AuthenticateUser(this.KickPage.KickUserProfile.Username, OldPassword.Text);
                } catch {
                    InvalidPassword.Visible = true;
                }
            }

            //update the password for the current user
            UserBR.UpdatePassword(this.KickPage.KickUserProfile.UserID, NewPassword.Text, this.KickPage.HostProfile);

            this.SuccessPanel.Visible        = true;
            this.ChangePasswordPanel.Visible = false;
        }
Esempio n. 20
0
        public static void AddShout(User fromUser, int hostID, string message, string toUsername, int?chatID)
        {
            if (!String.IsNullOrEmpty(message) && (!fromUser.IsBanned))
            {
                Shout shout = new Shout();
                shout.HostID     = hostID;
                shout.Message    = TextHelper.EncodeAndReplaceComment(message);
                shout.FromUserID = fromUser.UserID;

                User toUser = null;
                if (!string.IsNullOrEmpty(toUsername))
                {
                    toUser         = UserCache.GetUserByUsername(toUsername);
                    shout.ToUserID = toUser.UserID;

                    //record the event as an alert
                    UserBR.AddUserAlertMessage(toUser.UserID,
                                               Incremental.Kick.Common.Enums.AlertMessageEnum.ProfileShoutComment);
                }

                if (chatID.HasValue)
                {
                    shout.ChatID = chatID;
                }

                shout.Save();

                if (!chatID.HasValue)
                {
                    if (toUser == null)
                    {
                        UserAction.RecordShout(hostID, fromUser);
                    }
                    else
                    {
                        UserAction.RecordShout(hostID, fromUser, toUser);
                    }
                }

                ShoutCache.Remove(hostID, shout.ToUserID, chatID);
            }
        }
Esempio n. 21
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (this.KickPage.KickUserProfile.IsBanned)
            //    AddWebSiteAlertMessage("flash flash-information", "NOTE: Your account has been BANNED. This is probably due to submitting spam to the site. Please contact us if you feel that this is in error.");

            //can add more web site alerts
            //such as system status/offline/scheduled outages
            //or chat sessions etc.

            UserAlerts userAlerts = new UserAlerts();

            if (this.KickPage.KickUserProfile.IsBanned)
            {
                userAlerts.AddAlertMessage("NOTE: Your account has been BANNED. This is probably due to submitting spam to the site. Please contact us if you feel that this is in error.");
            }

            userAlerts.AddAlertMessage(UserBR.UserAlertMessages(this.KickPage.KickUserProfile.UserID));

            this.phWebSiteAlert.Controls.Add(userAlerts);
        }
Esempio n. 22
0
        public void ValidateUserNameTest4()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testExistingUserName";
            Nullable <long>       idValue = null;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = false;

            try
            {
                bool actual = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
                Assert.AreNotEqual(actual, true);
            }
            catch (Exception)
            {
                Assert.AreEqual(0, errors.Count);
                // if error happened everything is fine
            }
        }
Esempio n. 23
0
        public void ValidateUserNameTest7()
        {
            UserBR target = CreateNewUserBR();
            BusinessRuleErrorList errors = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName = RuleFunctionSEnum.Insert;
            bool throwIfErrors           = true;

            List <string> validUserNames = new List <string>();

            validUserNames.Add("Mohammad.Ali.Ghaderi");
            validUserNames.Add("Mohammad_Ali_Ghaderi");
            validUserNames.Add("Mohammad1234");
            validUserNames.Add("Mohammad.Ali.Ghaderi");
            validUserNames.Add("testVerylongUsernameWithoutAnySpecialCharacter1234");

            for (int i = 0; i < validUserNames.Count; i++)
            {
                target.ValidateUserName(validUserNames[i], null, errors, fnName, throwIfErrors);
            }
        }
Esempio n. 24
0
        protected void btnChangeEmail_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                ChangeEmailPanel.Visible = false;
                if (!String.IsNullOrEmpty(Email.Text))
                {
                    Incremental.Kick.Dal.User userTable = UserBR.GetUserByEmail(Email.Text.Trim());

                    if (userTable == null)
                    {
                        Kick.Helpers.EmailHelper.SendChangedEmailEmail(Email.Text, this.KickPage.KickUserProfile.Username, this.KickPage.KickUserProfile.Email, this.KickPage.HostProfile);
                        SuccessPanel.Visible = true;
                    }
                    else
                    {
                        FailedPanel.Visible = true;
                    }
                }
            }
        }
Esempio n. 25
0
        public void ValidateUserNameTest6()
        {
            UserBR                target  = CreateNewUserBR();
            string                value   = "testExistingUserName";
            Nullable <long>       idValue = 2;
            BusinessRuleErrorList errors  = new BusinessRuleErrorList();
            RuleFunctionSEnum     fnName  = RuleFunctionSEnum.Update;
            bool throwIfErrors            = true;

            try
            {
                bool actual = target.ValidateUserName(value, idValue, errors, fnName, throwIfErrors);
            }
            catch (BRException ex)
            {
                Assert.AreEqual(BusinessErrorStrings.User.UserName_DuplicateUserName, ex.RuleErrors[0].ErrorDescription);
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 26
0
        public static bool Login(string username, string password, bool isPersistant)
        {
            string securityToken;

            try {
                securityToken = UserBR.AuthenticateUser(username, password);
            } catch (SecurityException) {
                return(false);
            }

            DateTime expiryDate = DateTime.Now;

            if (isPersistant)
            {
                expiryDate = expiryDate.AddYears(1);
            }
            else
            {
                expiryDate = expiryDate.AddDays(1);
            }

            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1, username, DateTime.Now, expiryDate, isPersistant,
                securityToken, FormsAuthentication.FormsCookiePath);

            string     encryptedTicket = FormsAuthentication.Encrypt(ticket);
            HttpCookie cookie          = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            if (isPersistant)
            {
                cookie.Expires = expiryDate;
            }

            HttpContext.Current.Response.Cookies.Add(cookie);

            return(true);
        }
Esempio n. 27
0
        protected void UpdateAdSenseID_Click(object sender, EventArgs e)
        {
            UserBR.UpdateAdSenseID(KickUserProfile.UserID, AdSenseIDTextBox.Text);

            UpdateAdSenseID.Text = "Your AdSense ID has been updated.";
        }
Esempio n. 28
0
 public void ModeratorBanUser(int userID)
 {
     DemandModeratorRole();
     UserBR.BanUser(userID, KickUserProfile, HostProfile);
 }
Esempio n. 29
0
 public void UserBRConstructorTest()
 {
     UserBR target = CreateNewUserBR();
 }