Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can hide regitration from guests #64

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'),

Expand Down
6 changes: 6 additions & 0 deletions UserModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand Down
21 changes: 12 additions & 9 deletions components/WebUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
29 changes: 28 additions & 1 deletion controllers/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
6 changes: 5 additions & 1 deletion migrations/m110805_153437_installYiiUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -209,4 +213,4 @@ private function readStdinUser($prompt, $field, $default = '') {
}
return $input;
}
}
}
9 changes: 7 additions & 2 deletions views/user/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@
<?php echo CHtml::activeLabelEx($model,'password'); ?>
<?php echo CHtml::activePasswordField($model,'password') ?>
</div>

<?php

if(Yii::app()->getModule('user')->allowGuestRegister){
?>
<div class="row">
<p class="hint">
<?php echo CHtml::link(UserModule::t("Register"),Yii::app()->getModule('user')->registrationUrl); ?> | <?php echo CHtml::link(UserModule::t("Lost Password?"),Yii::app()->getModule('user')->recoveryUrl); ?>
</p>
</div>

<?php
}
?>
<div class="row rememberMe">
<?php echo CHtml::activeCheckBox($model,'rememberMe'); ?>
<?php echo CHtml::activeLabelEx($model,'rememberMe'); ?>
Expand Down