error */ if( !is_array($fetched_admin) || !isset($fetched_admin['id_admin']) || !is_numeric($fetched_admin['id_admin']) ) return ['connected' => false]; /* (3) Extract @id_admin */ $id_admin = intval( $fetched_admin['id_admin'] ); /* (3) Check password for admin ---------------------------------------------------------*/ /* (1) Check password */ $valid_pass = Repo::request('admin', 'checkPassword', $id_admin, $password); /* (2) If wrong password -> error */ if( !$valid_pass ) return ['connected' => false]; /* (4) Update session to be connected ---------------------------------------------------------*/ /* (1) Update session */ $_SESSION['TOKEN'] = 'a'.$fetched_admin['token']; new AuthSystemDefault; /* (2) Return status */ return ['connected' => true]; } public function POST_signup($argv){ extract($argv); /* (1) Logout by default ---------------------------------------------------------*/ $_SESSION['TOKEN'] = []; /* (2) Check if @username is unique ---------------------------------------------------------*/ /* (1) Fetch by username */ $fetched_admin = Repo::request('admin', 'getByUsername', $username); /* (2) If found -> error */ if( $fetched_admin !== false ) return ['error' => new Error(Err::AlreadyExists)]; /* (3) Check if @mail is unique ---------------------------------------------------------*/ /* (1) Fetch by mail */ $fetched_admin = Repo::request('admin', 'getByMail', $mail); /* (2) If found -> error */ if( $fetched_admin !== false ) return ['error' => new Error(Err::AlreadyExists)]; /* (4) Create user ---------------------------------------------------------*/ /* (1) Create repo request */ $id_created = Repo::request('admin', 'create', $username, $mail, $password); /* (2) If error -> dispatch */ if( $id_created === false ) return [ 'error' => new Error(Err::RepoError) ]; /* (3) Return status */ return [ 'registered' => $id_created ]; } }