Commit 5c14292c authored by Zohten's avatar Zohten

verif pseudo backend

parent a8aa0e71
......@@ -116,6 +116,12 @@ class UserController extends Controller
return new Response(422, $message);
}
// Check if login/pseudo is already used
if (User::checkLogin($array['login'])) {
$message = json_encode(["message" => 'This pseudo is already used']);
return new Response(422, $message);
}
// Fill facultative field
if (!isset($array['avatar'])){
$array['avatar'] = '';
......
......@@ -35,6 +35,12 @@ class User extends Model
$stm = parent::exec('USER_UPDATE', $array);
}
public static function checkLogin($login)
{
$stm = parent::exec('USER_CHECK_LOGIN', ['login' => $login]);
return $stm->fetch();
}
public static function tryLogin($login)
{
$stm = parent::exec('USER_GET_WITH_LOGIN', ['login' => $login]);
......
......@@ -5,6 +5,11 @@ User::addSqlQuery(
'SELECT * FROM MJ_USER ORDER BY LOGIN'
);
User::addSqlQuery(
'USER_CHECK_LOGIN',
'SELECT LOGIN FROM MJ_USER WHERE LOGIN=:login'
);
User::addSqlQuery(
'USER_GET_WITH_LOGIN',
'SELECT * FROM MJ_USER WHERE LOGIN=:login'
......
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