Skip to content
Snippets Groups Projects
Commit 30ccaed2 authored by xamgore's avatar xamgore
Browse files

Reformat code

parent 50e4a206
Branches
Tags
No related merge requests found
...@@ -15,7 +15,7 @@ class Model_Account extends Model ...@@ -15,7 +15,7 @@ class Model_Account extends Model
} }
public static function checkAuth($login, $password) { public static function checkAuth($login, $password) {
$sql = "SELECT `SignIn`(:login, :pass) AS `ID`;"; $sql = 'SELECT `SignIn`(:login, :pass) AS `ID`';
return DB::query(Database::SELECT, $sql) return DB::query(Database::SELECT, $sql)
->param(':login', $login) ->param(':login', $login)
->param(':pass', $password) ->param(':pass', $password)
......
...@@ -146,7 +146,7 @@ class User implements ArrayAccess ...@@ -146,7 +146,7 @@ class User implements ArrayAccess
return [false, 'login_exists']; return [false, 'login_exists'];
} }
$this->completeSignIn($id, $this->hash($password)); $this->initSession($id, $this->hash($password));
return [true, 'ok']; return [true, 'ok'];
} }
...@@ -159,19 +159,18 @@ class User implements ArrayAccess ...@@ -159,19 +159,18 @@ class User implements ArrayAccess
* и false, если данные являются некорректными. * и false, если данные являются некорректными.
*/ */
public function signIn($login, $password) { public function signIn($login, $password) {
$id = (int)Model_Account::checkAuth($login, $password); $id = (int) Model_Account::checkAuth($login, $password);
return $this->completeSignIn($id, $this->hash($password)); return $this->initSession($id, $this->hash($password));
} }
protected function completeSignIn($id, $passHash) protected function initSession($id, $passHash) {
{ if ($id <= 0) return false;
if ( $id <= 0 )
return false;
$source = $id . Request::$user_agent . Request::$client_ip; $source = $id . Request::$user_agent . Request::$client_ip;
$userHash = $this->hash($source) . $this->_config['hash_key']; $userHash = $this->hash($source) . $this->_config['hash_key'];
$passwordHash = $this->hash($passHash . $this->_config['hash_key']); $passwordHash = $this->hash($passHash . $this->_config['hash_key']);
Cookie::set('userhash', $passwordHash); Cookie::set('userhash', $passwordHash);
$userInfo = Model_Account::with($id, $this->_general->SemesterID); $userInfo = Model_Account::with($id, $this->_general->SemesterID);
$session = $this->_session; $session = $this->_session;
...@@ -182,9 +181,9 @@ class User implements ArrayAccess ...@@ -182,9 +181,9 @@ class User implements ArrayAccess
$session->set('UserHash', $this->hash($userHash)); $session->set('UserHash', $this->hash($userHash));
$session->set('PasswordHash', $passwordHash); $session->set('PasswordHash', $passwordHash);
$session->set('start_time', time()); $session->set('start_time', time());
foreach($userInfo as $key => $value) {
foreach ($userInfo as $key => $value)
$session->set($key, $value); $session->set($key, $value);
}
return true; return true;
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment