Quantcast
Channel: Yii Framework Forum
Viewing all articles
Browse latest Browse all 18717

Authenticate With (Usergroups Module)

$
0
0
Hi everyone! :D

I want to use a full scale user management system, so I choose the UserGroups module to do so.

Now everything is working fine.

I can login like usual, but when I'm logged in, I want in some sensitive area for the user to re-enter his password to protect key data.

Now usually in "modules/userGroups/controllers/UserController.php"
...
public function actionLogin()
	{
		$model=new UserGroupsUser('login');

		// collect user input data
		if(isset($_POST['UserGroupsUser']))
		{
			$model->attributes=$_POST['UserGroupsUser'];
			// validate user input and redirect to the previous page if valid
			if($model->validate() && $model->login()) {
				$this->redirect(Yii::app()->user->returnUrl);
			}
		}
...


where it uses its own "modules/userGroups/components/UserGroupsIdentity.php"
...
	public function authenticate()
	{
		$model=UserGroupsUser::model()->findByAttributes(array('username' => $this->username));

		if(!count($model))
			$this->errorCode=self::ERROR_USERNAME_INVALID;
		else if((int)$model->status === UserGroupsUser::WAITING_ACTIVATION)
			$this->errorCode=self::ERROR_USER_INACTIVE;
		else if($model->password!==md5($this->password . $model->getSalt()))
			$this->errorCode=self::ERROR_PASSWORD_INVALID;
...


Everything works well ONLY FROM THE MODULE CONTROLLER!!!

When I'm inside my application, when I use my code:
...
if (isset($_POST['formVal']['password']))
                {                                                 
                        $UG_identity = new UserIdentity( Yii::app()->user->name, $_POST['formVal']['password'].$modelUG->getSalt());         
                        
                        if ($UG_identity->authenticate())
                        {
...


I get the exception:
Trying to get property of non-object
/var/www/xxxxxxxxx/protected/modules/userGroups/models/UserGroupsUser.php(542)
-Line(542) if (Yii::app()->controller->module->salt)


"/modules/userGroups/models/UserGroupsUser.php"
public function getSalt()
	{
		// TODO when stop supporting php 5.2 use dateTime
		// turn the creation_date into the corresponding timestamp
		list($date, $time) = explode(' ', $this->creation_date);
		$date = explode('-', $date);
		$time = explode(':', $time);

		date_default_timezone_set('UTC');
                $timestamp = mktime($time[0], $time[1], $time[2], $date[1], $date[2], $date[0]);
		// create the salt
		$salt = $this->username . $timestamp;
                Yii::app()->toolbox->alert('BOOM');
		// add the additional salt if it's provided
		if (Yii::app()->controller->module->salt)
			$salt .= Yii::app()->controller->module->salt;

		return $salt;
	}


Now I have the feeling it's not working because i'm inside my siteController reaching for the property inside a module, but this line: Yii::app()->controller->module->salt ask for

Yii::app()->siteController->userGroups->salt which of course don't exist.

Now how in the world can I use the function from one module from another controller?? :huh:

Thank you for your time :lol:

Viewing all articles
Browse latest Browse all 18717

Trending Articles