[Module] Yii User Management Module

Hi guys, I’m going crazy here. I have installed and re-installed this module multiple times, but can’t get it to work.

The problem I’m having is this:

  1. After instalation I can log in as admin and go to r=user/user/admin to see the user management dashboard where I can click around and do stuff.

  2. After I log out and log in again as admin I get "Error 403, You are not authorized to perform this action." when going to r=user/user/admin…

Also on the second login, nothing works properly when I go to r=user/user/index…

-If I click on a user from the user index site I get:

"Fatal error: Call to a member function getFriends() on a non-object in C:\wamp\www\datasources\protected\modules\friendship\controllers\YumFriendshipController.php on line 150"

-If I try to update my profile I get:

“DbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column ‘admin’ in ‘where clause’. The SQL statement executed was: SELECT * FROM message t WHERE to_user_id = admin and message_read = 0 ORDER BY timestamp DESC LIMIT 10”.

Basically nothing seems to work properly anymore after I login a second time.

I followed the installation steps and tried to apply fixes that I found when searching, but nothing seems to worl :(

Sorry if I’m being unspecific, I’m new and don’t know what to do…

I’m using WAMP with PHP 5.3.13

[b]Can you please post your configuration file? :)

Anyway, have you tried follow my step-by-step tutorial? http://www.yiiframework.com/forum/index.php/topic/7591-module-yii-user-management-module/page__view__findpost__p__189681[/b]

I did follow your tutorial, very good :) Maybe I missed something.

Here is the config file:




return array(

	'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',

	'name'=>'My Web Application',


	// preloading 'log' component

	'preload'=>array('log'),


	// autoloading model and component classes

	'import'=>array(

                'application.modules.user.models.*',

                'application.modules.profile.models.*',

		'application.models.*',

		'application.components.*',

	),


	'modules'=>array(

                'user' => array(

                    'debug' => false,

                    'userTable' => 'user',

                    'translationTable' => 'translation',

                ),

                'usergroup' => array(

                    'usergroupTable' => 'usergroup',

                    'usergroupMessageTable' => 'user_group_message',

                ),

                'membership' => array(

                    'membershipTable' => 'membership',

                    'paymentTable' => 'payment',

                ),

                'friendship' => array(

                    'friendshipTable' => 'friendship',

                ),

                'profile' => array(

                    'privacySettingTable' => 'privacysetting',

                    'profileFieldTable' => 'profile_field',

                    'profileTable' => 'profile',

                    'profileCommentTable' => 'profile_comment',

                    'profileVisitTable' => 'profile_visit',

                ),

                'role' => array(

                    'roleTable' => 'role',

                    'userRoleTable' => 'user_role',

                    'actionTable' => 'action',

                    'permissionTable' => 'permission',

                ),

                'message' => array(

                    'messageTable' => 'message',

                ),

		// uncomment the following to enable the Gii tool

		/*

		'gii'=>array(

			'class'=>'system.gii.GiiModule',

			'password'=>'Enter Your Password Here',

			// If removed, Gii defaults to localhost only. Edit carefully to taste.

			'ipFilters'=>array('127.0.0.1','::1'),

		),

		*/

	),


	// application components

	'components'=>array(

                'cache' => array(

                        'class' => 'system.caching.CDummyCache'

                ),

                'session' => array(

                        'sessionName' => 'SiteSession',

                        'class' => 'CHttpSession',

                        'autoStart' => true,

		),

		'user'=>array(

                        'class' => 'application.modules.user.components.YumWebUser',

			// enable cookie-based authentication

			'allowAutoLogin'=>true,

                        'loginUrl' => array('//user/user/login'),

		),

		// uncomment the following to enable URLs in path-format

		/*

		'urlManager'=>array(

			'urlFormat'=>'path',

			'rules'=>array(

				'<controller:\w+>/<id:\d+>'=>'<controller>/view',

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),

		*/

		'db'=>array(

                        'tablePrefix' => '',

			'connectionString' => 'mysql:host=localhost;dbname=xxxxxx',

			'emulatePrepare' => true,

			'username' => 'admin',

			'password' => 'admin',

			'charset' => 'utf8',

                        'tablePrefix' => '',

		),

		'errorHandler'=>array(

			// use 'site/error' action to display errors

			'errorAction'=>'site/error',

		),

		'log'=>array(

			'class'=>'CLogRouter',

			'routes'=>array(

				array(

					'class'=>'CFileLogRoute',

					'levels'=>'error, warning',

				),

				// uncomment the following to show log messages on web pages

				/*

				array(

					'class'=>'CWebLogRoute',

				),

				*/

			),

		),

	),


	// application-level parameters that can be accessed

	// using Yii::app()->params['paramName']

	'params'=>array(

		// this is used in contact page

		'adminEmail'=>'webmaster@example.com',

	),

);



try import the modules after import the components and the models…probably can solve the problem…

or maybe because you are using the CHttpSession… idk, try comment that, if the tip before doesnt work

I tried to change the import order, but it didn’t affect anything. But I think you are on to something with sessions :) I removed this part:




'session' => array(

                        'sessionName' => 'SiteSession',

                        'class' => 'CHttpSession',

                        'autoStart' => true,

),



And it worked at first, but after login out and login in again, the problem re-appeared. I know nothing about sessions, what should I try next?

try a really fresh new install, exactly how i have do in the tutorial.

if after that, all is working, modify what you need, and keep testing if continues working

I’ve installed the module, however on thepages that contain an edit form (for instance, editing a user) there is no header or footer, just the form. Any idea how to fix this, or what caused it?

try add this to your config:


 'user' => array(

              	(...)

              	'baseLayout' => 'webroot.themes.YOUR_THEME_NAME.views.layouts.main',

I’m afraid it doesn’t work :( For instance, /user/user/update/id/1 is one of the pages that doesn’t display a header/footer; user/user/view/id/1 does.

can you post a print screen please?

and maybe, the html code.




<div class="form">

<form id="user-form" action="/dkk/index.php/user/user/update/id/1" method="post">

<div class="note">

<p class="note">Fields with <span class="required">*</span> are required.</p>

	</div>


<div style="float: right; margin: 10px;">

<div class="row">

<label for="YumUser_superuser" class="required">Superuser <span class="required">*</span></label><select name="YumUser[superuser]" id="YumUser_superuser">

<option value="0">No</option>

<option value="1" selected="selected">Yes</option>

</select></div>


<div class="row">

<label for="YumUser_status" class="required">Status <span class="required">*</span></label><select name="YumUser[status]" id="YumUser_status">

<option value="0">Not active</option>

<option value="1" selected="selected">Active</option>

<option value="-1">Banned</option>

<option value="-2">Deleted</option>

</select></div>

<div class="row roles">

<p> User belongs to these roles </p>


	

Screenshot: i.imgur.com/3v1wd98.png (can’t post a link due to my being new here)

really wired :\ sorry, i cant remember something to help you \:

Anyway I can debug it? I’m quite decent with PHP, just new to Yii…

have you changed some controllers of the YUM?

the only thing i can say is, try new fresh install with my tutorial… :\

I am using Yii user Managment module to develop my web application,the module itself uses its component and identity,the YumWebUser Class extends CWebUser of yii,however when a user try to perform an action that requires login it takes him to login but doesnt set the returnUrl after the user has successfully logged in.


public function loginRequired()

        {

                $app=Yii::app();

                $request=$app->getRequest();


                if(!$request->getIsAjaxRequest())

                        $this->setReturnUrl($request->getUrl());

                elseif(isset($this->loginRequiredAjaxResponse))

                {

                    echo $this->loginRequiredAjaxResponse;

                    Yii::app()->end();

            }


            if(($url=$this->loginUrl)!==null)

            {

                    if(is_array($url))

                    {

                            $route=isset($url[0]) ? $url[0] : $app->defaultController;

                            $url=$app->createUrl($route,array_splice($url,1));

                    }

                    $request->redirect($url);

            }

            else

                    throw new CHttpException(403,Yii::t('yii','Login Required'));

    }

i tried to go deep and watched variables values and noticed that the loginRequired method is being called and sets the returnUrl at


if(!$request->getIsAjaxRequest()) 

$this->setReturnUrl($request->getUrl());

At this point the returnUrl is still the one the same i want to redirect user to but after the redirection point


$request->redirect($url); 

the returnUrl is the defauot one.(/localhost/index.php)

has anyone succeeded in making usergroups private to its members and invitation based only?

Hello all,

I’m trying to create a registration widget for the yii user management so i can display it with a modal dialog. So far i managed to create and display the dialog, but when i submit the form it shows me an error saying that the captcha code is wrong. Here’s My code:

Myregistrationcontroller.php




<?php


Yii::import('application.modules.registration.controllers.YumRegistrationController');

class MyregistrationController extends YumRegistrationController {

 

 

 public function actionRegistration() {

		// When we override the registrationUrl, this one is not valid anymore!

		if(Yum::module('registration')->registrationUrl != array(

					'//registration/registration/registration'))

			throw new CHttpException(403);


		Yii::import('application.modules.profile.models.*');

		$form = new YumRegistrationForm;

		$profile = new YumProfile;


		$this->performAjaxValidation('YumRegistrationForm', $form);


		if (isset($_POST['YumRegistrationForm'])) { 

			$form->attributes = $_POST['YumRegistrationForm'];

			$profile->attributes = $_POST['YumProfile'];


			$form->validate();

			$profile->validate();


			if(!$form->hasErrors() && !$profile->hasErrors()) {

				$user = new YumUser;

				$user->register($form->username, $form->password, $profile);


				$this->sendRegistrationEmail($user);

				Yum::setFlash('Thank you for your registration. Please check your email.');

				$this->redirect(Yum::module()->loginUrl);

			}

		} 


		$this->render('myregistration', array(

					'form' => $form,

					'profile' => $profile,

					)

				);  

	}

}



myregistration.php





<h2> <?php echo Yum::t('Registration'); ?> </h2>


<?php $this->breadcrumbs = array(Yum::t('Registration')); ?>


<div class="form">

<?php $activeform = $this->beginWidget('CActiveForm', array(

			'id'=>'registration-form',

			'enableAjaxValidation'=>true,

			'enableClientValidation'=>true,

			'focus'=>array($form,'username'),

			));

?>


<?php echo Yum::requiredFieldNote(); ?>

<?php echo CHtml::errorSummary(array($form, $profile)); ?>


<div class="row"> <?

echo $activeform->labelEx($form,'username');

echo $activeform->textField($form,'username');

?> </div>


<div class="row"> <?

echo $activeform->labelEx($profile,'email');

echo $activeform->textField($profile,'email');

?> </div>  


<div class="row"> <?

echo $activeform->labelEx($profile,'firstname');

echo $activeform->textField($profile,'firstname');

?> </div>  


<div class="row"> <?

echo $activeform->labelEx($profile,'lastname');

echo $activeform->textField($profile,'lastname');

?> </div>  


<div class="row">

<?php echo $activeform->labelEx($form,'password'); ?>

<?php echo $activeform->passwordField($form,'password'); ?>

</div>


<div class="row">

<?php echo $activeform->labelEx($form,'verifyPassword'); ?>

<?php echo $activeform->passwordField($form,'verifyPassword'); ?>

</div>


<?php if(extension_loaded('gd') 

			&& Yum::module('registration')->enableCaptcha): ?>

	<div class="row">

		<?php echo CHtml::activeLabelEx($form,'verifyCode'); ?>

		<div>

		<?php $this->widget('CCaptcha'); ?>

		<?php echo CHtml::activeTextField($form,'verifyCode'); ?>

		</div>

		<p class="hint">

		<?php echo Yum::t('Please enter the letters as they are shown in the image above.'); ?>

		<br/><?php echo Yum::t('Letters are not case-sensitive.'); ?></p>

	</div>

	<?php endif; ?>

	

	<div class="row submit">

		<?php echo CHtml::submitButton(Yum::t('Registration')); ?>

	</div>


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

</div><!-- form -->



RegistrationWidget.php


<?php


class RegistrationWidget extends CWidget

{

	public $title='Registration';

    public $visible=true; 

 

    public function init()

    {

        if($this->visible)

        {

 

        }

    }

 

    public function run()

    {

        if($this->visible)

        {

            $this->renderContent();

        }

    }

 

    protected function renderContent()

    {

    	Yii::import('application.modules.profile.models.*');

        $form = new YumRegistrationForm;

		$profile = new YumProfile;

		if (isset($_POST['YumRegistrationForm'])) { 

			$profile->attributes = $_POST['Profile'];

			$profile->validate();

			if(!$profile->hasErrors()) {

				$user = new YumUser;

				$user->register($profile->username, $profile->password, $profile);

				$this->redirect(Yum::module()->loginUrl);

			}

		}

        $this->render('Registration', array('form' => $form,'profile' => $profile));  

    }   

}



registration.php


<?php if(Yii::app()->user->isGuest) : ?>

 

<?php 

if($form->getErrors() != null) {

   $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

     'id'=>'userloginwidget',

     'cssFile'=>'jquery-ui-1.8.7.custom.css',

     'theme'=>'redmond',

     'themeUrl'=>Yii::app()->request->baseUrl.'/css/ui',

     'options'=>array(

         'title'=>'Registration Errors',

         'autoOpen'=>true,

         'modal'=>true,

         'width'=>350,

     ),

   ));

}else{

   $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

     'id'=>'userloginwidget',

     'cssFile'=>'jquery-ui-1.8.7.custom.css',

     'theme'=>'redmond',

     'themeUrl'=>Yii::app()->request->baseUrl.'/css/ui',

     'options'=>array(

         'title'=>'Registration',

         'autoOpen'=>false,

         'modal'=>true,

         'width'=>300,

     ),

   ));

}

?>

<div class="form"> 

<?php echo CHtml::beginForm(Yii::app()->baseUrl.'/index.php/myregistration'); ?>

 

<div class="row"> <?

echo CHtml::activeLabel($form,'username');

echo CHtml::activeTextField($form,'username');

?> </div>


<div class="row"> <?

echo CHtml::activeLabel($profile,'email');

echo CHtml::activeTextField($profile,'email');

?> </div>  


<div class="row"> <?

echo CHtml::activeLabel($profile,'firstname');

echo CHtml::activeTextField($profile,'firstname');

?> </div>  


<div class="row"> <?

echo CHtml::activeLabel($profile,'lastname');

echo CHtml::activeTextField($profile,'lastname');

?> </div>  


<div class="row">

<?php echo CHtml::activeLabel($form,'password'); ?>

<?php echo CHtml::activeTextField($form,'password'); ?>

</div>


<div class="row">

<?php echo CHtml::activeLabel($form,'verifyPassword'); ?>

<?php echo CHtml::activeTextField($form,'verifyPassword'); ?>

</div>


<?php if(extension_loaded('gd') && Yum::module('registration')->enableCaptcha): ?>

	<div class="row">

		<?php echo CHtml::activeLabelEx($form,'verifyCode'); ?>

		<div>

		<?php $this->widget('CCaptcha'); ?>

		<?php echo CHtml::activeTextField($form,'verifyCode'); ?>

		</div>

		<p class="hint">

		<?php echo Yum::t('Please enter the letters as they are shown in the image above.'); ?>

		<br/><?php echo Yum::t('Letters are not case-sensitive.'); ?></p>

	</div>

<?php endif; ?>

	

<div class="row submit">

	<?php echo CHtml::submitButton(Yum::t('Registration')); ?>

</div>

 

<?php echo CHtml::endForm(); ?>

</div> 

<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>

<?php endif; ?>

main.php




...

<body>

<script type="text/javascript">

function doStuff()

{

	$("#yw1_button").trigger("click");

	$("#userloginwidget").dialog("open"); 

    return false; 

}

 

</script>


<div class="container" id="page">


	<div id="header">

		<div id="logo"><?php echo CHtml::encode(Yii::app()->name); ?></div>

	</div><!-- header -->

	

	<div id="mainmenu">

		<?php $this->widget('zii.widgets.CMenu',array(

			'items'=>array(

				array('label'=>'Home', 'url'=>array('/site/index')),

				array('label'=>'About', 'url'=>array('/site/page', 'view'=>'about')),

				array('label'=>'Contact', 'url'=>array('/site/contact')),

				array('label'=>'Login', 'url'=>array('/user/auth'), 'visible'=>Yii::app()->user->isGuest),

				array('label'=>'Logout ('.Yii::app()->user->name.')', 'url'=>array('/site/logout'), 'visible'=>!Yii::app()->user->isGuest),

				array('label'=>'Registration', 'url'=>'#','linkOptions'=>array( 'onclick'=>'doStuff();'), 'visible'=>Yii::app()->user->isGuest),

			),

		)); ?>

	</div><!-- mainmenu -->

	<?php	$this->widget('RegistrationWidget',array('visible'=>Yii::app()->user->isGuest)); ?>

...



The doStuff() is used for both opening the dialog and to refresh the captcha every opening.

Do you have any hint?

Thanks

maybe this can help, i hope

http://www.yiiframew…odulo=dialogbox

and another thing, try add this to your site controller:


	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to access 'index' and 'view' actions.

				'actions'=>array('...','captcha','...'),

				'users'=>array('*')

...


	public function actions()

	{

		return array(

			// captcha action renders the CAPTCHA image displayed on the contact page

			'captcha'=>array(

				'class'=>'CCaptchaAction',

				'backColor'=>0xFFFFFF

...

Finally managed to do it… if I have enough time i’ll post the solution

I have been working on this for a while now. Documentation really needs some improvements.

My question is related to permission & subordiate_id. How do I use that and how does it affect the permission system.

eg.


Action = Can_add_one 

Permission = To Role A 


Action = Can_add_two

Permission = To Role B

if I use subordinate when granting permission, how does it effect and how to use it?

Regards,

Shoeb Surya