Monday, August 20, 2012

Creating Login and Logout Operation for Forum Application Software Yii Framework

Now I will make action to login. The first time we did generate application code Yii, Yii automatically been providing the login form and action. Rather than create it from scratch, but we'll modify the login action that has been provided by Yii. You can see the code that processes the login action in "protected/controllers/SiteController.php", "protected/view/site/login.php", "protected/models/LoginForm.php", and "protected/Components/UserIdentify.php". Although there are many log files related action, but we will modify only UserIdentify.php.
class UserIdentity extends CUserIdentity
{
 private $_id;

 public function authenticate()
 {
  $username = strtolower($this->username);
  $user = User::model()->find('LOWER(username)=?', array($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->id;
   $this->username = $user->username;
   $this->errorCode = self::ERROR_NONE;
  }
  return $this->errorCode == self::ERROR_NONE;
 }

 public function getId()
 {
  return $this->_id;
 }
}
The above code works retrieved from the user table and match the username and password have been inputted by the user. Surely that would be matched password is the password that has been encrypted. If the username and password that matches the user inputted username and password exist in the database, the user is logged in successfully.

Okay, we have finished making the menu register, login, and logout. Logout menu is available directly from Yii and do not need to be modified again. Please try these actions!

1 comment:

  1. Sands Casino Resort Atlantic City | $400 Welcome Bonus
    Sign up at Sands Casino septcasino Resort, play your 제왕카지노 favorite online slots, and hit jackpots in our newly remodeled 온카지노 resort. Book your room today.

    ReplyDelete

Yii Framework Tutorials