Commit 498836f3 authored by Zohten's avatar Zohten

added checks

parent 3b680c7c
......@@ -104,6 +104,30 @@ class UserController extends Controller
*/
protected function addUser($array)
{
// Check if mendatory fields are filed
if (!isset($array['login']) || !isset($array['pwd']) || !isset($array['mail'])) {
$message = json_encode(["message" => 'login, pwd and mail fields are mandatory']);
return new Response(422, $message);
}
// Check if mail is valid
if (!filter_var($array['mail'], FILTER_VALIDATE_EMAIL)) {
$message = json_encode(["message" => 'Email is not valid']);
return new Response(422, $message);
}
// Fill facultative field
if (!isset($array['avatar'])){
$array['avatar'] = 'default.png';
}
if (!isset($array['lastname'])){
$array['lastname'] = '';
}
if (!isset($array['firstname'])){
$array['firstname'] = '';
}
// Create row
User::addRow($array);
$message = json_encode(["message" => 'User succesfully added!']);
$response = Response::createdResponse($message);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment