Adding IP address entry in session

pull/13/head
sundowndev 2018-07-26 17:12:01 +02:00
parent 3925592ade
commit 82e8ecbdc7
2 changed files with 5 additions and 4 deletions

View File

@ -54,7 +54,7 @@ class SessionController
$expire_at = new \DateTime();
$expire_at->modify('+1 Day'); // Expire in 1 day
$this->sessionRepository->create($user['id'], $token, $expire_at->format('Y-m-d H:i:s'));
$this->sessionRepository->create($user['id'], $token, $expire_at->format('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR']);
print $this->jsonResponse->create(200, 'Welcome ' . $user['name'], [
'token' => $token,
@ -62,7 +62,7 @@ class SessionController
]);
}
/**db
/**
* Register route
*/
public function signup()

View File

@ -81,12 +81,13 @@ class SessionRepository
* @param $csrf
* @param $cookie
*/
public function create($user_id, $token, $expiration)
public function create($user_id, $token, $expiration, $ip)
{
$stmt = $this->db->getConnection()->prepare('INSERT INTO Session (`user_id`, `token`, `issued_at`, `expire_at`) VALUES(:user_id, :token, NOW(), :expire_at)');
$stmt = $this->db->getConnection()->prepare('INSERT INTO Session (`user_id`, `token`, `issued_at`, `expire_at`, `ip_address`) VALUES(:user_id, :token, NOW(), :expire_at, :ip_address)');
$stmt->bindParam(':user_id', $user_id);
$stmt->bindParam(':token', $token);
$stmt->bindParam(':expire_at', $expiration);
$stmt->bindParam(':ip_address', $ip);
$stmt->execute();
}