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 cc624a9..79f506f 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 $allowGuestRegister=true; + + /** * @var boolean * @desc activate user on registration (only $sendActivationMail = false) */ 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) { diff --git a/controllers/RegistrationController.php b/controllers/RegistrationController.php index 7890b65..19c55e0 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\')->allowGuestRegister', + ), + array('deny', // deny all users + 'users'=>array('*'), + ), + ); + } /** * Declares class-based actions. */ 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 +} diff --git a/views/user/login.php b/views/user/login.php index 7064709..88ccdfa 100644 --- a/views/user/login.php +++ b/views/user/login.php @@ -33,13 +33,18 @@ - + getModule('user')->allowGuestRegister){ + ?>
getModule('user')->registrationUrl); ?> | getModule('user')->recoveryUrl); ?>