user_login, get_userdata( $result ) ); wp_safe_redirect( apply_filters( 'sirius_press_after_register_redirect', admin_url(), $result ) ); exit; } } self::render( $errors ); exit; } /** * @return int|WP_Error User ID. */ private static function process() { if ( ! SP_Settings::open_registration() ) { return new WP_Error( 'sirius_closed', __( 'This site is not accepting new accounts.', 'sirius-press' ) ); } $limited = SPA_Challenge::check_rate_limit( 'register', 10, 900 ); if ( is_wp_error( $limited ) ) { return $limited; } // phpcs:disable WordPress.Security.NonceVerification.Missing -- the signed challenge is the anti-forgery proof. $nonce = isset( $_POST['sirius_nonce'] ) ? sanitize_text_field( wp_unslash( $_POST['sirius_nonce'] ) ) : ''; $signature = isset( $_POST['sirius_signature'] ) ? sanitize_text_field( wp_unslash( $_POST['sirius_signature'] ) ) : ''; $login = isset( $_POST['user_login'] ) ? sanitize_user( wp_unslash( $_POST['user_login'] ), true ) : ''; $claimed = isset( $_POST['sirius_address'] ) ? sanitize_text_field( wp_unslash( $_POST['sirius_address'] ) ) : ''; // phpcs:enable WordPress.Security.NonceVerification.Missing if ( '' === $signature || '' === $nonce ) { return new WP_Error( 'sirius_missing', __( 'Sign the text above before submitting.', 'sirius-press' ) ); } /* * The claimed address is required here, unlike at sign-in. Recovering * a key from a signature always succeeds, so without something to * compare against, a signature over the wrong text would create an * account bound to an address the registrant cannot sign for — and * they would only find out the next time they tried to get in. */ if ( '' === $claimed ) { return new WP_Error( 'sirius_missing_address', __( 'Tell us which address you signed with, so the signature can be checked against it.', 'sirius-press' ) ); } $address = SPA_Challenge::verify( $nonce, $signature, SPA_Challenge::PURPOSE_REGISTER, $claimed ); if ( is_wp_error( $address ) ) { return $address; } $existing = SP_Identity::user_by_address( $address ); if ( $existing ) { return new WP_Error( 'sirius_exists', sprintf( /* translators: %s: login URL. */ __( 'That wallet already has an account here. Sign in instead.', 'sirius-press' ), esc_url( wp_login_url() ) ) ); } if ( '' !== $login && username_exists( $login ) ) { return new WP_Error( 'sirius_username_taken', __( 'That username is taken. Pick another.', 'sirius-press' ) ); } return SP_Identity::create_user( $address, $login ); } private static function render( WP_Error $errors ) { $nonce = SPA_Challenge::issue(); $message = SPA_Challenge::message( $nonce, SPA_Challenge::PURPOSE_REGISTER ); $open = SP_Settings::open_registration(); login_header( __( 'Create an account', 'sirius-press' ), '', $errors ); SPA_Login::print_config(); ?>