Yii Framework Forum: User - Admin or guest - Yii Framework Forum

Jump to content

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

User - Admin or guest Rate Topic: -----

#1 User is offline   Ted 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-July 10

Posted 25 July 2010 - 12:27 PM

I am using the authenticate function in the UserIdentity component to check a users details in the database. This works fine. In my database table User I have a column called admin (0 = guest 1 = admin). How do I set this in this function, then call it in my scripts to determine if the user has admin privliages (1) or guest privlages (0).

public function authenticate()
{

$user=User::model()->find('LOWER(email)=?',array(strtolower($this->username)));
if($user===null)
$this->errorCode=self::ERROR_USERNAME_INVALID;
else if(!$user->validatePassword($this->password))
$this->errorCode=self::ERROR_PASSWORD_INVALID;
else
{
$this->_id=$user->userId;
$this->username=$user->email;
$this->errorCode=self::ERROR_NONE;
}
return $this->errorCode==self::ERROR_NONE;

}
0

#2 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 25 July 2010 - 02:07 PM

$user=User::model()->find(...);
$rights = $user->admin;


are you sure it works?
$user=User::model()->find('LOWER(email)=?',array(strtolower($this->username)));

0

#3 User is offline   Ted 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-July 10

Posted 25 July 2010 - 02:09 PM

View Postfrantic, on 25 July 2010 - 02:07 PM, said:

$user=User::model()->find(...);
$rights = $user->admin;


are you sure it works?
$user=User::model()->find('LOWER(email)=?',array(strtolower($this->username)));



Yeah is there anything you might think is wrong with that?
0

#4 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 08-May 09

Posted 25 July 2010 - 02:09 PM

http://www.yiiframew...oc/cookbook/60/
0

#5 User is offline   frantic 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 172
  • Joined: 01-March 10
  • Location:Saint-Petersburg

Posted 25 July 2010 - 02:13 PM

View PostTed, on 25 July 2010 - 02:09 PM, said:

Yeah is there anything you might think is wrong with that?

I'm about parameters in find method. I usually write something like this:
$user = User::model()->find(array(
	'condition' => 'LOWER(email) = :email',
	'params' => array(':email' => strtolower($this->username)),
));


But if it works no difference :)
0

#6 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 26 July 2010 - 02:10 AM

View PostTed, on 25 July 2010 - 02:09 PM, said:

Yeah is there anything you might think is wrong with that?


@Ted:
Hehe, i thought i've read this syntax somewhere in the guide - but i guess i was wrong. The only place this way of passing parameters is mentioned seems to be in the API docs for bindParam/bindValue which are used by AR internally. So, that's why this works, too. Just curious, can you tell where you learned this syntax?
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