test-php-rest-api-user/engine/core/api/v1/createUser.php

40 lines
939 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
if(!isset($_REQUEST['login'])) {
$data = [
'error' => true,
'message' => 'Не передано поле login',
];
}
elseif(!isset($_REQUEST['password'])) {
$data = [
'error' => true,
'message' => 'Не передано поле password',
];
}
elseif(strlen($_REQUEST['password']) < 8) {
$data = [
'error' => true,
'message' => 'Пароль должен иметь 8 символов минимум',
];
}
elseif(!User::create($_REQUEST['login'], $_REQUEST['password'])) {
$data = [
'error' => true,
'message' => 'Пользователь с таким логином уже сужествует',
];
}
else {
$data = [
'error' => false,
'message' => 'Пользователь создан',
];
}
}
else {
$data = [
'error' => true,
'message' => 'Только POST метод',
];
}