array( ValidationRules::REQUIRED => 'email-required', ValidationRules::EMAIL => 'email-invalid', ValidationRules::UNIQUE => 'email-unique', ), 'password' => array( ValidationRules::REQUIRED => 'password-required', ValidationRules::CONFIRMED => 'password-confirmed', ValidationRules::MIN => 'password-min', ), 'code' => array( ValidationRules::REQUIRED => 'token-empty', ValidationRules::STRING => 'token-validation', ValidationRules::DIGITS => 'token-validation' ), 'totp_secret' => array( ValidationRules::REQUIRED => 'totp-secret-empty', ValidationRules::TOTP_SECRET => 'totp-secret-validation' ) ); /** * * @param Storage $storage * @param API_Wrapper $api_wrapper * @param Flash $flash */ public function __construct( Storage $storage, API_Wrapper $api_wrapper, Flash $flash ) { $this->storage = $storage; $this->api_wrapper = $api_wrapper; $this->flash = $flash; } /** * @param string $page * @param string $action * * @return Redirection_Response */ protected function redirect( $page, $action = '' ) { return new Redirection_Response( $page, $action ); } /** * @param string $template * @param array $data * * @return View_Response */ protected function render( $template, array $data = array() ) { return new View_Response( $template, $data ); } /** * @param array $body * @param int $status_code * * @return JSON_Response */ protected function json( array $body, $status_code = 200 ) { return new JSON_Response( $body, $status_code ); } /** * @param string $error * * @return View_Response */ protected function error( $error ) { return $this->render( Views::ERROR, array( 'description' => $error, ) ); } /** * @param ValidationExceptionInterface $exception * * @return string */ protected function get_validation_error( ValidationExceptionInterface $exception ) { foreach ( $exception->getErrors() as $key => $errors ) { if ( array_key_exists( $key, $this->validation_rules ) ) { return $this->validation_rules[ $key ][ $errors[0] ]; } } return 'default'; } }