original_string: public function handleRegister(array $request = [])
      {
          $validator = new \Valitron\Validator($request);
          $validator->rule('required', ['username', 'password', 'confirm_password']);
          $validator->rule(function ($field, $value, array $params, array $fields) {
              return is_string($value);
          }, ['username', 'password', 'confirm_password'])->message("{field} must be a string");
          $validator->rule('equals', 'confirm_password', 'password');
          $validator->rule('lengthBetween', 'username', 6, 200);
          $validator->rule('lengthBetween', 'password', 8, 80);
          if ($validator->validate() === false) {
              if (headers_sent() === false) {
                  header('X-PHP-Response-Code: 422', true, 422);
              }
              return $this->templates->render("Auth::Register", [
                  "messages" => [
                      'error' => $validator->errors(),
                      'info' => '',
                      'success' => '',
                      'warning' => ''
                  ],
                  "username" => $request['username']
              ]);
          }
  
          $response = $this->core->api('User/', 'POST')->run($request);
          if (headers_sent() === false) {
              foreach ($response["headers"] as $header) {
                  header($header[0], $header[1], $header[2]);
              }
          }
          if ($response["headers"][0][2] === 422) {
              return $this->templates->render("Auth::Register", [
                  "messages" => [
                      'error' => $response['response'],
                      'info' => '',
                      'success' => '',
                      'warning' => ''
                  ],
                  "username" => $request['username']
              ]);
          } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
              if (isset($_GET['template']) === false) {
                  return redirect($this->router->generate('login-page') . "?m=1");
              } else {
                  return 'Redirect: ' . $this->router->generate('login-page') . "?m=1";
              }
          } else {
              return $this->templates->render("500", [
                  "error" => $response['response'],
                  "result" => ''
              ]);
          }
      }
code: public function handleRegister(array $request = [])
      {
          $validator = new \Valitron\Validator($request);
          $validator->rule('required', ['username', 'password', 'confirm_password']);
          $validator->rule(function ($field, $value, array $params, array $fields) {
              return is_string($value);
          }, ['username', 'password', 'confirm_password'])->message("{field} must be a string");
          $validator->rule('equals', 'confirm_password', 'password');
          $validator->rule('lengthBetween', 'username', 6, 200);
          $validator->rule('lengthBetween', 'password', 8, 80);
          if ($validator->validate() === false) {
              if (headers_sent() === false) {
                  header('X-PHP-Response-Code: 422', true, 422);
              }
              return $this->templates->render("Auth::Register", [
                  "messages" => [
                      'error' => $validator->errors(),
                      'info' => '',
                      'success' => '',
                      'warning' => ''
                  ],
                  "username" => $request['username']
              ]);
          }
  
          $response = $this->core->api('User/', 'POST')->run($request);
          if (headers_sent() === false) {
              foreach ($response["headers"] as $header) {
                  header($header[0], $header[1], $header[2]);
              }
          }
          if ($response["headers"][0][2] === 422) {
              return $this->templates->render("Auth::Register", [
                  "messages" => [
                      'error' => $response['response'],
                      'info' => '',
                      'success' => '',
                      'warning' => ''
                  ],
                  "username" => $request['username']
              ]);
          } elseif (($response["headers"][0][2] - 200) * ($response["headers"][0][2] - 299) <= 0) {
              if (isset($_GET['template']) === false) {
                  return redirect($this->router->generate('login-page') . "?m=1");
              } else {
                  return 'Redirect: ' . $this->router->generate('login-page') . "?m=1";
              }
          } else {
              return $this->templates->render("500", [
                  "error" => $response['response'],
                  "result" => ''
              ]);
          }
      }
code_tokens: public function handleRegister ( array $ request = [ ] ) { $ validator = new \ Valitron \ Validator ( $ request ) ; $ validator -> rule ( 'required' , [ 'username' , 'password' , 'confirm_password' ] ) ; $ validator -> rule ( function ( $ field , $ value , array $ params , array $ fields ) { return is_string ( $ value ) ; } , [ 'username' , 'password' , 'confirm_password' ] ) -> message ( "{field} must be a string" ) ; $ validator -> rule ( 'equals' , 'confirm_password' , 'password' ) ; $ validator -> rule ( 'lengthBetween' , 'username' , 6 , 200 ) ; $ validator -> rule ( 'lengthBetween' , 'password' , 8 , 80 ) ; if ( $ validator -> validate ( ) === false ) { if ( headers_sent ( ) === false ) { header ( 'X-PHP-Response-Code: 422' , true , 422 ) ; } return $ this -> templates -> render ( "Auth::Register" , [ "messages" => [ 'error' => $ validator -> errors ( ) , 'info' => '' , 'success' => '' , 'warning' => '' ] , "username" => $ request [ 'username' ] ] ) ; } $ response = $ this -> core -> api ( 'User/' , 'POST' ) -> run ( $ request ) ; if ( headers_sent ( ) === false ) { foreach ( $ response [ "headers" ] as $ header ) { header ( $ header [ 0 ] , $ header [ 1 ] , $ header [ 2 ] ) ; } } if ( $ response [ "headers" ] [ 0 ] [ 2 ] === 422 ) { return $ this -> templates -> render ( "Auth::Register" , [ "messages" => [ 'error' => $ response [ 'response' ] , 'info' => '' , 'success' => '' , 'warning' => '' ] , "username" => $ request [ 'username' ] ] ) ; } elseif ( ( $ response [ "headers" ] [ 0 ] [ 2 ] - 200 ) * ( $ response [ "headers" ] [ 0 ] [ 2 ] - 299 ) <= 0 ) { if ( isset ( $ _GET [ 'template' ] ) === false ) { return redirect ( $ this -> router -> generate ( 'login-page' ) . "?m=1" ) ; } else { return 'Redirect: ' . $ this -> router -> generate ( 'login-page' ) . "?m=1" ; } } else { return $ this -> templates -> render ( "500" , [ "error" => $ response [ 'response' ] , "result" => '' ] ) ; } }
docstring: Handle the registration page submission
docstring_tokens: Handle the registration page submission