Files
FACULTATE-KNOW_YOUR_FOOD/knowyourfood/models/RegisterModel.php
T

59 lines
1.5 KiB
PHP

<?php
namespace app\models;
use app\core\Model;
class RegisterModel extends Model{
public string $username = '';
public string $email = '';
public string $password = '';
public function rules(): array{
return [
'username' => [self::RULE_REQUIRED],
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL],
'password' => [self::RULE_REQUIRED]
];
}
public function labels():array {
return [
'username' => 'Username',
'email' => 'Email',
'password' => 'Password',
];
}
public function createBody(): array
{
$body = array();
$body["values"] = [
"username" => $this->username,
"email" => $this->email,
"password" => $this->password
];
return $body;
}
public function createHeaders(string $body): array
{
$headers = array();
$headers["Content-type"] = "application/json";
$headers["Content-Length"] = strlen($body);
$headers["Authorization"] = hash('md5', 'api.knowyourfood');
$headers["Auth-Request"] = "register";
return $this->formatHeaderArray($headers);
}
protected function formatHeaderArray(array $headers): array{
$array = array();
foreach ($headers as $key => $value){
$array[] = $key . ": " . $value;
}
return $array;
}
}