diff --git a/UserModule.php b/UserModule.php index cc624a9..6737cce 100644 --- a/UserModule.php +++ b/UserModule.php @@ -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 @@ -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; + } } diff --git a/components/UActiveRecord.php b/components/UActiveRecord.php index 2ad3c73..c77b4ee 100644 --- a/components/UActiveRecord.php +++ b/components/UActiveRecord.php @@ -1,35 +1,47 @@ 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)); + } + } \ No newline at end of file diff --git a/controllers/LoginController.php b/controllers/LoginController.php index db03de5..223d3cc 100644 --- a/controllers/LoginController.php +++ b/controllers/LoginController.php @@ -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); } diff --git a/models/ProfileField.php b/models/ProfileField.php index 3723ff9..d9283ca 100644 --- a/models/ProfileField.php +++ b/models/ProfileField.php @@ -1,6 +1,6 @@ user->updateSession(); + //Yii::app()->user->updateSession(); } return parent::afterSave(); } diff --git a/views/admin/_form.php b/views/admin/_form.php index 0d294c8..6ad5473 100644 --- a/views/admin/_form.php +++ b/views/admin/_form.php @@ -64,8 +64,16 @@ } } ?> -
- + endWidget(); ?> diff --git a/views/admin/index.php b/views/admin/index.php index c4706b9..19cd76a 100644 --- a/views/admin/index.php +++ b/views/admin/index.php @@ -29,14 +29,13 @@<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done."); ?>
-'search-button')); ?> +'search-button btn')); ?> - -widget('zii.widgets.grid.CGridView', array( +widget(UserModule::module()->withBootstrap ? "bootstrap.widgets.TbGridView" : 'zii.widgets.grid.CGridView', array( 'id'=>'user-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, diff --git a/views/admin/view.php b/views/admin/view.php index 4f2dafe..38ae3c6 100644 --- a/views/admin/view.php +++ b/views/admin/view.php @@ -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, )); diff --git a/views/profile/changepassword.php b/views/profile/changepassword.php index 74a8fa5..5c25e2c 100644 --- a/views/profile/changepassword.php +++ b/views/profile/changepassword.php @@ -49,9 +49,16 @@ error($model,'verifyPassword'); ?> - -| getAttributeLabel('username')); ?> | username); ?> | @@ -54,3 +54,10 @@status)); ?> |
|---|
<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done."); ?>
-'search-button')); ?> + 'search-button btn')); ?> -widget('zii.widgets.grid.CGridView', array( - 'dataProvider'=>$model->search(), - 'filter'=>$model, - 'columns'=>array( - 'id', - array( - 'name'=>'varname', - 'type'=>'raw', - 'value'=>'UHtml::markSearch($data,"varname")', - ), - array( - 'name'=>'title', - 'value'=>'UserModule::t($data->title)', - ), - array( - 'name'=>'field_type', - 'value'=>'$data->field_type', - 'filter'=>ProfileField::itemAlias("field_type"), - ), - 'field_size', - //'field_size_min', - array( - 'name'=>'required', - 'value'=>'ProfileField::itemAlias("required",$data->required)', - 'filter'=>ProfileField::itemAlias("required"), - ), - //'match', - //'range', - //'error_message', - //'other_validator', - //'default', - 'position', - array( - 'name'=>'visible', - 'value'=>'ProfileField::itemAlias("visible",$data->visible)', - 'filter'=>ProfileField::itemAlias("visible"), - ), - //*/ - array( - 'class'=>'CButtonColumn', - ), - ), -)); ?> +widget(UserModule::module()->withBootstrap ? "bootstrap.widgets.TbGridView" : 'zii.widgets.grid.CGridView', array( + 'dataProvider' => $model->search(), + 'filter' => $model, + 'columns' => array( + 'id', + array( + 'name' => 'varname', + 'type' => 'raw', + 'value' => 'UHtml::markSearch($data,"varname")', + ), + array( + 'name' => 'title', + 'value' => 'UserModule::t($data->title)', + ), + array( + 'name' => 'field_type', + 'value' => '$data->field_type', + 'filter' => ProfileField::itemAlias("field_type"), + ), + 'field_size', + //'field_size_min', + array( + 'name' => 'required', + 'value' => 'ProfileField::itemAlias("required",$data->required)', + 'filter' => ProfileField::itemAlias("required"), + ), + //'match', + //'range', + //'error_message', + //'other_validator', + //'default', + 'position', + array( + 'name' => 'visible', + 'value' => 'ProfileField::itemAlias("visible",$data->visible)', + 'filter' => ProfileField::itemAlias("visible"), + ), + //*/ + array( + 'class' => 'CButtonColumn', + ), + ), +)); +?> diff --git a/views/profileField/view.php b/views/profileField/view.php index febb55b..0dd4261 100644 --- a/views/profileField/view.php +++ b/views/profileField/view.php @@ -13,7 +13,7 @@ ?>- getModule('user')->registrationUrl); ?> | getModule('user')->recoveryUrl); ?> + showRegisterLink) echo CHtml::link(UserModule::t("Register"),Yii::app()->getModule('user')->registrationUrl); ?> showRegisterLink && UserModule::module()->showForgetPasswordLink) echo "|"; ?> showForgetPasswordLink) echo CHtml::link(UserModule::t("Lost Password?"),Yii::app()->getModule('user')->recoveryUrl); ?>