Archived
1
0
Fork 0
This repository has been archived on 2026-05-10. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
fiktivkod/application/datastorage/Users.php
2010-09-10 23:30:22 +02:00

70 lines
No EOL
1.7 KiB
PHP

<?php
/**
*
*
*/
class Table_User extends Zend_Db_Table_Abstract implements Fiktiv_Data_Storage
{
protected $_schema = 'fiktivkod';
protected $_name = 'User';
protected $_primary = 'id';
protected $_rowClass = 'User';
/**
* Authenticate user
* TODO: Evaluate, should this be here? Datapoint = data access only?
* @param string $email
* @param string $password
*/
public function login($email, $password)
{
$auth = Zend_Auth::getInstance();
// Setup auth adapter
$authAdapter = new Zend_Auth_Adapter_DbTable($this->getAdapter(), $this->_name, 'email', 'password');
// Set credentials
$authAdapter->setIdentity($email);
$authAdapter->setCredential(hash('sha256',$password));
// Authenticate
$result = $auth->authenticate($authAdapter);
// Check result
if ($result->isValid()) {
// Keep all but password and salt in session.
$storage = $auth->getStorage();
$storage->write($authAdapter->getResultRowObject(null, array('password', 'salt')));
return true;
}
return false;
}
/**
* Fetch user based on email
*
* @return User
*/
public function findByEmail($email)
{
// Atleast 6 character long
if (is_string($email) && isset($email[5])) {
return $this->fetchRow($this->getAdapter()->quoteInto('email = ?', $email));
}
return null;
}
/**
* Get random user
*
* @return User
*/
public function findRandom()
{
return $this->fetchAll(null, 'RAND()', 1)->current();
}
}