public function testInvalidPassword()
 {
     $invalidTest = array('user_id' => 1, 'username' => 'mwatney', 'password' => 'in`v4l1dP@ssW0rd!');
     $invalidUser = new User($invalidTest);
     $this->assertEquals(1, $invalidUser->getErrorCount(), 'The User object should have exactly 1 error');
     $this->assertTrue(!empty($invalidUser->getError('password')), 'The User should have a password error');
 }
 public static function run()
 {
     $user = null;
     $userIsLegit = false;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $user = new User($_POST);
         if ($user->getErrorCount() == 0) {
             $checkUserArray = UsersDB::getUsersBy('username', $user->getUserName());
             if (count($checkUserArray) > 0) {
                 $checkUser = $checkUserArray[0];
                 $user->setUserId($checkUser->getUserId());
                 $userIsLegit = password_verify($_POST['password'], $checkUser->getPassword());
             }
         }
     } else {
         LoginView::show();
         return;
     }
     if ($userIsLegit) {
         $_SESSION['authenticatedUser'] = $user;
         $_SESSION['authenticated'] = true;
         HomeView::show();
     } else {
         $user->setError('username', 'USERNAME_PASSWORD_COMBO_INVALID');
         $_SESSION['user'] = $user;
         LoginView::show();
     }
 }
 public static function run()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST);
         if ($user->getErrorCount() == 0) {
             ProfileView::show($user);
         } else {
             LoginView::show($user);
         }
     } else {
         LoginView::show(null);
     }
 }
 public static function run()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST, True);
         if ($user->getErrorCount() == 0) {
             LogController::run("In");
         } else {
             LoginView::show($user);
         }
     } else {
         LoginView::show(null);
     }
 }
 public static function run()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST);
         $userData = new UserData($_POST);
         if ($user->getErrorCount() == 0 && $userData->getErrorCount() == 0) {
             HomeView::show();
         } else {
             SignupView::show($user, $userData);
         }
     } else {
         SignupView::show(null, null);
     }
 }
 public static function run()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST);
         // What if already logged in?
         if ($user->getErrorCount() == 0) {
             UserView::show($user);
         } else {
             LoginView::show($user);
         }
     } else {
         // Initial link
         LoginView::show(null);
     }
 }
 public static function run()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         //simpleEcho.php;
         $user = new User($_POST);
         $userData = new UserData($_POST);
         //print_r($_FILES); echo '<br>';
         if ($user->getErrorCount() == 0 && $userData->getErrorCount() == 0) {
             ProfileView::show($userData);
         } else {
             SignupView::show($user, $userData);
         }
     } else {
         // Initial link
         SignupView::show(null, null);
     }
 }
 public static function run()
 {
     $user = null;
     $userData = null;
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST);
         //$dbUser = UsersDB::addUser($user);
         $userData = new UserData($_POST);
         //$_POST["userId"] = $user->getUserId();
         if ($user->getErrorCount() == 0 && $userData->getErrorCount() == 0) {
             $dbUserData = UsersDB::addUser($user, $userData);
             ProfileView::show($user, $userData);
         } else {
             SignupView::show($user, $userData);
         }
     } else {
         SignupView::show(null, null);
     }
 }
 public static function run()
 {
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST);
         if ($user->getErrorCount() != 0) {
             LoginView::show($user);
         } else {
             $users = UsersDB::getUsersBy('userName', $user->getUserName());
             if (!empty($users)) {
                 HomeView::show($users[0]);
             } else {
                 $user->setError('userName', 'USER_NAME_DOES_NOT_EXIST');
                 LoginView::show($user);
             }
         }
     } else {
         // Initial link
         LoginView::show(null);
     }
 }
Example #10
0
 public static function run()
 {
     $webuser = NULL;
     $hockuser = NULL;
     $user = NULL;
     if ($_SERVER["REQUEST_METHOD"] == "POST") {
         $user = new User($_POST);
         $webusers = WebUserDB::getUsersBy('userName', $user->getUserName());
         if (empty($webusers)) {
             $user->setError('userName', 'USER_NAME_DOES_NOT_EXIST');
         } else {
             $webuser = $webusers[0];
         }
     }
     if (!is_null($webuser)) {
         if (strcmp($webuser->getPassword(), $user->getPassword()) == 0) {
             //passwords match.
             //get associated hockuser
             echo "<p>" . $webuser . "</p>";
             $hockusers = HockUserDB::getUsersBy('name', $webuser->getHockName());
             if (empty($hockusers)) {
                 $user->setError('userName', 'HOCK_NAME_UNASSOCIATED_WITH_ACCOUNT');
             } else {
                 $hockuser = $hockusers[0];
             }
         } else {
             //Invalid password
             $user->setError('password', 'PASSWORD_INVALID');
         }
     }
     $_SESSION['user'] = $webuser;
     if (is_null($webuser) || $user->getErrorCount() != 0) {
         LoginView::show($user);
     } else {
         //show profile
         ProfileView::show($webuser, $hockuser);
         //show home
         //HomeView::show();
         //header('Location: /'.$_SESSION['base'].'/user/profile');
     }
 }
 public static function run()
 {
     $user = null;
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $formUser = new User($_POST);
         if ($formUser->getErrorCount() == 0) {
             $plaintextPassword = $formUser->getPassword();
             $hashedPassword = password_hash($plaintextPassword, PASSWORD_DEFAULT);
             $formUser->setPassword($hashedPassword);
             $user = UsersDB::addUser($formUser);
             if ($user->getErrorCount() == 0) {
                 $_SESSION['user'] = $user;
             }
         } else {
             $user = $formUser;
         }
     }
     if (is_null($user) || $user->getErrorCount() != 0) {
         SignupView::show($user);
     } else {
         ProfileView::show();
     }
 }
Example #12
0
 public function testInvalidUserName()
 {
     $invalidTest = array("userName" => "krobbins\$", "password" => "123");
     $s1 = new User($invalidTest);
     $this->assertGreaterThan(0, $s1->getErrorCount(), 'It should have an error if the user name is invalid');
 }