Exemplo n.º 1
0
 public static function editAccount($account)
 {
     try {
         $db = Database::getDB();
         if (is_null($account) || $account->getErrorCount() > 0) {
             return $account;
         }
         $checkAccount = AccountsDB::getAccountsBy('accountID', $account->getAccountID());
         if (empty($checkAccount)) {
             $account->setError('accountId', 'ACCOUNT_DOES_NOT_EXIST');
         }
         if ($account->getErrorCount() > 0) {
             return $account;
         }
         //print_r($account->getAccountID().'<br>'.$account->getProfileID().'<br>');
         $query = "UPDATE Accounts SET profileID = :profileID\r\n\t    \t\t\t                 WHERE accountID = :accountID";
         $statement = $db->prepare($query);
         $statement->bindValue(":profileID", $account->getProfileID());
         $statement->bindValue(":accountID", $account->getAccountID());
         $statement->execute();
         $statement->closeCursor();
     } catch (Exception $e) {
         // Not permanent error handling
         $account->setError('accountId', 'ACCOUNT_COULD_NOT_BE_UPDATED');
     }
     return $account;
 }
Exemplo n.º 2
0
 public function testGetAccountByWithValidParameters()
 {
     $account = AccountsDB::getAccountsBy('accountID', 22);
     $this->assertInstanceOf('Account', $account[0], 'It should return a Account object when valid parameters are provided');
     $this->assertEquals(22, $account[0]->getAccountID(), 'It should return a Account object whose accountID matches the provided input when valid input is provided');
     $this->assertCount(0, $account[0]->getErrors(), 'It should return a Account object without errors when valid input is provided:' . "\n" . array_shift($account[0]->getErrors()));
     $this->assertEquals(0, $account[0]->getErrorCount(), 'It should return a Account object with an error count of 0 when valid input is provided');
 }
Exemplo n.º 3
0
 public static function createAccount($arguments)
 {
     $hardCode = array("profileID", "ssn");
     $parts = GenericInput::stripInput($arguments[0], $hardCode);
     //print_r($parts[0].'<br>'.$parts[1]);
     $num = intval($parts[0]);
     $parts[0] = $num;
     //print_r(($parts[0]+90).'<br>'.$parts[1]);
     if ($parts[0] < 0) {
         print_r("Error. accountID cannot be smaller or equal to 0<br>");
     } else {
         if ($parts[0] > 999999999) {
             print_r("Error. accountID cannot be that large<br>");
         } else {
             $account = AccountsDB::getAccountsBy('accountID', $parts[0]);
         }
     }
     // print_r($parts[1].'<br>'.$parts[2]);
     if (is_null($account[0])) {
         $param = array();
         $param['accountID'] = $parts[0];
         $param['SSN'] = intval($parts[2]);
         //     print_r(($parts[0]).'*<br>**'.$parts[1].'<br>***'.$parts[2]);
         $ProfileDB = ProfilesDB::getProfileBy('profileID', intval($parts[1]));
         if (!is_null($ProfileDB)) {
             //    print_r($account[0]->getProfileID()."***".$account[0]->getAccountID());
             //      if (is_null($account[0]->getProfileID())){
             $param['profileID'] = $ProfileDB->getProfileID();
             $param['SSN'] = $ProfileDB->getSSN();
             $account = new Account($param);
             AccountsDB::addAccount($account);
             //      }else{
             //              print_r("Error. Bank Account already has owner");
             //      }
         } else {
             //print_r( ($param['SSN']+3).'+<br>');
             $ProfileDB = ProfilesDB::getProfileBy('SSN', $param['SSN']);
             // 	print_r($ProfileDB->getProfileID().'&&<br>');
             if (is_null($ProfileDB)) {
                 $account = new Account($param);
                 //    print_r( $account->getSSN().'+<br>');
                 AccountsDB::addAccountNoOwner($account);
             } else {
                 print_r("ERROR. Profile with that SSN already exists");
             }
         }
     } else {
         print_r("Error. This Bank Account is already created<br>");
     }
 }
Exemplo n.º 4
0
 public static function changePassword($arguments)
 {
     $hardCode = array("old_password", "new_password");
     $parts = GenericInput::stripInput($arguments[0], $hardCode);
     $email = $parts[0];
     $ProfileDB = ProfilesDB::getProfileBy('email', $parts[0]);
     if (!is_null($ProfileDB)) {
         if ($ProfileDB->getTimeOfTemp() == 0) {
             //	print_r($parts[0]."<br>".$parts[1]."<br>".$parts[2]."<br>");
             if (strcmp($ProfileDB->getPassword(), $parts[1]) == 0) {
                 $ProfileDB->setPassword($parts[2]);
                 ProfilesDB::editProfile($ProfileDB);
                 self::outputMessage(self::CODE_SUCCESS, 'Password Set', 'Password is Set');
             } else {
                 self::outputMessage(self::CODE_BAD_REQUEST, 'Incorrect email/password', 'Passwrod or Email was incorrect. ');
             }
         } else {
             if ($ProfileDB->getTimeOfTemp() > time()) {
                 //print_r(time().'***'.$ProfileDB->getTimeOfTemp());
                 if (strcmp($ProfileDB->getTemp(), $parts[1]) == 0) {
                     $old = new Profile($ProfileDB->getParameters());
                     $ProfileDB->setPassword($parts[2]);
                     $ProfileDB->setTimeOfTemp(0);
                     //print_r($ProfileDB->__toString());
                     ProfilesDB::editProfile($ProfileDB);
                     self::outputMessage(self::CODE_SUCCESS, 'Password Set', 'Password is Set');
                 } else {
                     self::outputMessage(self::CODE_BAD_REQUEST, 'Incorrect email/password', 'Passwrod or Email was Incorrect. ');
                 }
             } else {
                 //	print_r(time().'***'.$ProfileDB->getTimeOfTemp());
                 AccountsDB::deleteAccountsBy('profileID', $ProfileDB->getProfileID());
                 ProfilesDB::deleteProfileBy('email', $parts[0]);
                 self::outputMessage(self::CAUSE_TIME_OUT, 'Password timed out', "Account Exceeded Temporary Password Time. Please Create the Account again.");
             }
         }
     } else {
         self::outputMessage(self::CAUSE_INVALID_ACTION, 'Account not found', 'Invalid Account, Account Not Found');
     }
 }
Exemplo n.º 5
0
 private static function createProfile($arguments)
 {
     // check arguments
     if (!array_key_exists(0, $arguments) || !isset($_GET['ssn']) || !isset($_GET['name']) || !isset($_GET['email'])) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Missing arguments', 'bankID, SSN, name, and email are required for registration.');
         return;
     }
     list($_GET['firstName'], $_GET['lastName']) = explode(' ', $_GET['name']);
     $bankID = $arguments[0];
     // make sure an account with the specified bankID (aka accountID) exists
     $matchingAccounts = AccountsDB::getAccountsBy('bankID', $bankID);
     if (empty($matchingAccounts)) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Member not found', 'A member with the specified bank ID does not exist.');
         return;
     }
     // make sure the profile has not already been created
     $existingProfile = ProfilesDB::getProfileBy('email', $_GET['email']);
     if (!is_null($existingProfile)) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Account already exists', 'An account with the specified bank ID already exists.');
         return;
     }
     // generate default password for account, and store bank ID
     $_GET['password'] = Email::sendEmail($_GET['email'], 1);
     $_GET['bankID'] = $bankID;
     // create the profile
     $profile = new Profile($_GET);
     if ($profile->getErrorCount() > 0) {
         self::outputMessage(self::CODE_BAD_REQUEST, 'Account creation failed', 'Errors occured while processing the arguments to create the account.');
         return;
     }
     // store the profile in the database
     $result = ProfilesDB::addProfile($profile);
     if ($profile->getErrorCount() > 0 || !is_numeric($result)) {
         self::outputMessage(self::CODE_INTERNAL_SERVER_ERROR, 'Account creation failed', 'Errors occured while attempting to store the new account information in the database.');
         return;
     }
     $profile->setProfileID($result);
     // success
     self::outputMessage(self::CODE_SUCCESS, 'Registration complete', 'An account for specified member was successfully created.', $profile);
 }
Exemplo n.º 6
0
 public static function run()
 {
     $profiles = ProfilesDB::getAllProfiles();
     $accounts = AccountsDB::getAllAccounts();
     echo "<!DOCTYPE html><html><style type=\"text/css\">a { font-size: 1.3em; }</style><head></head><body>";
     ?>
     Other Views: <a href="/BankingSystem/view/login">Login View</a> | <a href="/BankingSystem/view/gps">GPS View</a>
     <?php 
     echo "<h1>BankSystem profile list</h1>";
     echo "<table>";
     echo "<thead>";
     echo "<tr><th>ProfilID</th><th>AccountID</th><th>Email</th> <th>Password</th><th>isLoggedIn</th><th>isEmployee</th><th>isPasswordChanged</th></tr>";
     echo "</thead>";
     echo "<tbody>";
     foreach ($profiles as $profile) {
         echo '<tr>';
         echo '<td>' . $profile->getProfileID() . '</td>';
         echo '<td>' . $profile->getAccountID() . '</td>';
         echo '<td>' . $profile->getEmail() . '</td>';
         echo '<td>' . $profile->getPassword() . '</td>';
         echo '<td>' . $profile->isLoggedIn() . '</td>';
         echo '<td>' . $profile->isEmployee() . '</td>';
         echo '<td>' . $profile->isPasswordChanged() . '</td>';
         echo '</tr>';
         $personalAccounts = AccountsDB::getAccountsBy('bankID', $profile->getAccountID());
         if (!empty($personalAccounts)) {
             echo "<tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td>\r\n\t\t\t\t        <th>Account Id</th>\r\n\t\t\t\t        <th>SSN</th>\r\n\t\t\t\t        <th>First Name</th>\r\n\t\t\t\t        <th>Last Name</th>\r\n\t\t\t\t        <th>Balance</th>\r\n\t\t\t\t      </tr>";
             foreach ($personalAccounts as $acc) {
                 if (!is_null($acc)) {
                     //	print_r('<br>'.$acc);
                     echo '<tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td>';
                     echo '<td>   ' . $acc->getAccountID() . '</td>';
                     echo '<td>   ' . $acc->getSSN() . '</td>';
                     echo '<td>   ' . $acc->getFirstName() . '</td>';
                     echo '<td>   ' . $acc->getLastName() . '</td>';
                     echo '<td>   ' . $acc->getBalance() . '</td>';
                     echo '</tr>';
                 }
             }
         }
     }
     echo "</tbody>";
     echo "</table>";
     echo "<br><br>";
     echo "<h1>BankSystem Account list</h1>";
     echo "<table>";
     echo "<thead>";
     echo "<tr><td></td><th>Account Id</th><td></td><th>First Name</th><th>Last Name</th><th>Balance</th><th>SSN</th></tr>";
     echo "</thead>";
     echo "<tbody>";
     foreach ($accounts as $acc) {
         echo '<tr><td></td>';
         echo '<td>' . $acc->getAccountID() . '</td><td></td>';
         echo '<td>' . $acc->getFirstName() . '</td>';
         echo '<td>' . $acc->getLastName() . '</td>';
         echo '<td>' . $acc->getBalance() . '</td>';
         echo '<td>' . $acc->getSSN() . '</td>';
         echo '</tr>';
     }
     echo "</tbody>";
     echo "</table>";
     echo "</body></html>";
 }