Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!$_SERVER['HTTP_REFERER']) {
- header('Location: ../index.php');
- die();
- }
- include_once $_SERVER['DOCUMENT_ROOT'].'/bank/includes/database_inc.php';
- class User extends Database {
- private $login;
- private $password;
- private $userId;
- public function checkUser($login, $password) {
- $this->login = $login;
- $this->password = $password;
- try {
- $query = $this->pdo->prepare('SELECT * FROM users WHERE login = :login');
- $query->bindValue(':login', $this->login, PDO::PARAM_STR);
- $query->execute();
- $checkUser = $query->fetch();
- $_SESSION['userName'] = $checkUser['name'];
- $_SESSION['userSurname'] = $checkUser['surname'];
- $_SESSION['userId'] = $checkUser['id_user'];
- $passwordHashed = $checkUser['password'];
- $checkPassword = password_verify($password, $passwordHashed);
- sleep(1.5);
- if ($checkPassword) {
- $_SESSION['loggedIn'] = true;
- header('Location: paneluser/accounts.php');
- } else {
- $_SESSION['loggedIn'] = false;
- $_SESSION['loginFailed'] = "Nieprawidłowy login lub hasło";
- header('Location: index.php');
- }
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- public function getAccounts($userId) {
- $this->userId = $userId;
- try {
- $query = $this->pdo->prepare('SELECT * FROM accounts WHERE id_user = :userId');
- $query->bindValue(':userId', $this->userId, PDO::PARAM_INT);
- $query->execute();
- $accountsAmount = $query->rowCount();
- $accInfo = $query->fetchAll();
- if ($accountsAmount > 0) {
- function convertAccountNumber($accountNumber) {
- $entryNumber = $accountNumber[0] . $accountNumber[1];
- $restNumber = null;
- for ($i = 2; $i < 26; $i++) {
- $restNumber = $restNumber . $accountNumber[$i];
- }
- return $entryNumber . ' ' . chunk_split($restNumber, 4 , ' ');
- }
- function convertAccountType($accountType) {
- switch($accountType) {
- case 'standard':
- $accountType = 'Konto standard';
- break;
- case 'standard-plus':
- $accountType = "Konto standard plus";
- break;
- case 'for-young':
- $accountType = "Konto dla młodych";
- break;
- case 'company':
- $accountType = "Konto firmowe";
- break;
- }
- return $accountType;
- }
- $accounts = [];
- foreach ($accInfo as $row) {
- $accountNumber = $row['account_number'];
- $accountType = $row['account_type'];
- $accounts[] = [
- 'accountNumber' => convertAccountNumber($accountNumber),
- 'accountType' => convertAccountType($accountType),
- 'accountBalance' => number_format($row['balance'], 2, ',', ' '),
- 'accountAvailableFunds' => number_format($row['available_funds'], 2, ',', ' ')
- ];
- }
- echo json_encode($accounts);
- } else {
- echo $accountsAmount;
- }
- } catch (PDOException $e) {
- echo $e->getMessage();
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement