Class TDbUser

Description

TDbUser class

TDbUser is the base user class for using together with TDbUserManager. Two methods are declared and must be implemented in the descendant classes:

  • validateUser(): validates if username and password are correct entries.
  • createUser(): creates a new user instance given the username

  • abstract:
  • since: 3.1.0
  • version: $Id: TDbUserManager.php 2244 2007-09-26 13:15:56Z xue $
  • author: Qiang Xue <qiang.xue@gmail.com>

Located in /Security/TDbUserManager.php (line 223)

TComponent
   |
   --TUser
      |
      --TDbUser
Method Summary
TDbUser createUser (string $username)
void saveUserToCookie (THttpCookie $cookie)
boolean validateUser (string $username, string $password)
Methods
createUser (line 278)

Creates a new user instance given the username.

This method usually needs to retrieve necessary user information (e.g. role, name, rank, etc.) from the user database according to the specified username. The newly created user instance should be initialized with these information.

If the username is invalid (not found in the user database), null should be returned.

You may use DbConnection to deal with database.

  • return: the newly created and initialized user instance
  • access: public
  • abstract:
TDbUser createUser (string $username)
  • string $username: username (case-sensitive)
createUserFromCookie (line 296)

Creates a new user instance given the cookie containing auth data.

This method is invoked when TAuthManager::setAllowAutoLogin is set true. The default implementation simply returns null, meaning no user instance can be created from the given cookie.

If you want to support automatic login (remember login), you should override this method. Typically, you obtain the username and a unique token from the cookie's value. You then verify the token is valid and use the username to create a user instance.

  • return: the user instance generated based on the cookie auth data, null if the cookie does not have valid auth data.
  • access: public
  • since: 3.1.1
  • see: TDbUser::saveUserToCookie()
TDbUser createUserFromCookie (THttpCookie $cookie)
  • THttpCookie $cookie: the cookie storing user authentication information
getDbConnection (line 232)

Returns a database connection that may be used to retrieve data from database.

  • return: database connection that may be used to retrieve data from database
  • access: public
TDbConnection getDbConnection ()
saveUserToCookie (line 316)

Saves necessary auth data into a cookie.

This method is invoked when TAuthManager::rememberLogin is invoked. The default implementation does nothing, meaning auth data is not stored in the cookie (and thus automatic login is not supported.)

If you want to support automatic login (remember login), you should override this method. Typically, you generate a unique token according to the current login information and save it together with the username in the cookie's value. You should avoid revealing the password in the generated token.

void saveUserToCookie (THttpCookie $cookie)
  • THttpCookie $cookie: the cookie to store the user auth information
validateUser (line 261)

Validates if username and password are correct entries.

Usually, this is accomplished by checking if the user database contains this (username, password) pair. You may use DbConnection to deal with database.

  • return: whether the validation succeeds
  • access: public
  • abstract:
boolean validateUser (string $username, string $password)
  • string $username: username (case-sensitive)
  • string $password: password

Inherited Methods

Inherited From TUser

TUser::__construct()
TUser::getIsGuest()
TUser::getManager()
TUser::getName()
TUser::getRoles()
TUser::getState()
TUser::getStateChanged()
TUser::isInRole()
TUser::loadFromString()
TUser::saveToString()
TUser::setIsGuest()
TUser::setName()
TUser::setRoles()
TUser::setState()
TUser::setStateChanged()

Inherited From TComponent

TComponent::addParsedObject()
TComponent::attachEventHandler()
TComponent::canGetProperty()
TComponent::canSetProperty()
TComponent::createdOnTemplate()
TComponent::detachEventHandler()
TComponent::evaluateExpression()
TComponent::evaluateStatements()
TComponent::getEventHandlers()
TComponent::getSubProperty()
TComponent::hasEvent()
TComponent::hasEventHandler()
TComponent::hasProperty()
TComponent::raiseEvent()
TComponent::setSubProperty()
TComponent::__get()
TComponent::__set()

Documentation generated on Mon, 21 Apr 2008 11:34:54 -0400 by phpDocumentor 1.3.0RC4