public static function updateUser()
 {
     // Process updating of user information
     $users = UsersDB::getUsersBy('userId', $_SESSION['arguments']);
     if (empty($users)) {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
         $_SESSION['users'] = $users;
         UserView::showUpdate();
     } else {
         $parms = $users[0]->getParameters();
         $parms['userName'] = array_key_exists('userName', $_POST) ? $_POST['userName'] : "";
         $parms['password'] = array_key_exists('password', $_POST) ? $_POST['password'] : "";
         $newUser = new User($parms);
         $newUser->setUserId($users[0]->getUserId());
         $user = UsersDB::updateUser($newUser);
         if ($user->getErrorCount() != 0) {
             $_SESSION['users'] = array($newUser);
             return;
             UserView::showUpdate();
         } else {
             HomeView::show();
             header('Location: /' . $_SESSION['base']);
         }
     }
 }
 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();
     }
 }
 private function updateUser($userId)
 {
     $users = UsersDB::getUsersBy('user_id', $userId);
     if (empty($users)) {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } else {
         if ($_SERVER['REQUEST_METHOD'] == 'GET') {
             $_SESSION['user'] = $users[0];
             UserView::showUpdate();
         } else {
             $params = $users[0]->getParameters();
             $params['username'] = array_key_exists('username', $_POST) ? $_POST['username'] : "";
             $params['password'] = array_key_exists('password', $_POST) ? $_POST['password'] : "";
             $updatedUser = new User($params);
             $updatedUser->setUserId($users[0]->getUserId());
             $plaintextPassword = $updatedUser->getPassword();
             $hashedPassword = password_hash($plaintextPassword, PASSWORD_DEFAULT);
             $updatedUser->setPassword($hashedPassword);
             $returnedUser = UsersDB::updateUser($updatedUser);
             if ($returnedUser->getErrorCount() == 0) {
                 // TODO: Log out the current user before diplaying the HomeView; LogoutController::LogoutCurrentUser()
                 HomeView::show();
                 header('Location: /' . $_SESSION['base']);
             } else {
                 $_SESSION['user'] = $updatedUser;
                 UserView::showUpdate();
             }
         }
     }
 }
 function getUserForID($userId)
 {
     $user = new User();
     ini_set('display_errors', 'On');
     $db = "w4111c.cs.columbia.edu:1521/adb";
     $conn = oci_connect("kpg2108", "test123", $db);
     $stmt = oci_parse($conn, "select * from users where user_Id='" . $userId . "'");
     $rows = oci_execute($stmt);
     oci_close($conn);
     while ($row = oci_fetch_assoc($stmt)) {
         echo $row['LOGIN_ID'];
         $user->setUserId($row['USER_ID']);
         $user->setPassword($row['PASSWORD']);
         $user->setFirstName($row['FNAME']);
         $user->setLastName($row['LNAME']);
         $user->setLoginId($row['LOGIN_ID']);
         $user->setEmailId($row['EMAIL_ID']);
         $user->setAddress($row['ADDRESS']);
         $user->setPhoneNumber($row['PHONE_NO']);
         $user->setSecurityAnswer($row['ANSWER']);
         $user->setSecurityQuestion($row['QUESTION']);
         $user->setMiles($row['MILES']);
     }
     return $user;
 }
 private function changeRole()
 {
     $userId = $this->requestParameter['userId'];
     if ($this->requestParameter['submit']) {
         $objUser = new User();
         $objUser->setUserId($this->requestParameter['userId']);
         $objUser->setRole($this->requestParameter['role']);
         $this->objUserManager->editUser($objUser);
         echo json_encode(array('userId' => $userId));
     }
 }
 public static function add(User $user)
 {
     $insertUser = Db::pdoConnect()->prepare("INSERT INTO user SET full_name=:fullname, user_password=:user_password, user_email=:user_email");
     $insertUser->bindValue(':fullname', $user->getFullName(), PDO::PARAM_STR);
     $insertUser->bindValue(':user_password', $user->getPassword(), PDO::PARAM_STR);
     $insertUser->bindValue(':user_email', $user->getUserEmail(), PDO::PARAM_STR);
     $insertUser->execute();
     $lastId = Db::pdoConnect()->lastInsertId();
     $user->setUserId($lastId);
     return $user;
 }
Example #7
0
 public function testUpdateUser()
 {
     // Test show the update
     ob_start();
     $user = new User(array("userName" => "Kay", "password" => "xxx"));
     $user->setUserId(1);
     $_SESSION = array('users' => array($user), 'base' => "mvcdbcrud");
     UserView::showUpdate();
     $output = ob_get_clean();
     $this->assertFalse(empty($output), "It should show the user update form");
 }
Example #8
0
 public static function getUsersArray($rowSets)
 {
     // Returns an array of User objects extracted from $rowSets
     $users = array();
     if (!empty($rowSets)) {
         foreach ($rowSets as $userRow) {
             $user = new User($userRow);
             $user->setUserId($userRow['userID']);
             array_push($users, $user);
         }
     }
     return $users;
 }
 public static function getUsersArray($rowSets)
 {
     $users = array();
     if (!empty($rowSets)) {
         // Convert the array of arrays into an array of Users
         foreach ($rowSets as $userRow) {
             $user = new User($userRow);
             $user->setUserId($userRow['userId']);
             array_push($users, $user);
         }
     }
     return $users;
 }
Example #10
0
 public static function mapResult($result)
 {
     $config = DataAccessConfig::userData();
     $userId = (int) $result[$config->id];
     $email = $result[$config->email];
     $pin = $result[$config->pin];
     $name = $result[$config->name];
     $birthday = new DateTime($result[$config->birthday]);
     $user = new User($email, $pin);
     $user->setUserId($userId);
     $user->setPin($pin);
     $user->setName($name);
     $user->setBirthday($birthday);
     return $user;
 }
 public function testUpdateUserEmail()
 {
     $myDB = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $testUserId = 1;
     $users = UsersDB::getUsersBy('userId', $testUserId);
     $user = $users[0];
     $params = $user->getParameters();
     $this->assertEquals($user->getEmail(), '*****@*****.**', 'Before the update it should have email bjabituya@yahoo.com');
     $params['email'] = '*****@*****.**';
     $newUser = new User($params);
     $newUser->setUserId($testUserId);
     $user = UsersDB::updateUser($newUser);
     $this->assertEquals($user->getEmail(), '*****@*****.**', 'After the update it should have email bjabituya2000@yahoo.com');
     $this->assertTrue(empty($user->getErrors()), 'The updated user should have no errors');
 }
Example #12
0
 public function testUpdateUserName()
 {
     // Test the update of the userName
     $myDb = DBMaker::create('ptest');
     Database::clearDB();
     $db = Database::getDB('ptest', 'C:\\xampp\\myConfig.ini');
     $users = UsersDB::getUsersBy('userId', 1);
     $user = $users[0];
     $parms = $user->getParameters();
     $this->assertEquals($user->getUserName(), 'Kay', 'Before the update it should have user name Kay');
     $parms['userName'] = '******';
     $newUser = new User($parms);
     $newUser->setUserId(1);
     $user = UsersDB::updateUser($newUser);
     $this->assertEquals($user->getUserName(), 'Kay1', 'Before the update it should have user name Kay1');
     $this->assertTrue(empty($user->getErrors()), 'The updated user should not have errors');
 }
Example #13
0
 public function selectAll()
 {
     $resultArrayWithUsers = array();
     $db = Connection::getConnection();
     $rows = $db->query("SELECT * FROM `users`");
     $count = 0;
     while ($row = $rows->fetch(PDO::FETCH_ASSOC)) {
         $user = new User();
         $user->setLogin($row[User::$LOGIN]);
         $user->setPassword($row[User::$PASSWORD]);
         $user->setUserId($row[User::$USER_ID]);
         $resultArrayWithUsers[$count] = $user;
         $count++;
     }
     Connection::close();
     return $resultArrayWithUsers;
 }
 public function execute($filterChain)
 {
     if (isset($_SESSION['isAdmin']) && $_SESSION['isAdmin'] == "Yes") {
         $userRoleArray['isAdmin'] = true;
     } else {
         $userRoleArray['isAdmin'] = false;
     }
     if (isset($_SESSION['isSupervisor'])) {
         $userRoleArray['isSupervisor'] = $_SESSION['isSupervisor'];
     }
     if (isset($_SESSION['isHiringManager'])) {
         $userRoleArray['isHiringManager'] = $_SESSION['isHiringManager'];
     }
     if (isset($_SESSION['isInterviewer'])) {
         $userRoleArray['isInterviewer'] = $_SESSION['isInterviewer'];
     }
     if (isset($_SESSION['empNumber']) && $_SESSION['empNumber'] == null) {
         $userRoleArray['isEssUser'] = false;
     } else {
         $userRoleArray['isEssUser'] = true;
     }
     if (isset($_SESSION['isProjectAdmin']) && $_SESSION['isProjectAdmin']) {
         $userRoleArray['isProjectAdmin'] = true;
     } else {
         $userRoleArray['isProjectAdmin'] = false;
     }
     $userObj = new User();
     if (isset($_SESSION['empNumber'])) {
         $userObj->setEmployeeNumber($_SESSION['empNumber']);
     }
     if (isset($_SESSION['user'])) {
         $userObj->setUserId($_SESSION['user']);
     }
     if (isset($_SESSION['userTimeZoneOffset'])) {
         $userObj->setUserTimeZoneOffset($_SESSION['userTimeZoneOffset']);
     } else {
         $userObj->setUserTimeZoneOffset(0);
     }
     $simpleUserRoleFactory = new SimpleUserRoleFactory();
     $decoratedUser = $simpleUserRoleFactory->decorateUserRole($userObj, $userRoleArray);
     $this->getContext()->getUser()->setAttribute("user", $decoratedUser);
     $filterChain->execute();
 }
 public function update()
 {
     $userId = $this->registry->request->getParam("userId");
     $name = $this->registry->request->getParam("name");
     $email = $this->registry->request->getParam("email");
     $pin = $this->registry->request->getParam("pin");
     $birthday = new DateTime($this->registry->request->getParam("birthday"));
     $updatedUser = new User($email, $pin);
     $updatedUser->setName($name);
     $updatedUser->setBirthday($birthday);
     $updatedUser->setUserId((int) $userId);
     $userDao = new UserDAO();
     try {
         $userDao->updateUser($updatedUser);
         $_SESSION[AppConstants::SESSION_USER] = $email;
         $_SESSION[AppConstants::SESSION_PASSWORD] = $pin;
         Mailman::sendNoticeOfUpdatedUser($updatedUser);
         $this->redirect("/account?success=" . MessageConfig::USER_UPDATE_SUCCESS);
     } catch (Exception $e) {
         $this->redirect("/account?error=" . $e->getMessage());
     }
 }
Example #16
0
 public static function map(User $user, array $properties)
 {
     if (array_key_exists('userId', $properties)) {
         $user->setUserId($properties['userId']);
     }
     if (array_key_exists('password', $properties)) {
         $user->setPassword($properties['password']);
     }
     if (array_key_exists('name', $properties)) {
         $user->setName($properties['name']);
     }
     if (array_key_exists('gender', $properties)) {
         $user->setGender($properties['gender']);
     }
     if (array_key_exists('telephone', $properties)) {
         $user->setTelephone($properties['telephone']);
     }
     if (array_key_exists('email', $properties)) {
         $user->setEmail($properties['email']);
     }
     if (array_key_exists('avatar', $properties)) {
         $user->setAvatar($properties['avatar']);
     }
     if (array_key_exists('slogan', $properties)) {
         $user->setSlogan($properties['slogan']);
     }
     if (array_key_exists('birthday', $properties)) {
         $user->setBirthday($properties['birthday']);
     }
     if (array_key_exists('createdAt', $properties)) {
         $tempCreatedAt = DateTransform::createDate($properties['createdAt']);
         if ($tempCreatedAt) {
             $user->setCreatedAt($tempCreatedAt);
         }
     }
     if (array_key_exists('character', $properties)) {
         $user->setCharacter($properties['character']);
     }
 }
<?php

include_once "../class/User.php";
$delUser = new User();
$userId = $_GET["userId"];
$delUser->setUserId($userId);
$delUser->delUser();
 $validator->addValidation("loginName", "alnum", "Please fill only alphanumeric characters for login name.");
 $validator->addValidation("firstName", "req", "Please fill in first name");
 $validator->addValidation("firstName", "alpha", "Please fill only aplphabets for first name");
 $validator->addValidation("lastName", "req", "Please fill in last name");
 $validator->addValidation("lastName", "alpha", "Please fill only alphabets for last name");
 $validator->addValidation("address", "req", "Please fill in address");
 $validator->addValidation("phoneNo", "req", "Please fill in phone number");
 $validator->addValidation("phoneNo", "numeric", "Please fill only numeric values for phone number");
 $validator->addValidation("passwordRecoveryQues", "req", "Please fill in password recovery question");
 $validator->addValidation("passwordRecoveryAns", "req", "Please fill in password recovery answer");
 $validator->addValidation("email", "email", "The input for email should be a valid email value");
 $validator->addValidation("email", "req", "Please fill in email");
 if ($validator->ValidateForm()) {
     $_SESSION['action'] = "updateUser";
     $user = new User();
     $user->setUserId($_SESSION['userId']);
     $user->setLoginId($user1->getLoginId());
     $user->setPassword($_REQUEST["password"]);
     $user->setFirstName($_REQUEST["firstName"]);
     $user->setLastName($_REQUEST["lastName"]);
     $user->setEmailId($_REQUEST["email"]);
     $user->setAddress($_REQUEST["address"]);
     $user->setPhoneNumber($_REQUEST["phoneNo"]);
     $user->setSecurityAnswer($_REQUEST["passwordRecoveryQues"]);
     $user->setSecurityQuestion($_REQUEST["passwordRecoveryAns"]);
     $_SESSION['userToBeUpdated'] = serialize($user);
     header("Location: ../controller/Controller.php");
 } else {
     echo "<B>Validation Errors:</B>";
     $error_hash = $validator->GetErrors();
     foreach ($error_hash as $inpname => $inp_err) {
 public function testUpdateUsername()
 {
     $myDb = DBMaker::create('sensordatarepotest');
     Database::clearDB();
     $db = Database::getDB('sensordatarepotest', 'C:\\xampp\\myConfig.ini');
     $testUserId = 1;
     $users = UsersDB::getUsersBy('user_id', $testUserId);
     $user = $users[0];
     $params = $user->getParameters();
     $this->assertEquals($user->getUsername(), 'jabituya', 'Before the update is should have username jabituya');
     $params['username'] = '******';
     $newUser = new User($params);
     $newUser->setUserId($testUserId);
     $updatedUser = UsersDB::updateUser($newUser);
     $this->assertEquals($updatedUser->getUsername(), $params['username'], 'After the update it should have username ' . $params['username']);
     $this->assertTrue(empty($updatedUser->getErrors()), 'The updated user should have no errors');
 }
Example #20
0
    echo "No User with this telephone number";
} else {
    echo "The value of User with a specified telephone number is:<br>{$user}<br>";
}
?>

<h2>It should get a user name by user id</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$userNames = UsersDB::getUserValuesBy('userName', 'userId', 1);
print_r($userNames);
?>
<h2>It should allow update of the user name</h2>
<?php 
DBMaker::create('ptest');
Database::clearDB();
$db = Database::getDB('ptest');
$users = UsersDB::getUsersBy('userId', 1);
$user = $users[0];
echo "<br>Before update: {$user} <br>";
$parms = $user->getParameters();
$parms['userName'] = '******';
$newUser = new User($parms);
$newUser->setUserId(1);
$user = UsersDB::updateUser($newUser);
echo "<br>After update: {$user} <br>";
?>
</body>
</html>
Example #21
0
 public function getUsers()
 {
     $connection = parent::connect();
     $selectSQL = "SELECT * FROM USER";
     $rows = $connection->query($selectSQL);
     $users = array();
     foreach ($rows as $row) {
         $user = new User();
         $user->setUserId($row[0]);
         $user->setUserName($row[1]);
         $user->setPassword($row[2]);
         $users[] = $user;
     }
     parent::disconnect($connection);
     return $users;
 }
Example #22
0
 public function testSetChain()
 {
     $user = new User();
     $this->assertEquals(TRUE, $user->setUserId(2) instanceof User);
 }
Example #23
0
$validTest = array("userName" => "krobbins", "password" => "xxx");
$_SESSION = array('user' => new User($validTest), 'base' => 'mvcdbcrud');
$validSubmission = array("submitterName" => "krobbins", "assignmentNumber" => "1", "submissionFile" => "myText.apl");
$_SESSION['userSubmissions'] = array(new Submission($validSubmission));
$input = array("reviewerName" => "krobbins", "submissionID" => 2, "score" => "5", "review" => "This was a great presentation");
$_SESSION['userReviews'] = array(new Review($input));
UserView::show();
?>

<h2>It should show all users when the session variable is set</h2>
<?php 
$s1 = new User(array("userName" => "Kay", "password" => "xxx"));
$s1->setUserId(1);
$s2 = new User(array("userName" => "John", "password" => "yyy"));
$s2->setUserId(2);
$_SESSION = array('users' => array($s1, $s2), 'base' => 'mvcdbdcrud', 'arguments' => null);
UserView::showall();
?>

<h2>It should allow updating when a valid user is passed</h2>
<?php 
$validTest = array("userName" => "Kay", "password" => "xxx");
$user = new User($validTest);
$user->setUserId(1);
echo $user;
$_SESSION = array('users' => array($user), 'base' => "mvcdbcrud");
UserView::showUpdate();
?>
</body>
</html>
Example #24
0
 private function getUser($selectResult)
 {
     $User = new User();
     $count = 0;
     while ($list = mysqli_fetch_assoc($selectResult)) {
         $User->setUserId($list['usr_user_id']);
         $User->setFirstName($list['usr_first_name']);
         $User->setLastName($list['usr_last_name']);
         $User->setLogin($list['usr_login']);
         //$User->setUserRatingId($list['']);
         $User->setEmail($list['usr_email']);
         $User->setDOB($list['usr_DOB']);
         //$User->setLocation($list['']);
         $User->setRegistration_date($list['usr_registration_date']);
         $User->setUserType($list['usr_user_type_id']);
         $User->setUserLanguage($list['usr_language']);
         $User->setEmailSub($list['usr_email_subscribed']);
     }
     return $User;
 }
Example #25
0
<?php

require_once '../core/init.php';
$data = array();
$userId = $_POST['userid'];
$userType = $_POST['usertype'];
$userFullName = $_POST['fullname'];
$userStatus = $_POST['userstatus'];
$user = new User();
$fetchedUser = $user->getUserUsingUserId($userId);
if (isset($fetchedUser)) {
    //now set the modified values using the setter methods..
    $modifiedUser = new User();
    $modifiedUser->setUserId($userId);
    $modifiedUser->setUserType($userType);
    $modifiedUser->setUsername($fetchedUser->username);
    $modifiedUser->existingUserPassword($fetchedUser->user_password);
    $modifiedUser->setUserFullName($userFullName);
    $modifiedUser->setUserStatus($userStatus);
    $modifiedUser->setEmail($fetchedUser->email);
    $modifiedUser->setUserLastValidLogin($fetchedUser->user_last_valid_login);
    $modifiedUser->setUserFirstInvalidLogin($fetchedUser->user_first_invalid_login);
    $modifiedUser->setUserFailedLoginCount($fetchedUser->user_faild_login_count);
    $modifiedUser->setUserCreateDate($fetchedUser->user_create_date);
    $modifiedUser->setModifiedBy($fetchedUser->modified_by);
    $modifiedUser->setModificationDate($fetchedUser->modification_date);
    //update the record
    $user->update($modifiedUser);
    $data['success'] = true;
    $data['message'] = "<div class='alert alert-success alert-dismissable'>" . "<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>" . "Lorem ipsum dolor sit amet, consectetur adipisicing elit. <a href='#' class='alert-link'>Alert Link</a>." . "</div><br/>";
    echo json_encode($data);
Example #26
0
<?php

require_once "UserPDO.php";
require_once "User.php";
if (isset($_POST['submit'])) {
    $userid = $_POST["userid"];
    // echo $userid . "<br>\n";
    $username = $_POST["username"];
    //echo $username . "<br>\n";
    $password = $_POST["password"];
    //echo $password ."<br>\n";
    if ($username != '' && $password != '') {
        $userPDO = new UserPDO();
        $user = new User();
        $user->setUserId($userid);
        $user->setUserName($username);
        $user->setPassword($password);
        $userPDO->updateUser($user);
        echo "<html>";
        echo "<head>";
        echo "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' >";
        echo "<link rel='stylesheet' type='text/css' href='menu.css'>";
        echo "<title>News Portal - Edit User</title>";
        echo "</head>";
        echo "<body>";
        include "menu.php";
        echo "User updated <br>";
        echo "<a href='Home.php'> Back to Home</a>";
        echo "</body>";
        echo "</html";
    } else {