Ejemplo n.º 1
0
 void GivenThereIsAnotherUserInTheUsersCollection()
 {
     _user02 = new User
     {
         FirstName = FirstName02,
         LastName  = LastName02,
         BirthDate = _birthDate02
     };
     UsersCollection.AddUser(_user02);
 }
Ejemplo n.º 2
0
 void GivenThereIsUserInTheUsersCollection()
 {
     _user01 = new User
     {
         FirstName = FirstName01,
         LastName  = LastName01,
         BirthDate = _birthDate01
     };
     UsersCollection.AddUser(_user01);
 }
Ejemplo n.º 3
0
        public void RemoveUserById()
        {
            UsersCollection.Clear();
            UsersCollection.AddUser(new User
            {
                FirstName = FirstName02,
                LastName  = LastName02,
                BirthDate = _birthDate02,
                City      = City02,
                Email     = Email02,
                Id        = _guid02
            });

            WhenDeletingUser(_guid02);

            ThenThereAreNoUsersFromTheUsersCollection();
        }
Ejemplo n.º 4
0
        public void GetSpecificUserById()
        {
            UsersCollection.Clear();
            UsersCollection.AddUser(new User
            {
                FirstName = FirstName02,
                LastName  = LastName02,
                BirthDate = _birthDate02,
                City      = City02,
                Email     = Email02,
                Id        = _guid02
            });

            WhenGettingUser(_guid02);

            ThenThereIsUserLoadedFromTheUsersCollection(UsersCollection.Users[0]);
        }
Ejemplo n.º 5
0
        Negotiator CreateNewOrUpdateExistingUser(string rootPath, IUser userInfo)
        {
            dynamic data = new ExpandoObject();

            data.Users = UsersCollection.Users;
            var cookies = Context.NegotiationContext.Cookies;

            if (UsersCollection.Users.All(usr => usr.Id != userInfo.Id))
            {
                UsersCollection.AddUser(userInfo);
                return(Negotiate.WithView(rootPath + "/" + Constants.ViewNameUsers).WithModel((ExpandoObject)data).WithStatusCode(HttpStatusCode.Created).WithFullNegotiation());
            }

            var existingUser = UsersCollection.Users.First(usr => usr.Id == userInfo.Id);

            UsersCollection.Users.RemoveAll(usr => usr.Id == userInfo.Id);
            UsersCollection.AddUser(userInfo);

            return(Negotiate.WithView(rootPath + "/" + Constants.ViewNameUsers).WithModel((ExpandoObject)data).WithStatusCode(HttpStatusCode.OK).WithFullNegotiation());
        }
Ejemplo n.º 6
0
        partial void BtnAdd_TouchUpInside(UIButton sender)
        {
            if (string.IsNullOrEmpty(txtFirstName.Text) || string.IsNullOrEmpty(txtLastName.Text) ||
                string.IsNullOrEmpty(txtUserName.Text) || string.IsNullOrEmpty(txtPassword.Text))
            {
                var emptyFieldAlert = UIAlertController.Create("Required Field Empty", "A required field is not entered", UIAlertControllerStyle.Alert);
                emptyFieldAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                this.PresentViewController(emptyFieldAlert, true, null);
                return;
            }

            //String validations for Password
            var hasNumber            = new Regex(@"[0-9]+");
            var hasUpperChar         = new Regex(@"[A-Z]+");
            var hasLowerChar         = new Regex(@"[a-z]+");
            var hasSymbols           = new Regex(@"[!@#$%^&*()_+=\[{\]};:<>|./?,-]");
            var isBetween5And12Chars = new Regex(@".{5,12}");

            //Length has to be between 5 and 12
            if (!isBetween5And12Chars.IsMatch(txtPassword.Text))
            {
                var passwordLengthAlert = UIAlertController.Create("Password Validation", "Password must be between 5 and 12 characters", UIAlertControllerStyle.Alert);
                passwordLengthAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                this.PresentViewController(passwordLengthAlert, true, null);
                return;
            }

            //Has atleast one number
            if (!hasNumber.IsMatch(txtPassword.Text))
            {
                var passwordLengthAlert = UIAlertController.Create("Password Validation", "Password must have atleast one number", UIAlertControllerStyle.Alert);
                passwordLengthAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                this.PresentViewController(passwordLengthAlert, true, null);
                return;
            }

            //Has atleast one letter
            if (!hasUpperChar.IsMatch(txtPassword.Text) && !hasLowerChar.IsMatch(txtPassword.Text))
            {
                var passwordLengthAlert = UIAlertController.Create("Password Validation", "Password must have atleast one letter", UIAlertControllerStyle.Alert);
                passwordLengthAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                this.PresentViewController(passwordLengthAlert, true, null);
                return;
            }

            //Cannot have special characters
            if (hasSymbols.IsMatch(txtPassword.Text))
            {
                var passwordLengthAlert = UIAlertController.Create("Password Validation", "Password cannot have special characters", UIAlertControllerStyle.Alert);
                passwordLengthAlert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Default, null));
                this.PresentViewController(passwordLengthAlert, true, null);
                return;
            }

            var newUser = new User {
                FirstName = txtFirstName.Text, LastName = txtLastName.Text, UserName = txtUserName.Text, Password = txtPassword.Text
            };

            var users = new UsersCollection();

            users.AddUser(newUser).GetAwaiter();

            NSNotificationCenter.DefaultCenter.PostNotificationName("NewUserAdded", this);

            this.DismissViewController(true, null);
        }
Ejemplo n.º 7
0
        public void addNewUser(string firstname, string lastname, string username, string email, string password, UserType userType)
        {
            User newUser = UsersCollection.CreateNewUser(firstname, lastname, email, username, password, userType);

            UsersCollection.AddUser(newUser);
        }