where("name", $name)->find(); if ($user->loaded) { throw new Exception("@todo USER_ALREADY_EXISTS $name"); } $user->name = $name; $user->full_name = $full_name; $user->password = $password; // Required groups $user->add(group::everybody()); $user->add(group::registered_users()); $user->save(); return $user; } /** * Hash the password to the internal value * @param string $password the user password * @param string The hashed equivalent */ static function hash_password($password) { require_once(MODPATH . "user/lib/PasswordHash.php"); $hashGenerator = new PasswordHash(10, true); return $hashGenerator->HashPassword($password); } /** * Look up a user by id. * @param integer $id the user id * @return User_Definition the user object, or null if the id was invalid. */ static function lookup($id) { return self::lookup_by_field("id", $id); } /** * Look up a user by name. * @param integer $name the user name * @return User_Definition the user object, or null if the name was invalid. */ static function lookup_by_name($name) { return self::lookup_by_field("name", $name); } static function lookup_by_field($field_name, $value) { try { $user = model_cache::get("user", $value, $field_name); if ($user->loaded) { return $user; } } catch (Exception $e) { if (strpos($e->getMessage(), "MISSING_MODEL") === false) { throw $e; } } return null; } }