Continued work on getter/setters: staff confirm

This commit is contained in:
Marcin Kurczewski 2014-05-07 20:39:48 +02:00
parent 16942d9d19
commit 20ee47e596
7 changed files with 22 additions and 13 deletions

View file

@ -5,7 +5,7 @@ class AcceptUserRegistrationJob extends AbstractUserJob
{
$user = $this->user;
$user->staffConfirmed = true;
$user->setStaffConfirmed(true);
UserModel::save($user);
Logger::log('{user} confirmed {subject}\'s account', [

View file

@ -7,7 +7,7 @@ class AddUserJob extends AbstractJob
$user = UserModel::spawn();
$user->setJoinTime(time());
$user->staffConfirmed = $firstUser;
$user->setStaffConfirmed($firstUser);
UserModel::forgeId($user);
if ($firstUser)

View file

@ -21,7 +21,7 @@ class Auth
if ($passwordHash != $user->getPasswordHash())
throw new SimpleException('Invalid password');
if (!$user->staffConfirmed and $config->registration->staffActivation)
if (!$user->isStaffConfirmed() and $config->registration->staffActivation)
throw new SimpleException('Staff hasn\'t confirmed your registration yet');
if ($user->isBanned())

View file

@ -7,7 +7,7 @@ class UserEntity extends AbstractEntity implements IValidatable
protected $name;
protected $passSalt;
protected $passHash;
public $staffConfirmed;
protected $staffConfirmed;
protected $emailUnconfirmed;
protected $emailConfirmed;
protected $joinDate;
@ -48,7 +48,7 @@ class UserEntity extends AbstractEntity implements IValidatable
throw new SimpleException('User with this name is already registered and awaits e-mail confirmation');
}
if (!$otherUser->staffConfirmed
if (!$otherUser->isStaffConfirmed()
and $config->registration->staffActivation)
{
throw new SimpleException('User with this name is already registered and awaits staff confirmation');
@ -168,6 +168,16 @@ class UserEntity extends AbstractEntity implements IValidatable
$this->emailConfirmed = $email;
}
public function isStaffConfirmed()
{
return $this->staffConfirmed;
}
public function setStaffConfirmed($confirmed)
{
$this->staffConfirmed = $confirmed;
}
public function getPasswordHash()
{
return $this->passHash;

View file

@ -9,7 +9,6 @@ class UserModel extends AbstractCrudModel
const SETTING_POST_TAG_TITLES = 3;
const SETTING_HIDE_DISLIKED_POSTS = 4;
public static function getTableName()
{
return 'user';
@ -45,7 +44,7 @@ class UserModel extends AbstractCrudModel
'name' => $user->getName(),
'pass_salt' => $user->getPasswordSalt(),
'pass_hash' => $user->getPasswordHash(),
'staff_confirmed' => $user->staffConfirmed,
'staff_confirmed' => $user->isStaffConfirmed(),
'email_unconfirmed' => $user->getUnconfirmedEmail(),
'email_confirmed' => $user->getConfirmedEmail(),
'join_date' => $user->getJoinTime(),

View file

@ -103,7 +103,7 @@ Assets::addStylesheet('user-view.css');
}
if (Access::check(new Privilege(Privilege::AcceptUserRegistration))
and !$this->context->transport->user->staffConfirmed
and !$this->context->transport->user->isStaffConfirmed()
and getConfig()->registration->staffActivation)
{
$options []=

View file

@ -65,7 +65,7 @@ class AuthTest extends AbstractTest
getConfig()->registration->needEmailForRegistering = false;
$user = $this->prepareValidUser();
$user->staffConfirmed = false;
$user->setStaffConfirmed(false);
UserModel::save($user);
$this->assert->throws(function()
@ -80,7 +80,7 @@ class AuthTest extends AbstractTest
getConfig()->registration->needEmailForRegistering = false;
$user = $this->prepareValidUser();
$user->staffConfirmed = false;
$user->setStaffConfirmed(false);
UserModel::save($user);
$this->assert->doesNotThrow(function()
@ -95,7 +95,7 @@ class AuthTest extends AbstractTest
getConfig()->registration->needEmailForRegistering = true;
$user = $this->prepareValidUser();
$user->staffConfirmed = false;
$user->setStaffConfirmed(false);
UserModel::save($user);
$this->assert->throws(function()
@ -110,7 +110,7 @@ class AuthTest extends AbstractTest
getConfig()->registration->needEmailForRegistering = true;
$user = $this->prepareValidUser();
$user->staffConfirmed = false;
$user->setStaffConfirmed(false);
$user->setUnconfirmedEmail('test@example.com');
UserModel::save($user);
@ -126,7 +126,7 @@ class AuthTest extends AbstractTest
getConfig()->registration->needEmailForRegistering = true;
$user = $this->prepareValidUser();
$user->staffConfirmed = false;
$user->setStaffConfirmed(false);
$user->setConfirmedEmail('test@example.com');
UserModel::save($user);