Finished token validation
This commit is contained in:
parent
9882e84aa6
commit
9cc8d03376
5 changed files with 40 additions and 40 deletions
|
@ -88,7 +88,6 @@ class Mailer
|
||||||
//prepare unique user token
|
//prepare unique user token
|
||||||
$token = TokenModel::spawn();
|
$token = TokenModel::spawn();
|
||||||
$token->setUser($user);
|
$token->setUser($user);
|
||||||
$token->setText(TokenModel::forgeUnusedToken());
|
|
||||||
$token->setUsed(false);
|
$token->setUsed(false);
|
||||||
$token->setExpirationTime(null);
|
$token->setExpirationTime(null);
|
||||||
TokenModel::save($token);
|
TokenModel::save($token);
|
||||||
|
|
|
@ -4,19 +4,19 @@ use \Chibi\Database as Database;
|
||||||
|
|
||||||
final class PostEntity extends AbstractEntity implements IValidatable
|
final class PostEntity extends AbstractEntity implements IValidatable
|
||||||
{
|
{
|
||||||
protected $type;
|
private $type;
|
||||||
protected $name;
|
private $name;
|
||||||
protected $origName;
|
private $origName;
|
||||||
protected $fileHash;
|
private $fileHash;
|
||||||
protected $fileSize;
|
private $fileSize;
|
||||||
protected $mimeType;
|
private $mimeType;
|
||||||
protected $safety;
|
private $safety;
|
||||||
protected $hidden;
|
private $hidden;
|
||||||
protected $uploadDate;
|
private $uploadDate;
|
||||||
protected $imageWidth;
|
private $imageWidth;
|
||||||
protected $imageHeight;
|
private $imageHeight;
|
||||||
protected $uploaderId;
|
private $uploaderId;
|
||||||
protected $source;
|
private $source;
|
||||||
|
|
||||||
public function fillNew()
|
public function fillNew()
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,18 @@ final class TokenEntity extends AbstractEntity implements IValidatable
|
||||||
|
|
||||||
public function fillNew()
|
public function fillNew()
|
||||||
{
|
{
|
||||||
|
$this->used = false;
|
||||||
|
|
||||||
|
$tokenText = '';
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
$tokenText = md5(mt_rand() . uniqid());
|
||||||
|
$token = TokenModel::tryGetByToken($tokenText);
|
||||||
|
if (!$token)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->token = $tokenText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function fillFromDatabase($row)
|
public function fillFromDatabase($row)
|
||||||
|
@ -21,7 +33,8 @@ final class TokenEntity extends AbstractEntity implements IValidatable
|
||||||
|
|
||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
//todo
|
if (empty($this->token))
|
||||||
|
throw new Exception('Trying to save empty token');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getText()
|
public function getText()
|
||||||
|
|
|
@ -4,20 +4,20 @@ use \Chibi\Database as Database;
|
||||||
|
|
||||||
final class UserEntity extends AbstractEntity implements IValidatable
|
final class UserEntity extends AbstractEntity implements IValidatable
|
||||||
{
|
{
|
||||||
protected $name;
|
private $name;
|
||||||
protected $passSalt;
|
private $passSalt;
|
||||||
protected $passHash;
|
private $passHash;
|
||||||
protected $staffConfirmed;
|
private $staffConfirmed;
|
||||||
protected $emailUnconfirmed;
|
private $emailUnconfirmed;
|
||||||
protected $emailConfirmed;
|
private $emailConfirmed;
|
||||||
protected $joinDate;
|
private $joinDate;
|
||||||
protected $lastLoginDate;
|
private $lastLoginDate;
|
||||||
protected $accessRank;
|
private $accessRank;
|
||||||
public $settings;
|
public $settings;
|
||||||
protected $banned = false;
|
private $banned = false;
|
||||||
|
|
||||||
protected $__passwordChanged = false;
|
private $__passwordChanged = false;
|
||||||
protected $__password;
|
private $__password;
|
||||||
|
|
||||||
public function fillNew()
|
public function fillNew()
|
||||||
{
|
{
|
||||||
|
@ -55,7 +55,7 @@ final class UserEntity extends AbstractEntity implements IValidatable
|
||||||
throw new Exception('Trying to save anonymous user into database');
|
throw new Exception('Trying to save anonymous user into database');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function validateUserName()
|
private function validateUserName()
|
||||||
{
|
{
|
||||||
$userName = $this->getName();
|
$userName = $this->getName();
|
||||||
$config = getConfig();
|
$config = getConfig();
|
||||||
|
|
|
@ -72,16 +72,4 @@ final class TokenModel extends AbstractCrudModel
|
||||||
if ($token->getExpirationTime() !== null and time() > $token->getExpirationTime())
|
if ($token->getExpirationTime() !== null and time() > $token->getExpirationTime())
|
||||||
throw new SimpleException('This token has expired');
|
throw new SimpleException('This token has expired');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function forgeUnusedToken()
|
|
||||||
{
|
|
||||||
$tokenText = '';
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
$tokenText = md5(mt_rand() . uniqid());
|
|
||||||
$token = self::tryGetByToken($tokenText);
|
|
||||||
if (!$token)
|
|
||||||
return $tokenText;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue