Skip to content
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
109 changes: 109 additions & 0 deletions UserModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,44 @@

class UserModule extends CWebModule
{
/**
* @var boolean
* @desc whether to hsow forget password link on login page
*/
public $showForgetPasswordLink = true;
/**
* @var boolean
* @desc whether to show register link on login page
*/
public $showRegisterLink = true;
/**
* @var string
* @desc layout for the login form
*/
public $userLayoutPath = "/user/login";
/**
* @var boolean
* @desc whether to use bootstrap widgets
*/
public $withBootstrap = false;
/**
* @var boolean
* @desc whether to include hybridauth widget in profile and login view
*/
public $withHybridAuth = false;

/**
* @var string
* @desc path to hybridauth module
*/
public $hybridAuthModulePath = "application.modules.hybridauth";

/**
* @var CDbConnection
* @desc database connection to use
*/
public $db = null;

/**
* @var int
* @desc items on page
Expand Down Expand Up @@ -271,4 +309,75 @@ public static function getUserByName($username) {
public function users() {
return User;
}

public static function getModuleId()
{
$stateKey = "usermodule.moduleid";

// Get module Id
if(!Yii::app()->user->hasState($stateKey))
{
$tmp = Yii::app()->getModules();
foreach($tmp as $key=>$value)
{
if(stripos($value['class'], "usermodule") !== false)
{
Yii::app()->user->setState($stateKey, $key);
}
}
}

return Yii::app()->user->getState($stateKey, "yii-user");
}

public static function module()
{
return Yii::app()->getModule(UserModule::getModuleId());
}

public static function newUser()
{

}

public static function newRegistrationFormModel()
{
return new RegistrationForm;
}

public static function registerUser($registrationFormModel, $profileData = array())
{
Profile::$regMode = true;
$model = RegistrationForm::model()->find("username='$registrationFormModel->username'");
if($model !== null)
{
return $model;
}
$model = new RegistrationForm;
$profile=new Profile;

$model->attributes=$registrationFormModel->attributes;
$model->verifyPassword = $model->password;
$profile->attributes=$profileData;
if($model->validate()&&$profile->validate())
{
$model->activkey=UserModule::encrypting(microtime().$model->password);
$model->password=UserModule::encrypting($model->password);
$model->verifyPassword=UserModule::encrypting($model->verifyPassword);
$model->superuser=0;
$model->status=User::STATUS_ACTIVE;

if ($model->save()) {
$profile->user_id=$model->id;
$profile->save();
return $model;
} else {
return $model->getErrors();
}
}else{
return array_merge($model->getErrors(), $profile->getErrors());
}

return null;
}
}
56 changes: 34 additions & 22 deletions components/UActiveRecord.php
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
<?php
class UActiveRecord extends CActiveRecord
{
/**
* Extends setAttributes to handle active date fields
*
* @param $values array
* @param $safeOnly boolean
*/
public function setAttributes($values,$safeOnly=true)
{
foreach ($this->widgetAttributes() as $fieldName=>$className) {
if (isset($values[$fieldName])&&class_exists($className)) {

class UActiveRecord extends CActiveRecord {
public function getDbConnection() {
$db = Yii::app()->getModule('user')->db;
if($db === null)
{
$db = Yii::app()->db;
}
return Yii::createComponent($db);
}

/**
* Extends setAttributes to handle active date fields
*
* @param $values array
* @param $safeOnly boolean
*/
public function setAttributes($values, $safeOnly = true) {
if(method_exists($this, "widgetAttribute")) {
foreach ($this->widgetAttributes() as $fieldName => $className) {
if (isset($values[$fieldName]) && class_exists($className)) {
$class = new $className;
$arr = $this->widgetParams($fieldName);
if ($arr) {
$newParams = $class->params;
$arr = (array)CJavaScript::jsonDecode($arr);
foreach ($arr as $p=>$v) {
if (isset($newParams[$p])) $newParams[$p] = $v;
$arr = (array) CJavaScript::jsonDecode($arr);
foreach ($arr as $p => $v) {
if (isset($newParams[$p]))
$newParams[$p] = $v;
}
$class->params = $newParams;
}
if (method_exists($class,'setAttributes')) {
$values[$fieldName] = $class->setAttributes($values[$fieldName],$this,$fieldName);
if (method_exists($class, 'setAttributes')) {
$values[$fieldName] = $class->setAttributes($values[$fieldName], $this, $fieldName);
}
}
}
parent::setAttributes($values,$safeOnly);
}

public function behaviors(){
return Yii::app()->getModule('user')->getBehaviorsFor(get_class($this));
}
parent::setAttributes($values, $safeOnly);
}

public function behaviors() {
return Yii::app()->getModule('user')->getBehaviorsFor(get_class($this));
}

}
2 changes: 1 addition & 1 deletion controllers/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function actionLogin()
}
}
// display the login form
$this->render('/user/login',array('model'=>$model));
$this->render(UserModule::module()->userLayoutPath,array('model'=>$model));
} else
$this->redirect(Yii::app()->controller->module->returnUrl);
}
Expand Down
2 changes: 1 addition & 1 deletion models/ProfileField.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class ProfileField extends CActiveRecord
class ProfileField extends UActiveRecord
{
const VISIBLE_ALL=3;
const VISIBLE_REGISTER_USER=2;
Expand Down
4 changes: 2 additions & 2 deletions models/User.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

class User extends CActiveRecord
class User extends UActiveRecord
{
const STATUS_NOACTIVE=0;
const STATUS_ACTIVE=1;
Expand Down Expand Up @@ -199,7 +199,7 @@ public function setLastvisit($value) {

public function afterSave() {
if (get_class(Yii::app())=='CWebApplication'&&Profile::$regMode==false) {
Yii::app()->user->updateSession();
//Yii::app()->user->updateSession();
}
return parent::afterSave();
}
Expand Down
12 changes: 10 additions & 2 deletions views/admin/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,16 @@
}
}
?>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save')); ?>
<div class="form-actions row buttons">
<?php if(UserModule::module()->withBootstrap) { ?>
<?php $this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save'),
)); ?>
<?php } else { ?>
<?php echo CHtml::submitButton($model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save')); ?>
<?php } ?>
</div>

<?php $this->endWidget(); ?>
Expand Down
14 changes: 11 additions & 3 deletions views/admin/_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,17 @@
<?php echo $form->dropDownList($model,'status',$model->itemAlias('UserStatus')); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton(UserModule::t('Search')); ?>
</div>
<div class="form-actions row buttons">
<?php if(UserModule::module()->withBootstrap) { ?>
<?php $this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>UserModule::t('Search'),
)); ?>
<?php } else { ?>
<?php echo CHtml::submitButton(UserModule::t('Search')); ?>
<?php } ?>
</div>

<?php $this->endWidget(); ?>

Expand Down
5 changes: 2 additions & 3 deletions views/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@

<p><?php echo UserModule::t("You may optionally enter a comparison operator (<b>&lt;</b>, <b>&lt;=</b>, <b>&gt;</b>, <b>&gt;=</b>, <b>&lt;&gt;</b> or <b>=</b>) at the beginning of each of your search values to specify how the comparison should be done."); ?></p>

<?php echo CHtml::link(UserModule::t('Advanced Search'),'#',array('class'=>'search-button')); ?>
<?php echo CHtml::link(UserModule::t('Advanced Search'),'#',array('class'=>'search-button btn')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->

<?php $this->widget('zii.widgets.grid.CGridView', array(
<?php $this->widget(UserModule::module()->withBootstrap ? "bootstrap.widgets.TbGridView" : 'zii.widgets.grid.CGridView', array(
'id'=>'user-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
Expand Down
2 changes: 1 addition & 1 deletion views/admin/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
)
);

$this->widget('zii.widgets.CDetailView', array(
$this->widget(UserModule::module()->withBootstrap ? "bootstrap.widgets.TbDetailView" : 'zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>$attributes,
));
Expand Down
11 changes: 9 additions & 2 deletions views/profile/changepassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@
<?php echo $form->error($model,'verifyPassword'); ?>
</div>


<div class="row submit">
<div class="form-actions row submit">
<?php if(UserModule::module()->withBootstrap) { ?>
<?php $this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>UserModule::t("Save"),
)); ?>
<?php } else { ?>
<?php echo CHtml::submitButton(UserModule::t("Save")); ?>
<?php } ?>
</div>

<?php $this->endWidget(); ?>
Expand Down
12 changes: 10 additions & 2 deletions views/profile/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,16 @@
<?php echo $form->error($model,'email'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save')); ?>
<div class="form-actions row buttons">
<?php if(UserModule::module()->withBootstrap) { ?>
<?php $this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save'),
)); ?>
<?php } else { ?>
<?php echo CHtml::submitButton($model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save')); ?>
<?php } ?>
</div>

<?php $this->endWidget(); ?>
Expand Down
9 changes: 8 additions & 1 deletion views/profile/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<?php echo Yii::app()->user->getFlash('profileMessage'); ?>
</div>
<?php endif; ?>
<table class="dataGrid">
<table class="dataGrid detail-view table table-striped table-condensed">
<tr>
<th class="label"><?php echo CHtml::encode($model->getAttributeLabel('username')); ?></th>
<td><?php echo CHtml::encode($model->username); ?></td>
Expand Down Expand Up @@ -54,3 +54,10 @@
<td><?php echo CHtml::encode(User::itemAlias("UserStatus",$model->status)); ?></td>
</tr>
</table>

<?php if(UserModule::module()->withHybridAuth) { ?>
<div>
Link your account:
<?php $this->widget(UserModule::module()->hybridAuthModulePath . '.widgets.renderProviders'); ?>
</div>
<?php } ?>
12 changes: 10 additions & 2 deletions views/profileField/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,16 @@
<?php echo CHtml::error($model,'visible'); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save')); ?>
<div class="form-actions row buttons">
<?php if(UserModule::module()->withBootstrap) { ?>
<?php $this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save'),
)); ?>
<?php } else { ?>
<?php echo CHtml::submitButton($model->isNewRecord ? UserModule::t('Create') : UserModule::t('Save')); ?>
<?php } ?>
</div>

<?php echo CHtml::endForm(); ?>
Expand Down
14 changes: 11 additions & 3 deletions views/profileField/_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,17 @@
<?php echo $form->dropDownList($model,'visible',ProfileField::itemAlias('visible')); ?>
</div>

<div class="row buttons">
<?php echo CHtml::submitButton(UserModule::t('Search')); ?>
</div>
<div class="form-actions row buttons">
<?php if(UserModule::module()->withBootstrap) { ?>
<?php $this->widget('bootstrap.widgets.TbButton',array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>UserModule::t('Search'),
)); ?>
<?php } else { ?>
<?php echo CHtml::submitButton(UserModule::t('Search')); ?>
<?php } ?>
</div>

<?php $this->endWidget(); ?>

Expand Down
Loading