Пример #1
0
 /**
  * @param Slim $app
  * @return $response
  */
 public static function register(Slim $app)
 {
     $status = [];
     $response = $app->response();
     $response->headers->set('Content-Type', 'application/json');
     $username = $app->request->params('username');
     $password = password_hash($app->request->params('password'), PASSWORD_BCRYPT);
     $data = json_decode(self::validate($app, $username, $password));
     foreach ($data as $key => $value) {
         array_push($status, $value);
     }
     if ($status[0] == 200) {
         $username = $status[1];
         $password = $status[2];
     }
     try {
         $user = new User();
         $user->username = $username;
         $user->password = $password;
         $user->save();
         $response->body(json_encode(['status' => 200, 'message' => 'Way to go ' . $username . '!']));
         return $response;
     } catch (QueryException $e) {
         $app->halt(403, json_encode(['status' => 403, 'message' => 'User exists already!']));
     }
 }