Yii Framework Forum: Accessing Yii auth from non-yii php - Yii Framework Forum

Jump to content

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

Accessing Yii auth from non-yii php Rate Topic: -----

#1 User is offline   charris66 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 09-October 09
  • Location:BC, Canada

Posted 02 March 2010 - 07:49 PM

This is my first post and i'd like to say first off that I think Yii is a very good framework and I have used it for quite a few projects now with success.

I have a question regarding the user/auth mechanism. I am transitioning a site from vanilla php to Yii, and first off I am converting the members section. Everything works well but there is one thing I cannot figure out how to do. Basically, once a member signs in, the "Login" link should change to "Logout (username)" throughout the site. The problem I am having is that I cannot see a way to access the user's status and login details (set via Yii login) through plain php.

The way it is setup currently is something like this:

<?php   
    if (isset($_SESSION['loggedIn'] && $_SESSION['loggedIn'] === '1') {
        echo '<a href="/logout.php">Logout ('.getCurrentUsername().')</a>';
    else {
        echo '<a href="/login.php">Login</a>';
    }
?>


Is there a way to include some core Yii files to be able to access the CWebUser object? This would enable me to transition the frontend to Yii page-by-page.

Thanks in advance.

Chris

0

#2 User is offline   charris66 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 09-October 09
  • Location:BC, Canada

Posted 02 March 2010 - 11:29 PM

I think I have it solved. My idea is as follows:

Request
|
if file exists and is php file
|
pass request to yii entry script with catchAllRequest CWebApplication setting
|
load php file in controller and use Yii::app()->getUser() in existing php security check functions.

I'll try this out when I get to work tomorrow.
0

#3 User is offline   charris66 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 09-October 09
  • Location:BC, Canada

Posted 03 March 2010 - 02:10 PM

I just tried this and it does work. The catchAllRequest property actually belongs to CWebApplication and not CUrlManager so I changed that above in case anyone is looking for a similar solution.
0

#4 User is offline   bettor 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 751
  • Joined: 02-February 09

Posted 04 March 2010 - 05:36 AM

View Postcharris66, on 03 March 2010 - 02:10 PM, said:

Basically, once a member signs in, the "Login" link should change to "Logout (username)" throughout the site. The problem I am having is that I cannot see a way to access the user's status and login details (set via Yii login) through plain php.


are you looking for smth like
Yii::app()->user->isGuest

0

#5 User is offline   charris66 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 09-October 09
  • Location:BC, Canada

Posted 05 March 2010 - 02:04 AM

Yeah thanks I was looking for a way to be able to access that via an old site where I am changing the security functions to be run through Yii.
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