public void Assignment_UpdateUser_Test()
        {
            //Arrange
            UserSqlDAL dao = new UserSqlDAL(ConnectionString);

            User inputUser = new User();

            inputUser.Password = "******";
            inputUser.Salt     = "NuE0Y6FonAI=";
            inputUser.Role     = "Teacher";
            inputUser.Username = "******";


            dao.CreateUser(inputUser);

            inputUser = dao.GetUser(inputUser.Username);

            inputUser.Role = "Admin";
            dao.UpdateUser(inputUser);

            //Action
            User testUser = dao.GetUser(inputUser.Username);

            //Assert
            Assert.AreEqual(testUser.Role, inputUser.Role);
        }
示例#2
0
        /// <summary>
        /// Signs the user in and saves their username in session.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool SignIn(string username, string password)
        {
            var user         = userDAL.GetUser(username);
            var hashProvider = new HashProvider();

            if (user != null && hashProvider.VerifyPasswordMatch(user.UserPassword, password, user.Salt))
            {
                Session.SetString(SessionKey, user.UserEmail);
                return(true);
            }

            return(false);
        }
        public void Assignment_DeleteUser_Test()
        {
            //Arrange
            UserSqlDAL dao = new UserSqlDAL(ConnectionString);

            User inputUser = new User();

            inputUser.Password = "******";
            inputUser.Salt     = "NuE0Y6FonAI=";
            inputUser.Role     = "Teacher";
            inputUser.Username = "******";


            dao.CreateUser(inputUser);

            int test = GetRowCount("users");

            inputUser = dao.GetUser(inputUser.Username);
            //Action
            dao.DeleteUser(inputUser);
            int result = GetRowCount("users");

            //Assert
            Assert.AreEqual(result, test - 1);
        }
        public void GetUserTest()
        {
            UserSqlDAL dal  = new UserSqlDAL(ConnectionString);
            User       user = dal.GetUser("luteMan");

            Assert.IsNotNull(user);
        }
示例#5
0
        public ActionResult Login(User model)
        {
            UserSqlDAL userDal = new UserSqlDAL(connectionString);

            User user = userDal.GetUser(model.Email);

            if (user.Email == null || user.Password != model.Password)
            {
                ModelState.AddModelError("invalid-credentials", "An invalid email or password was provided");
                return(View("Login", model));
            }

            //if user clicked on 'cards' or 'decks' before logging in, take them there now
            Session["userid"] = user.Id;
            Session["admin"]  = user.IsAdmin;
            switch (Session["anon"].ToString())
            {
            case "Cards":
                return(RedirectToAction("Index", "Card"));

            case "Decks":
                return(RedirectToAction("Index", "Deck"));

            default:
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#6
0
        public void ShouldReturnUser()
        {
            UserSqlDAL dao      = new UserSqlDAL(connectionString);
            string     username = "******";
            User       user     = dao.GetUser(username);

            Assert.AreEqual("IvoryUnclerico", user);
        }
示例#7
0
        public ActionResult CreateProfile(UserProfile userProfile)
        {
            var checkExists = userSqlDAL.GetUser(userProfile.UserEmail);

            if (checkExists != null)
            {
                return(View("CreateProfileUserNameTaken"));
            }

            var hashedPasswordAndSalt = hashProvider.HashPassword(userProfile.UserPassword);

            userProfile.UserPassword = hashedPasswordAndSalt.Password;
            userProfile.Salt         = hashedPasswordAndSalt.Salt;
            userSqlDAL.CreateUser(userProfile);
            SaveUserSession(userProfile.UserEmail);


            return(RedirectToAction("Survey", "Home")); //Jarrod: changed this to redirect to the survey, before it was going to profile and crashing because they hadnt made a profile yet
        }
示例#8
0
        public IActionResult Index()
        {
            string currentUserName = HttpContext.Session.Get <string>(USERNAMEKEY);
            User   currentUser     = userDAL.GetUser(currentUserName);

            if (currentUser.Role != "admin")
            {
                return(RedirectToAction("NotAuthorized"));
            }
            else
            {
                return(View());
            }
        }
示例#9
0
        public ActionResult Register(User model)
        {
            if (!ModelState.IsValid)
            {
                return(View("Register", model));
            }

            UserSqlDAL newUserDAL = new UserSqlDAL(connectionString);
            //attempt to retrieve provided email - cannot duplicate existing
            User newUser = newUserDAL.GetUser(model.Email);

            if (newUser.Email == null)
            {
                newUser.Email    = model.Email;
                newUser.Password = model.Password;
                if (model.DisplayName == null)
                {
                    newUser.DisplayName = model.Email.Substring(0, model.Email.IndexOf('@'));
                }
                else
                {
                    newUser.DisplayName = model.DisplayName;
                }

                newUserDAL.Register(newUser);
                User retriveUser = newUserDAL.GetUser(newUser.Email);

                Session["userid"] = retriveUser.Id;
                Session["admin"]  = retriveUser.IsAdmin;
            }
            else
            {
                ModelState.AddModelError("email-exists", "That email address exists, please contact Admin for password reset if needed.");
                return(View("Register", model));
            }
            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult Survey(Survey survey)
        {
            //    // TODO Should we move RetrieveUserSession and SaveUserSession to a helper class?
            //    // Otherwise, code is redundant
            UserProfile   userProfile   = userProfileSqlDAL.GetUser(RetrieveUserSession());
            SurveyAnswers surveyAnswers = new SurveyAnswers(userProfile.UserEmail, survey.Business1, survey.State2, survey.Experience3, survey.NetWorth4, survey.Staff5, survey.HaveOwnedBusiness6, survey.WorkStyle7, survey.Industry8, survey.Challenges9, survey.Timeframe10);

            var testIfInDb = surveyAnswerDAL.GetSurveyResult(surveyAnswers.userEmail);

            if (testIfInDb.experience == null)
            {
                surveyAnswerDAL.SaveNewSurveyResult(surveyAnswers);
            }
            else
            {
                surveyAnswerDAL.UpdateSurveyResult(surveyAnswers);
            }

            return(RedirectToAction("ViewProfile", "Profile", userProfile));
        }