Exemple #1
0
 public ActionResult EditUser(Users user)
 {
     ViewBag.Districts = new AccountsController().DistrictList();
     if (ModelState.IsValid)
     {
         int rowAffected = new UserGateway().UpdateUser(user);
         if (rowAffected > 0)
         {
             ViewBag.Success = "Site user info updated successful";
         }
         else
         {
             ViewBag.Error = "Server temporary unavailable.";
         }
     }
     else
     {
         ViewBag.Error = "Information is missing.";
     }
     return(View(user));
 }
        public void UserConfiguration_UserDNE_Fail()
        {
            var user = new UserAccount
            {
                Username        = "******",
                IsActive        = true,
                IsFirstTimeUser = false,
                RoleType        = "standard"
            };
            var expected = false;
            var actual   = false;

            using (_userGateway = new UserGateway())
            {
                UserManagementService _userManagementService = new UserManagementService(_userGateway);

                actual = _userManagementService.UpdateUser(user).Data;
            }
            //Assert
            Assert.AreEqual(expected, actual);
        }
Exemple #3
0
        public async Task can_create_find_update_and_delete_user()
        {
            UserGateway sut      = new UserGateway(TestHelpers.ConnectionString);
            string      email    = string.Format("user{0}@test.com", Guid.NewGuid());
            var         password = Guid.NewGuid().ToByteArray();

            var result = await sut.CreatePasswordUser(email, password);

            UserData user = await sut.FindById(result.Content);

            {
                Assert.That(user.Email, Is.EqualTo(email));
                Assert.That(user.Password, Is.EqualTo(password));
            }

            {
                UserData u = await sut.FindById(user.UserId);

                Assert.That(u.Email, Is.EqualTo(email));
                Assert.That(u.Password, Is.EqualTo(password));
            }

            {
                email = string.Format("user{0}@test.com", Guid.NewGuid());
                await sut.UpdateEmail(user.UserId, email);
            }

            {
                UserData u = await sut.FindById(user.UserId);

                Assert.That(u.Email, Is.EqualTo(email));
                Assert.That(u.Password, Is.EqualTo(password));
            }

            {
                await sut.Delete(user.UserId);

                Assert.That(await sut.FindById(user.UserId), Is.Null);
            }
        }
Exemple #4
0
 protected void createButton_Click(object sender, EventArgs e)
 {
     try
     {
         User aUser = new User(userNameTextBox.Text, emailTextBox.Text, passwordTextBox.Text, addressTextBox.Text);
         if (UserGateway.IsUserNameExists(aUser))
         {
             messageLabel.Text = "User Name already exists!";
         }
         else
         {
             messageLabel.Text    = UserGateway.SaveUser(aUser);
             userNameTextBox.Text = "";
             emailTextBox.Text    = "";
             addressTextBox.Text  = "";
         }
     }
     catch (Exception)
     {
         messageLabel.Text = "Registration Faild!";
     }
 }
        public async Task can_create_google_user()
        {
            UserGateway sut          = new UserGateway(TestHelpers.ConnectionString);
            string      email        = string.Format("user{0}@test.com", Guid.NewGuid());
            string      googleId     = Guid.NewGuid().ToString();
            string      refreshToken = Guid.NewGuid().ToString().Replace("-", string.Empty);

            await sut.CreateOrUpdateGoogleUser(email, googleId, refreshToken);

            UserData user = await sut.FindByEmail(email);

            Assert.That(user.GoogleRefreshToken, Is.EqualTo(refreshToken));

            refreshToken = Guid.NewGuid().ToString().Replace("-", string.Empty);
            await sut.CreateOrUpdateGoogleUser(user.Email, user.GoogleId, refreshToken);

            user = await sut.FindById(user.UserId);

            Assert.That(user.GoogleRefreshToken, Is.EqualTo(refreshToken));

            await sut.Delete(user.UserId);
        }
        public async Task can_create_github_user()
        {
            UserGateway sut         = new UserGateway(TestHelpers.ConnectionString);
            string      email       = string.Format("user{0}@test.com", Guid.NewGuid());
            int         githubId    = _random.Next(1000000, int.MaxValue);
            string      accessToken = Guid.NewGuid().ToString().Replace("-", string.Empty);

            await sut.CreateOrUpdateGithubUser(email, githubId, accessToken);

            UserData user = await sut.FindByEmail(email);

            Assert.That(user.GithubAccessToken, Is.EqualTo(accessToken));

            accessToken = Guid.NewGuid().ToString().Replace("-", string.Empty);
            await sut.CreateOrUpdateGithubUser(user.Email, user.GithubId, accessToken);

            user = await sut.FindById(user.UserId);

            Assert.That(user.GithubAccessToken, Is.EqualTo(accessToken));

            await sut.Delete(user.UserId);
        }
Exemple #7
0
        protected void btnLogin_OnClick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(TextLogin) ||
                string.IsNullOrEmpty(TextPassword))
            {
                TextError = "Не заданы логин или пароль!";
                return;
            }

            var userGate = new UserGateway(_connection);
            var user     = userGate.Auth(TextLogin, TextPassword);

            if (user == null)
            {
                TextError = "Пользователь не зарегистрирован!";
            }
            else
            {
                Session["__user"] = user;
                RedirectToDefaultPage();
            }
        }
        public async Task can_create_github_user()
        {
            UserGateway sut         = new UserGateway(TestHelpers.ConnectionString);
            string      email       = "*****@*****.**";
            int         githubId    = 124412415;
            string      accessToken = "34fe2-43g3g-34g33-3g43";

            await sut.CreateOrUpdateGithubUser(email, githubId, accessToken);

            UserData user = await sut.FindByEmail(email);

            Assert.That(user.GithubAccessToken, Is.EqualTo(accessToken));

            accessToken = "34rg2-4rg3g-34g3w-3g43";
            await sut.CreateOrUpdateGithubUser(user.Email, user.GithubId, accessToken);

            user = await sut.FindById(user.UserId);

            Assert.That(user.GithubAccessToken, Is.EqualTo(accessToken));

            await sut.Delete(user.UserId);
        }
        public void Should_ReturnFalse_When_FoodPreferencesAreNotUpdated()
        {
            // Arrange
            string username             = "******";
            var    preferencesToBeAdded = new List <string>
            {
                "Lacto-vegetarian",
                "Pescetarian",
                "Vegan"
            };
            var preferencesToBeRemoved = new List <string>
            {
                "Halal"
            };
            UserGateway gateway = new UserGateway();

            // Act
            var result = gateway.EditFoodPreferencesByUsername(username, preferencesToBeAdded, preferencesToBeRemoved);

            result.Data.Should().BeFalse();
            result.Error.Should().NotBeNull();
        }
 protected void userDropDownList_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (userDropDownList.SelectedIndex.Equals(0))  // Item in index 0 is "-Select-" and not a valid item. So must not use
     {
         errorLabel.Text           = "";
         successLabel.Text         = "";
         userCurrentTypeLabel.Text = "";
         userNameLabel.Text        = "";
         changeUserTypeButton.Text = "Change Type";
         return;
     }
     try
     {
         UserGateway     UserGatewayObject     = new UserGateway();
         EmployeeGateway EmployeeGatewayObject = new EmployeeGateway();
         Employee        employeeObject        = EmployeeGatewayObject.SelectEmployee(userDropDownList.SelectedItem.Value);
         userNameLabel.Text = employeeObject.Name;
         if (UserGatewayObject.GetUserType(userDropDownList.SelectedItem.Value).ToString() == "Admin")
         {
             userCurrentTypeLabel.Text = "Admin";
             changeUserTypeButton.Text = "Change to Normal user ";
         }
         else
         {
             userCurrentTypeLabel.Text = "Normal";
             changeUserTypeButton.Text = "Change to Admin user ";
         }
     }
     catch (SqlException sqlExceptionObj)
     {
         errorLabel.Text = sqlExceptionObj.Message;
     }
     catch (Exception exceptionObj)
     {
         errorLabel.Text = exceptionObj.Message;
     }
 }
        public void can_create_find_update_and_delete_user()
        {
            UserGateway sut   = new UserGateway(TestHelpers.ConnectionString);
            string      email = string.Format("user{0}@test.com", Guid.NewGuid());

            byte[] password = Guid.NewGuid().ToByteArray();

            sut.CreatePasswordUser(email, password);
            User user = sut.FindByEmail(email);

            {
                Assert.That(user.Email, Is.EqualTo(email));
                Assert.That(user.Password, Is.EqualTo(password));
            }

            {
                User u = sut.FindById(user.UserId);
                Assert.That(u.Email, Is.EqualTo(email));
                Assert.That(u.Password, Is.EqualTo(password));
            }

            {
                email = string.Format("user{0}@test.com", Guid.NewGuid());
                sut.UpdateEmail(user.UserId, email);
            }

            {
                User u = sut.FindById(user.UserId);
                Assert.That(u.Email, Is.EqualTo(email));
                Assert.That(u.Password, Is.EqualTo(password));
            }

            {
                sut.Delete(user.UserId);
                Assert.That(sut.FindById(user.UserId), Is.Null);
            }
        }
Exemple #12
0
    protected void logInButton_Click(object sender, EventArgs e)
    {
        string userType = null;

        try
        {
            UserGateway UserGatewayObject = new UserGateway();
            userType = UserGatewayObject.CheckUser(employeeIdDropDownList.SelectedItem.Value, passwordTextBox.Text);
        }
        catch (SqlException sqlExceptionObj)
        {
            Label4.Text = sqlExceptionObj.Message;
        }
        catch (Exception exceptionObj)
        {
            Label4.Text = exceptionObj.Message;
        }

        Session["UserType"] = userType;
        switch (userType)
        {
        case "Admin":
            Session["userID"] = employeeIdDropDownList.SelectedItem.Value;
            Response.Redirect("HomePage.aspx");
            break;

        case "Normal":
            Session["userID"] = employeeIdDropDownList.SelectedItem.Value;
            Response.Redirect("HomePage.aspx");
            break;

        default:
            Label4.Text = " Invalid Password! Please retype the Password";
            break;
        }
    }
Exemple #13
0
        /// <summary>
        /// DeleteUser deletes the user when given a username.
        /// <para>
        /// @author: Angelica Salas Tovar
        /// @update: 03/20/2018
        /// </para>
        /// </summary>
        /// <param name="username">The user that will be deleted.</param>
        /// <returns>Response Dto</returns>
        public ResponseDto <bool> DeleteUser(UserAccountDto user)
        {
            // Validation Strategy
            var usernameValidation = new UsernameValidationStrategy(user);

            // Validate data transfer object
            var result = usernameValidation.ExecuteStrategy();

            if (result.Error != null)
            {
                return(new ResponseDto <bool>
                {
                    Data = false,
                    Error = result.Error
                });
            }

            // Gateway
            using (var gateway = new UserGateway())
            {
                var gatewayResult = gateway.DeleteUser(user.Username);

                if (gatewayResult.Data == false)
                {
                    return(new ResponseDto <bool>()
                    {
                        Data = false,
                        Error = gatewayResult.Error
                    });
                }
                return(new ResponseDto <bool>
                {
                    Data = true
                });
            }
        }
Exemple #14
0
        public ResponseDto <RestaurantProfileDto> GetProfile(string token)
        {
            var tokenService = new TokenService();
            var restaurantBusinessHourDtoService = new RestaurantBusinessHourDtoService();

            // Retrieve account by username
            var userGateway = new UserGateway();

            // Call the gateway
            var userAccountResponseDto = userGateway.GetUserByUsername(tokenService.GetTokenUsername(token));

            // Retrieve restaurant profile from database
            var restaurantProfileGateway = new RestaurantProfileGateway();

            var restaurantProfileResponseDto = restaurantProfileGateway.GetRestaurantProfileById(userAccountResponseDto.Data.Id);

            // Call the RestaurantBusinessHourDtoService
            var convertedRestaurantBusinessHourDtos = restaurantBusinessHourDtoService.SetStringTimesFromDateTimes(restaurantProfileResponseDto.Data.BusinessHours);

            // Replace the BusinessHourDtos with the converted ones
            restaurantProfileResponseDto.Data.BusinessHours = convertedRestaurantBusinessHourDtos;

            return(restaurantProfileResponseDto);
        }
        /// <summary>
        /// Method to check if user is a first time user
        ///
        /// @author: Rachel Dang
        /// @updated: 04/28/18
        /// </summary>
        /// <param name="username"></param>
        /// <returns>Bool?</returns>
        private ResponseDto <bool?> CheckIfFirstTimeUser(string username)
        {
            using (var gateway = new UserGateway())
            {
                // Call gateway to get user by username
                var user = gateway.GetUserByUsername(username);

                // If user is invalid and an error occurs, return dto with error
                if (user.Error != null)
                {
                    return(new ResponseDto <bool?>
                    {
                        Data = false,
                        Error = user.Error
                    });
                }

                // Return dto with user's isFirstTimeUser value
                return(new ResponseDto <bool?>
                {
                    Data = user.Data.IsFirstTimeUser
                });
            }
        }
 public UserManagementService()
 {
     _userGateway = new UserGateway();
 }
Exemple #17
0
 public int PerManantSameAsPresentAddress(PresentAddress apresentAddress)
 {
     aUserGateway = new UserGateway();
     return(aUserGateway.PerManantSameAsPresentAddress(apresentAddress));
 }
Exemple #18
0
 public UserService(UserGateway userGateway, PasswordHasher passwordHasher)
 {
     _userGateway    = userGateway;
     _passwordHasher = passwordHasher;
 }
 public UserManagementService(UserGateway userGateway)
 {
     _userGateway = userGateway;
 }
Exemple #20
0
 public static UserGateway<User> GetUserUserGateway()
 {
     if(UserUserGateway == null)
     {
         UserUserGateway = new UserGateway<User>("Api/User");
     }
     return UserUserGateway;
 }
Exemple #21
0
 public UserGateway GetUserGateway()
 {
     return userGW != null ? userGW : userGW = new UserGateway();
 }
 public GoogleAuthenticationManager(UserService userService, UserGateway userGateway)
 {
     _userGateway = userGateway;
 }
 public TokenController(UserGateway userGateway, TokenService tokenService)
 {
     _userGateway  = userGateway;
     _tokenService = tokenService;
 }
Exemple #24
0
 public int SaveOverSeasAddress(OverSeasAddress ovAddress)
 {
     aUserGateway = new UserGateway();
     return(aUserGateway.SaveOverSeasAddress(ovAddress));
 }
        public void Should_StoreUser_When_ValidModelsArePassedIn()
        {
            // Arrange
            var userAccount = new UserAccount()
            {
                Username        = "******",
                Password        = "******",
                IsActive        = true,
                IsFirstTimeUser = false
            };
            var passwordSalt = new PasswordSalt()
            {
                Salt = "!@#$%^&*()"
            };
            var claims = new UserClaims()
            {
                Claims = new Collection <Claim>()
                {
                    new Claim("ReadIndividualProfile", "True"),
                    new Claim("UpdateIndividualProfile", "True"),
                    new Claim("ReadPreferences", "True"),
                    new Claim("UpdatePreferences", "True"),
                    new Claim("ReadBillSplitter", "True"),
                    new Claim("ReadMenu", "True"),
                    new Claim("ReadDictionary", "True"),
                    new Claim("UpdateDictionary", "True")
                }
            };
            var securityQuestions = new List <SecurityQuestion>()
            {
                new SecurityQuestion()
                {
                    Question = 1,
                    Answer   = "answer1",
                },
                new SecurityQuestion()
                {
                    Question = 2,
                    Answer   = "answer2",
                },
                new SecurityQuestion()
                {
                    Question = 3,
                    Answer   = "answer3",
                }
            };
            var securityAnswerSalts = new List <SecurityAnswerSalt>()
            {
                new SecurityAnswerSalt()
                {
                    Salt = "!Q2w#E4r"
                },
                new SecurityAnswerSalt()
                {
                    Salt = "%T6y&U8i"
                },
                new SecurityAnswerSalt()
                {
                    Salt = "&U8i(O0p"
                }
            };
            var userProfile = new UserProfile()
            {
                DisplayPicture = "www.img.com",
                DisplayName    = "displayName"
            };
            var userGateway = new UserGateway();

            // Act
            Action act = () => userGateway.StoreIndividualUser(userAccount, passwordSalt, claims, userProfile, securityQuestions, securityAnswerSalts);

            // Assert
            act.Should().NotThrow();
        }
Exemple #26
0
        public ActionResult NonConfirmUserList()
        {
            List <Users> users = new UserGateway().GetUsers(0, 1);

            return(View(users));
        }
Exemple #27
0
 public RestaurantController(RestaurantGateway restaurantGateway, UserGateway userGateway)
 {
     _restaurantGateway = restaurantGateway;
     _userGateway       = userGateway;
 }
Exemple #28
0
 public int SaveEmailAddress(EmailAddress address)
 {
     aUserGateway = new UserGateway();
     return(aUserGateway.SaveEmailAddress(address));
 }
Exemple #29
0
        public ActionResult Users()
        {
            List <Users> users = new UserGateway().GetUsers(1, 1);

            return(View(users));
        }
Exemple #30
0
 public int SaveUserEmail(UserEmail aEmail)
 {
     aUserGateway = new UserGateway();
     return(aUserGateway.SaveUserEmail(aEmail));
 }
 public SpotifyAuthenticationManager(UserGateway userGateway)
 {
     _userGateway = userGateway;
 }
 public int SaveUser(User aUser)
 {
     aGateway = new UserGateway();
     return(aGateway.SaveUser(aUser));
 }