Yii Framework Forum: Authenticate With (Usergroups Module) - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Authenticate With (Usergroups Module) Rate Topic: -----

#1 User is offline   Ƒяąȼţąℓ ϻɨɲď 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 04-May 12

Posted 31 March 2013 - 08:37 PM

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:
0

#2 User is offline   Ƒяąȼţąℓ ϻɨɲď 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 04-May 12

Posted 03 April 2013 - 06:06 PM

Up! :D
0

#3 User is offline   Ƒяąȼţąℓ ϻɨɲď 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 04-May 12

Posted 09 April 2013 - 07:36 PM

Up! Up! ;)
0

#4 User is offline   Ƒяąȼţąℓ ϻɨɲď 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 68
  • Joined: 04-May 12

Posted 15 April 2013 - 04:05 PM

Up!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users