сlass User
The class is used to identify the current system User.
Add and edit User profiles using ORM.
Use the User model to get information on Users:
class User { /** * Instantiate a User * @return User */ static public function getInstance() /** * Force User ID setup (leads to object data dump) * @param integer $id * @return void */ public function setId($id) /** * Set up User data * @param array $data */ public function setInfo(array $data) /** * Get User data * @return array */ public function getInfo() /** * The object has a getter defined, which can be invoked by a key. * example: $user->name or $user->email * @throws Exception * @return mixed */ public function __get($val) /** * Check once more if the user is authorized * at first launch (while running the script); * the model verifies whether the authorization data has been transferred by Post method * and if yes, it attempts to authorize the User; for more details, learn the * Model_User::checkLogin method * @return mixed - user_id or false */ public function isAuthorized() /** * Check if the User has administrative access to the system * @return boolean */ public function isAdmin() /** * Force current User authorization * @param boolean $admin - optional * @return void */ public function setAuthorised($admin = false) /** * Remove User authorization data (the session remains active, while the User is logged out) */ public function logout() /** * Authorizing the user: successful authorization returns the link to the object, while failure to authorize returns false * @param string $user * @param string $password * @return User|boolean */ static public function login($user , $password) /* == ADMIN SECTION == */ /** * Get modules available for the current user * @return array */ public function getAvailableModules() /** * Check if user can view module data * @param string $module * @return boolean */ public function canView($module) /** * Check if user can edit module data * @param string $module * @return boolean */ public function canEdit($module) /** * Check if user can delete module data * @param string $module * @return boolean */ public function canDelete($module) /** * Check if user can publish module data * @param string $module * @return boolean */ public function canPublish($module)
Example:
$user = new Db_Object('user');
$date = date('Y-m-d H:i:s');
$user->setValues(
array(
'name' =>'User Name',
'email' => 'user@gmail.com',
'login' => 'userlogin',
'pass' => Utils::hash('userpassword'),
'enabled' => true,
'admin' => false,
'registration_date' => $date ,
'confirmation_code' => $date ,
'group_id' => 0,
'confirmed' => true,
'avatar' => '',
'registration_ip' => $_SERVER['REMOTE_ADDR'],
'last_ip' => $_SERVER['REMOTE_ADDR'],
'confirmation_date' =>$date
)
);
$userId = $user->save();
comments powered by Disqus