58 lines
1.3 KiB
PHP
Executable File
58 lines
1.3 KiB
PHP
Executable File
<?php
|
|
|
|
namespace app\models;
|
|
use app\core\Model;
|
|
|
|
class LoginModel extends Model{
|
|
public string $email = '';
|
|
public string $password = '';
|
|
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'email' => [self::RULE_REQUIRED, self::RULE_EMAIL],
|
|
'password' => [self::RULE_REQUIRED]
|
|
];
|
|
}
|
|
|
|
public function labels():array
|
|
{
|
|
return [
|
|
'email' => 'Email',
|
|
'password' => 'Password'
|
|
];
|
|
}
|
|
|
|
|
|
public function createBody(): array
|
|
{
|
|
$body = array();
|
|
$body["values"] = [
|
|
"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"] = "login";
|
|
|
|
return $this->formatHeaderArray($headers);
|
|
}
|
|
|
|
protected function formatHeaderArray(array $headers): array{
|
|
$array = array();
|
|
|
|
foreach ($headers as $key => $value){
|
|
$array[] = $key . ": " . $value;
|
|
}
|
|
|
|
return $array;
|
|
}
|
|
} |