Created
December 6, 2013 12:04
-
-
Save kolyadin/7822719 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
public function findByHash($userId,$securityHash){ | |
$this->findByHashMemoryStatement->bindValue(':id',$userId); | |
$this->findByHashMemoryStatement->bindValue(':securityHash',$securityHash); | |
$this->findByHashMemoryStatement->execute(); | |
$userIdMemory = $this->findByHashMemoryStatement->fetch(\PDO::FETCH_COLUMN); | |
if ($userIdMemory){ | |
//Сначала проверяем существует ли hash пользователя в кэше (mysql memory) | |
return $userIdMemory; | |
}else{ | |
//Смотрим в основной таблице юзверей | |
$this->findByHashStatement->bindValue(':id',$userId); | |
$this->findByHashStatement->bindValue(':securityHash',$securityHash); | |
$this->findByHashStatement->execute(); | |
$userId = $this->findByHashStatement->fetch(\PDO::FETCH_COLUMN); | |
if ($userId){ | |
$stmt = $this->getPDO()->prepare('delete from pn_users_auth where id = ?'); | |
$stmt->bindValue(1,$userId,\PDO::PARAM_INT); | |
$stmt->execute(); | |
$stmt = $this->getPDO()->prepare('insert into pn_users_auth set id = ?, securityHash = ?'); | |
$stmt->bindValue(1,$userId,\PDO::PARAM_INT); | |
$stmt->bindValue(2,$securityHash,\PDO::PARAM_STR); | |
$stmt->execute(); | |
return $userId; | |
}else{ | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment