From 20ee47e596842d2e56f2f449d00560550af87cb8 Mon Sep 17 00:00:00 2001 From: Marcin Kurczewski Date: Wed, 7 May 2014 20:39:48 +0200 Subject: [PATCH] Continued work on getter/setters: staff confirm --- src/Api/Jobs/AcceptUserRegistrationJob.php | 2 +- src/Api/Jobs/AddUserJob.php | 2 +- src/Auth.php | 2 +- src/Models/Entities/UserEntity.php | 14 ++++++++++++-- src/Models/UserModel.php | 3 +-- src/Views/user-view.phtml | 2 +- tests/MiscTests/AuthTest.php | 10 +++++----- 7 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/Api/Jobs/AcceptUserRegistrationJob.php b/src/Api/Jobs/AcceptUserRegistrationJob.php index cbb57566..ef58bcc4 100644 --- a/src/Api/Jobs/AcceptUserRegistrationJob.php +++ b/src/Api/Jobs/AcceptUserRegistrationJob.php @@ -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', [ diff --git a/src/Api/Jobs/AddUserJob.php b/src/Api/Jobs/AddUserJob.php index 479649a9..53bee1e0 100644 --- a/src/Api/Jobs/AddUserJob.php +++ b/src/Api/Jobs/AddUserJob.php @@ -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) diff --git a/src/Auth.php b/src/Auth.php index 4f4af4e9..c5ded64a 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -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()) diff --git a/src/Models/Entities/UserEntity.php b/src/Models/Entities/UserEntity.php index 3794fe05..dd121a22 100644 --- a/src/Models/Entities/UserEntity.php +++ b/src/Models/Entities/UserEntity.php @@ -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; diff --git a/src/Models/UserModel.php b/src/Models/UserModel.php index f94361f0..abe6cd52 100644 --- a/src/Models/UserModel.php +++ b/src/Models/UserModel.php @@ -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(), diff --git a/src/Views/user-view.phtml b/src/Views/user-view.phtml index 4a59bc08..99c046a6 100644 --- a/src/Views/user-view.phtml +++ b/src/Views/user-view.phtml @@ -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 []= diff --git a/tests/MiscTests/AuthTest.php b/tests/MiscTests/AuthTest.php index 86e6df67..1d41ceb3 100644 --- a/tests/MiscTests/AuthTest.php +++ b/tests/MiscTests/AuthTest.php @@ -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);