The User Class

User creation and manipulation.

Functions

User::confirmUsername

Definition

Name
User::confirmUsername
Syntax
Integer|Array|False = User::confirmUsername( String $username, String $verification_code );

Description

Verify and activate user (if not already verified).

Deletes verification reminder log for username.

Parameters

$username
String The username to be verified
$verification_code
String The verification code associated with the username

Return values

Integer $user_id if the username is succesfully confirmed. The username will be verified and the user will be activated (status = 1).

Array with the element "status" => "USER_VERIFIED" if the username is already verified.

False if confirmation fails (wrong username and/or wrong verification code).

Examples

$UC = new User(); $username = "example@parentnode.dk"; $verification_code = "7dof205k"; $user_id = $UC->confirmUsername($username, $verification_code);

Dependencies

Janitor
  • Query
  • Page::addLog

User::setPassword

Definition

Name
User::setPassword
Syntax
Array|Boolean = User::setPassword( Array $action );

Description

Saves a new password posted by current user. If user has a password already, this is also posted for validation.

Parameters

$action
array action array
Action parameters
$action[0]
"setPassword"|arbitrary parameter

Return values

Array with the value "error" => "wrong_password" if the old password is not successfully verified. The new password is not saved.

False if the new password is not saved (password is not validated successfully or exactly one action parameter is not received.)

True if the new password is successfully saved.

Examples

Example 1
$_POST["old_password"] = "SuperSecretAndWrongOldPassword"; $_POST["new_password"] = "SuperSecretNewPassword"; $UC = new User(); $result = $UC->setPassword($action);

Returns an array with information about the result of the function call. The new password was not saved, since the old password was not succesfully verified.

$result = ( ["error"] => "wrong_password" )
Example 2
$_POST["old_password"] = "SuperSecretAndCorrectOldPassword"; $_POST["new_password"] = "SuperSecretNewPassword"; $UC = new User(); $result = $UC->setPassword($action);

Returns true. The new password was succesfully saved.

$result = true

Dependencies

PHP
  • count
  • password_hash
  • password_verify
Janitor
  • Model::getPostedEntities
  • Model::getProperty
  • Model::validateList
  • Query::checkDbExistence
  • Query::result
  • Session::value
  • User::hasPassword