Last active
May 30, 2017 02:54
-
-
Save andrewstobbe/c423c5f16fc1416caa09a9f0c04aa08e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('BASEPATH') OR exit('No direct script access allowed'); | |
/** | |
* Class Account | |
*/ | |
class Account | |
{ | |
private $account_id; | |
private $email; | |
/** | |
* Account constructor. | |
* @param $registry | |
*/ | |
public function __construct($registry) | |
{ | |
$this->config = $registry->get('config'); | |
$this->db = $registry->get('db'); | |
$this->request = $registry->get('request'); | |
$this->session = $registry->get('session'); | |
if (isset($this->session->data['account_id'])) { | |
try { | |
$sql = 'SELECT * | |
FROM account | |
WHERE account_id = ? | |
AND status = "1" | |
LIMIT 1'; | |
$result = $this->db->prepare($sql); | |
$result->execute(array($this->session->data['account_id'])); | |
if ($result->rowCount()) { | |
while ($row = $result->fetch(PDO::FETCH_OBJ)) { | |
$this->account_id = $row->account_id; | |
$this->email = $row->email; | |
$this->session->data['email'] = $this->email; | |
} | |
} else { | |
$this->logout(); | |
} | |
} catch (PDOException $e) { | |
die('ERROR: ' . $e->getMessage()); | |
} | |
} | |
} | |
/** | |
* login() | |
* | |
* @param $email | |
* @param $password | |
* @return bool | |
*/ | |
public function login($email, $password) | |
{ | |
try { | |
$pass = md5($password); | |
$sql = "SELECT * | |
FROM account | |
WHERE LOWER(email) = ? | |
AND password = ? | |
AND status = '1' | |
LIMIT 1"; | |
$result = $this->db->prepare($sql); | |
$result->execute(array($email, $pass)); | |
if ($result->rowCount()) { | |
while ($row = $result->fetch(PDO::FETCH_OBJ)) { | |
$this->session->data['account_id'] = $row->account_id; | |
$this->session->data['id-jjlprocess'] = session_id(); | |
$this->account_id = $row->account_id; | |
$this->email = $row->email; | |
} | |
return true; | |
} else { | |
return false; | |
} | |
} catch (PDOException $e) { | |
die('ERROR: ' . $e->getMessage()); | |
} | |
} | |
/** | |
* logout() | |
*/ | |
public function logout() | |
{ | |
unset($this->session->data['account_id']); | |
unset($this->session->data['email']); | |
unset($this->session->data['id-jjlprocess']); | |
$this->account_id = ''; | |
$this->email = ''; | |
} | |
/** | |
* isLogged() | |
* | |
* @return mixed | |
*/ | |
public function isLogged() | |
{ | |
return $this->account_id; | |
} | |
/** | |
* getId() | |
* | |
* @return mixed | |
*/ | |
public function getId() | |
{ | |
return $this->account_id; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment