Chyrp

User

The User model.

See Also

Model

Summary
User The User model.
Functions
__construct Model::grab
find Model::search
authenticate Checks to see if a given Login and Password match a user in the database.
add Adds a user to the database with the passed username, password, and e-mail.
update Updates the user with the given login, password, full name, e-mail, website, and Group ID.
delete Deletes a given user.  Calls the delete_user trigger and passes the User as an argument.
hashPassword Creates a secure hash of a user’s password.
checkPassword Checks a given password against the stored hash.
group Returns a user’s group.  Example: $user->group->can(“do_something”)
posts Returns all the posts of the user.
pages Returns all the pages of the user.

Functions

__construct

public function __construct( $user_id,   
$options  =  array() )

See Also

Model::grab

find

static function find( $options  =  array(),
$options_for_object  =  array() )

See Also

Model::search

authenticate

static function authenticate( $login,
$password )

Checks to see if a given Login and Password match a user in the database.

Parameters

$login The Login to check.
$password The matching Password to check.

Returns

true or false

add

static function add( $login,   
$password,   
$email,   
$full_name  =  "",
$website  =  "",
$group_id  =  null,
$joined_at  =  null )

Adds a user to the database with the passed username, password, and e-mail.

Calls the add_user trigger with the inserted user.

Parameters

$login The Login for the new user.
$password The Password for the new user.  Don’t hash this, it’s done in the function.
$email The E-Mail for the new user.

Returns

The newly created User.

See Also

update

update

public function update( $login  =  null,
$password  =  null,
$email  =  null,
$full_name  =  null,
$website  =  null,
$group_id  =  null,
$joined_at  =  null )

Updates the user with the given login, password, full name, e-mail, website, and Group ID.

Passes all of the arguments to the update_user trigger.

Parameters

$login The new Login to set.
$password The new Password to set, already encoded.
$full_name The new Full Name to set.
$email The new E-Mail to set.
$website The new Website to set.
$group_id The new Group to set.

See Also

add

delete

static function delete( $id )

Deletes a given user.  Calls the delete_user trigger and passes the User as an argument.

Parameters

$id The user to delete.

hashPassword

static function hashPassword( $password )

Creates a secure hash of a user’s password.

Parameters

$password The unhashed password.

Returns

The securely hashed password to be stored in the database.

checkPassword

static function checkPassword( $password,
$storedHash )

Checks a given password against the stored hash.

Parameters

$password The unhashed password given during a login attempt.
$storedHash The stored hash for the user.

Returns

true or false

group

public function group()

Returns a user’s group.  Example: $user->group->can(“do_something”)

!!  DEPRECATED AFTER 2.0 !!

posts

public function posts()

Returns all the posts of the user.

!!  DEPRECATED AFTER 2.0 !!

pages

public function pages()

Returns all the pages of the user.

!!  DEPRECATED AFTER 2.0 !!