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

28 lines
617 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(strlen($password) < 8) {
$data = [
'error' => true,
'message' => 'Пароль должен иметь 8 символов минимум',
];
}
elseif(!User::create($login, $password)) {
$data = [
'error' => true,
'message' => 'Пользователь с таким логином уже сужествует',
];
}
else {
$data = [
'error' => false,
'message' => 'Пользователь создан',
];
}
}
else {
$data = [
'error' => true,
'message' => 'Только POST метод',
];
}