/**
  *  This function creates a new instance of a user
  * @param  Slim   $app
  */
 public static function register(Slim $app)
 {
     $app->response->headers->set('Content-Type', 'application/json');
     $user = new User();
     $user->username = Authenticator::checkParamValue($app, "username", $app->request->params('username'));
     $user->password = Authenticator::checkParamValue($app, "password", $app->request->params('password'));
     $user->name = Authenticator::checkParamValue($app, "name", $app->request->params('name'));
     $user->password = password_hash($user->password, PASSWORD_DEFAULT);
     $conn = User::getConnection();
     $stmt = $conn->query("SELECT * FROM users WHERE username='******'");
     $result = $stmt->fetch(PDO::FETCH_ASSOC);
     if ($result) {
         OutputFormatter::formatOutput($app, 200, "The user '{$user->username}' already exists.");
     }
     $rows = $user->save();
     if ($rows > 0) {
         OutputFormatter::formatOutput($app, 201, 'User registration successful.');
     } else {
         OutputFormatter::formatOutput($app, 400, 'User registration failed!');
     }
 }
 /**
  * This function updates some fields of an empji record in the database
  * @param  Slim   $app      [Slim instance]
  * @param  $id              [the id of the emoji in the emojis table]
  */
 public static function patchEmoji(Slim $app, $id)
 {
     $app->response->headers->set('Content-Type', 'application/json');
     Authenticator::authenticate($app);
     $emoji = Emoji::findById($id);
     if (is_string($emoji)) {
         OutputFormatter::formatOutput($app, 404, $emoji);
     }
     $params = $app->request->patch();
     if (count($params) == 0) {
         OutputFormatter::formatOutput($app, 406, "The field to update was not specified.");
     }
     foreach ($params as $key => $value) {
         Authenticator::checkParamValue($app, $key, $value);
         $emoji->{$key} = $value;
     }
     $rows = $emoji->save();
     if ($rows > 0) {
         OutputFormatter::formatOutput($app, 200, 'Emoji successfully updated.');
     } else {
         OutputFormatter::formatOutput($app, 400, 'Emoji partial update failed!');
     }
 }