From ef3e84cdc3c5fd35de4d809ad7d59b45e1fc76c4 Mon Sep 17 00:00:00 2001 From: jmartin Date: Mon, 28 Jan 2013 17:30:26 +0100 Subject: [PATCH 1/4] Fix WebUser->updateSession crashes when user is not login in --- components/WebUser.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/components/WebUser.php b/components/WebUser.php index 4a664f6..04c4095 100644 --- a/components/WebUser.php +++ b/components/WebUser.php @@ -48,16 +48,19 @@ protected function afterLogin($fromCookie) public function updateSession() { $user = Yii::app()->getModule('user')->user($this->id); - $this->name = $user->username; - $userAttributes = CMap::mergeArray(array( - 'email'=>$user->email, - 'username'=>$user->username, - 'create_at'=>$user->create_at, - 'lastvisit_at'=>$user->lastvisit_at, - ),$user->profile->getAttributes()); - foreach ($userAttributes as $attrName=>$attrValue) { - $this->setState($attrName,$attrValue); + if ($user!==false){ + $this->name = $user->username; + $userAttributes = CMap::mergeArray(array( + 'email'=>$user->email, + 'username'=>$user->username, + 'create_at'=>$user->create_at, + 'lastvisit_at'=>$user->lastvisit_at, + ),$user->profile->getAttributes()); + foreach ($userAttributes as $attrName=>$attrValue) { + $this->setState($attrName,$attrValue); + } } + } public function model($id=0) { From 7e08944153f8d34605b79cc2e6001daa6ff8d513 Mon Sep 17 00:00:00 2001 From: uldisn Date: Mon, 11 Nov 2013 11:05:03 +0200 Subject: [PATCH 2/4] implemented allowRegister --- UserModule.php | 6 ++++++ controllers/RegistrationController.php | 29 +++++++++++++++++++++++++- views/user/login.php | 9 ++++++-- 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/UserModule.php b/UserModule.php index cc624a9..033e9c7 100644 --- a/UserModule.php +++ b/UserModule.php @@ -41,6 +41,12 @@ class UserModule extends CWebModule public $loginNotActiv=false; /** + * @var boolean + * @desc allow guests register + */ + public $allowRegister=true; + + /** * @var boolean * @desc activate user on registration (only $sendActivationMail = false) */ diff --git a/controllers/RegistrationController.php b/controllers/RegistrationController.php index 7890b65..0b44c49 100644 --- a/controllers/RegistrationController.php +++ b/controllers/RegistrationController.php @@ -3,7 +3,34 @@ class RegistrationController extends Controller { public $defaultAction = 'registration'; - + + /** + * @return array action filters + */ + public function filters() + { + return CMap::mergeArray(parent::filters(),array( + 'accessControl', // perform access control for CRUD operations + )); + } + + /** + * Specifies the access control rules. + * This method is used by the 'accessControl' filter. + * @return array access control rules + */ + public function accessRules() + { + return array( + array('allow', // allow admin user to perform 'admin' and 'delete' actions + 'actions'=>array('registration'), + 'expression'=>'Yii::app()->getModule(\'user\')->allowRegister', + ), + array('deny', // deny all users + 'users'=>array('*'), + ), + ); + } /** * Declares class-based actions. */ diff --git a/views/user/login.php b/views/user/login.php index 7064709..bbad67a 100644 --- a/views/user/login.php +++ b/views/user/login.php @@ -33,13 +33,18 @@ - + getModule('user')->allowRegister){ + ?>

getModule('user')->registrationUrl); ?> | getModule('user')->recoveryUrl); ?>

- +
From 7ecee2c98cae8be0ab32204bffe5b85fc5843e75 Mon Sep 17 00:00:00 2001 From: uldisn Date: Mon, 11 Nov 2013 11:21:50 +0200 Subject: [PATCH 3/4] changed allowRegister to allowGuestRegister --- README.md | 3 +++ UserModule.php | 2 +- controllers/RegistrationController.php | 2 +- views/user/login.php | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 4fa2526..6b56cf6 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,9 @@ Change your config main: # automatically login from registration 'autoLogin' => true, + # guests allow register + 'allowGuestRegister' => true, + # registration path 'registrationUrl' => array('/user/registration'), diff --git a/UserModule.php b/UserModule.php index 033e9c7..79f506f 100644 --- a/UserModule.php +++ b/UserModule.php @@ -44,7 +44,7 @@ class UserModule extends CWebModule * @var boolean * @desc allow guests register */ - public $allowRegister=true; + public $allowGuestRegister=true; /** * @var boolean diff --git a/controllers/RegistrationController.php b/controllers/RegistrationController.php index 0b44c49..19c55e0 100644 --- a/controllers/RegistrationController.php +++ b/controllers/RegistrationController.php @@ -24,7 +24,7 @@ public function accessRules() return array( array('allow', // allow admin user to perform 'admin' and 'delete' actions 'actions'=>array('registration'), - 'expression'=>'Yii::app()->getModule(\'user\')->allowRegister', + 'expression'=>'Yii::app()->getModule(\'user\')->allowGuestRegister', ), array('deny', // deny all users 'users'=>array('*'), diff --git a/views/user/login.php b/views/user/login.php index bbad67a..88ccdfa 100644 --- a/views/user/login.php +++ b/views/user/login.php @@ -35,7 +35,7 @@
getModule('user')->allowRegister){ + if(Yii::app()->getModule('user')->allowGuestRegister){ ?>

From 7deacbb39b3e899d103d77224ad4e6522e833179 Mon Sep 17 00:00:00 2001 From: erics342 Date: Tue, 12 Nov 2013 20:45:40 -0200 Subject: [PATCH 4/4] 2 fields on create statement were missing create_at and lastvisit_at were missing in the table. --- migrations/m110805_153437_installYiiUser.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/migrations/m110805_153437_installYiiUser.php b/migrations/m110805_153437_installYiiUser.php index 6130658..eb609db 100644 --- a/migrations/m110805_153437_installYiiUser.php +++ b/migrations/m110805_153437_installYiiUser.php @@ -33,6 +33,8 @@ public function safeUp() "lastvisit" => "int(10) NOT NULL DEFAULT 0", "superuser" => "int(1) NOT NULL DEFAULT 0", "status" => "int(1) NOT NULL DEFAULT 0", + "create_at" => "timestamp NULL DEFAULT NULL", + "lastvisit_at" => "timestamp NULL DEFAULT NULL", ), $this->MySqlOptions); $this->createIndex('user_username', Yii::app()->getModule('user')->tableUsers, 'username', true); $this->createIndex('user_email', Yii::app()->getModule('user')->tableUsers, 'email', true); @@ -74,6 +76,8 @@ public function safeUp() "lastvisit" => "int(10) NOT NULL", "superuser" => "int(1) NOT NULL", "status" => "int(1) NOT NULL", + "create_at" => "timestamp NULL", + "lastvisit_at" => "timestamp NULL", )); $this->createIndex('user_username', Yii::app()->getModule('user')->tableUsers, 'username', true); $this->createIndex('user_email', Yii::app()->getModule('user')->tableUsers, 'email', true); @@ -209,4 +213,4 @@ private function readStdinUser($prompt, $field, $default = '') { } return $input; } -} \ No newline at end of file +}