Repository navigation
Internals Admin Model AdminModel
Framework Internals · Subsystem overview · Developer guide
Source: awt_src/classes/admin/model/AdminModel.php · Snapshot 8411f4287706.
Admin models and authentication manage the framework administrator record and PHP session. Permission levels are compared numerically with lower values granting broader access. Passwords currently use SHA-512.
use /**
* The Model class typically serves as the base class for all data-driven models
* in the application, providing core functionalities for data manipulation,
* validation, and interaction with data storage mechanisms such as databases.
*
* Responsibilities of this class may include:
* - Defining and managing properties that represent data fields.
* - Handling data retrieval and storage via external sources such as databases.
* - Providing methods for data validation and transformation within the model.
* - Acting as a common interface for various entity-specific models in the system.
*
* This class is expected to be extended by specific implementations tailored to
* the application's needs and should follow common design patterns for managing
* and structuring data logic.
*/
model\Model;
use /**
* The SessionHandler class provides a way to manage session operations in a standardized manner.
* It implements custom session storage handlers for reading, writing, updating, and deleting session data.
*
* This class works as an interface between PHP's session management system and any custom session storage implementation.
*/
session\SessionHandler;class AdminModel extends ModelSource description (behavioral corrections are recorded in Known discrepancies):
Class AdminModel
Represents an administrative user with various properties and methods for managing user data, including authentication, session handling, and role-based permissions.
Declarations below preserve visibility, type, default and modifiers exactly. A typed property without an initializer remains uninitialized until its constructor or another method assigns it. Mutable fields belong to this instance unless marked static; readonly fields can be initialized once. Constructor-promoted properties are also listed below.
| Member | Declaration | Purpose or source contract |
|---|---|---|
| $id | public ?int $id = null; |
Used by setID(). |
| $username | public ?string $username; |
Used by __construct(), setUsername(). |
| $profile_picture | public ?string $profile_picture; |
Used by __construct(), setProfilePicture(). |
| $permission_level | public ?int $permission_level; |
Used by __construct(), setPermLevel(), setRole(). |
| $token | public ?string $token = null; |
Used by setToken(), createToken(). |
| $firstname | public ?string $firstname; |
Used by setFirstname(). |
| $lastname | public ?string $lastname; |
Used by setLastname(). |
public ?string $email; |
Used by setEmail(). |
|
| $session | private SessionHandler $session; |
Used by __construct(). |
| $role | public ?string $role; |
Used by __construct(), setRole(). |
| $password | public ?string $password; |
Used by __construct(), setPassword(), createToken(), changePassword(). |
| $roles | private array $roles = [ "Admin", "Moderator", "Author", ]; |
Used by __construct(), setRole(). |
| Constructor-promoted | public function __construct(?int $id = null |
Initialized from the constructor argument; default expression is evaluated when the argument is omitted. |
| Method | Signature |
|---|---|
| __construct | public function __construct(?int $id = null, bool $manual = false) |
| hiddenAttributes | protected function hiddenAttributes(): array |
| setID | public function setID(int $id) |
| setUsername | public function setUsername(string $username): self |
| setProfilePicture | public function setProfilePicture(?string $profile_picture): self |
| setPermLevel | public function setPermLevel(int $permission_level): self |
| setPassword | public function setPassword(string $password): self |
| setEmail | public function setEmail(string $email): self |
| setRole | public function setRole(): self |
| setToken | public function setToken(string $token): self |
| setFirstname | public function setFirstname(string $firstname): self |
| setLastname | public function setLastname(string $lastname): self |
| createToken | public function createToken(): self |
| changePassword | public function changePassword(string $oldPassword, string $newPassword): bool |
| register | public function register(): int|bool |
public function __construct(?int $id = null, bool $manual = false)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
?int $id = null |
Record or runtime identifier selected by this operation. |
$manual |
bool $manual = false |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->session, $this->username, $this->profile_picture, $this->permission_level, $this->role, $this->password.
Implementation, validation guards and interaction order
public function __construct(?int $id = null, bool $manual = false)
{
parent::__construct();
if (is_null($id) && !$manual) {
$this->session = new SessionHandler();
$this->session->SessionHandler();
$id = (int)$_SESSION['admin']['id'];
}
if (!$manual) {
$this->selectByID($id, "awt_admin");
$this->username = $this->getParam("username");
$this->profile_picture = $this->getParam("profile_picture");
$this->permission_level = $this->getParam("permission_level");
$this->role = $this->roles[$this->permission_level];
$this->password = $this->getParam("password");
}
$this->paramBlackList("role");
}protected function hiddenAttributes(): arrayReturn expressions (including local callbacks): ['password', 'token'].
Implementation, validation guards and interaction order
protected function hiddenAttributes(): array { return ['password', 'token']; }public function setID(int $id)| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$id |
int $id |
Record or runtime identifier selected by this operation. |
State writes: $this->id, $this->model_id.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setID(int $id)
{
$this->id = $id;
$this->model_id = $id;
return $this;
}public function setUsername(string $username): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$username |
string $username |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->username.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setUsername(string $username): self
{
$this->username = $username;
return $this;
}public function setProfilePicture(?string $profile_picture): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$profile_picture |
?string $profile_picture |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->profile_picture.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setProfilePicture(?string $profile_picture): self
{
$this->profile_picture = $profile_picture;
return $this;
}public function setPermLevel(int $permission_level): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$permission_level |
int $permission_level |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->permission_level.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setPermLevel(int $permission_level): self
{
$this->permission_level = $permission_level;
$this->setRole();
return $this;
}public function setPassword(string $password): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$password |
string $password |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->password.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setPassword(string $password): self
{
$password = hash("SHA512", $password);
$this->password = $password;
return $this;
}public function setEmail(string $email): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$email |
string $email |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->email.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}public function setRole(): selfState writes: $this->role.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setRole(): self
{
$this->role = $this->roles[$this->permission_level];
return $this;
}public function setToken(string $token): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$token |
string $token |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->token.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setToken(string $token): self
{
$this->token = $token;
return $this;
}public function setFirstname(string $firstname): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$firstname |
string $firstname |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->firstname.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}public function setLastname(string $lastname): self| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$lastname |
string $lastname |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
State writes: $this->lastname.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function setLastname(string $lastname): self
{
$this->lastname = $lastname;
return $this;
}public function createToken(): selfState writes: $this->token.
Return expressions (including local callbacks): $this.
Implementation, validation guards and interaction order
public function createToken(): self
{
$this->token = hash("SHA512", time() . $this->password);
return $this;
}public function changePassword(string $oldPassword, string $newPassword): bool| Parameter | Type, modifiers and default | Purpose |
|---|---|---|
$oldPassword |
string $oldPassword |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
$newPassword |
string $newPassword |
Operation input; the exact use, validation and propagation are shown in the implementation trace. |
Return expressions (including local callbacks): $this->setPassword($newPassword)->save(); false.
Implementation, validation guards and interaction order
public function changePassword(string $oldPassword, string $newPassword): bool
{
if ($this->password === hash("SHA512", $oldPassword)) {
return $this->setPassword($newPassword)->save();
}
return false;
}public function register(): int|boolState writes: $this->model_source.
Return expressions (including local callbacks): $this->saveModel(); false.
Failure handling catches \PDOException.
Implementation, validation guards and interaction order
public function register(): int|bool
{
try {
$this->model_source = "awt_admin";
return $this->saveModel();
} catch (\PDOException $e) {
return false;
}
}AWT Framework Wiki · Home · Installation Guide · Developer Guide · Framework Internals
Philosophy · Architecture · Known discrepancies · Verification
Installation Guide
Developer Guide
- Learning sequence
- First package
- Package structure
- Lifecycle
- Runtimes
- Events and objects
- Routing and controllers
- Views and resources
- Database and models
- Storage and caching
- Configuration and CLI
- Responses and errors
- Extension points
Framework Internals
- Architecture
- Bootstrap
- Packages
- Runtime
- Events and context
- Objects
- HTTP routing and controllers
- Rendering
- Blade integration
- Database
- Models
- Storage and caching
- Settings
- CLI
- Identity and sessions
- Responses
- Errors
- Complete source inventory
Documentation notes