= ( 'login' === $kind ? 10 : 5 ); } /** * Handle POSTs. */ public static function handle() { if ( empty( $_POST['fillnova_auth'] ) ) { return; } $kind = sanitize_key( wp_unslash( $_POST['fillnova_auth'] ) ); if ( ! in_array( $kind, array( 'login', 'register' ), true ) ) { return; } if ( ! isset( $_POST['_fnauth'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_fnauth'] ) ), 'fillnova_' . $kind ) ) { self::$errors[ $kind ] = __( 'Your session expired. Please try again.', 'fillnova' ); return; } if ( ! empty( $_POST['fillnova_hp'] ) ) { return; // Bot. } if ( self::throttled( $kind ) ) { self::$errors[ $kind ] = __( 'Too many attempts. Please wait 15 minutes and try again.', 'fillnova' ); return; } if ( 'login' === $kind ) { $user = wp_signon( array( 'user_login' => isset( $_POST['log'] ) ? sanitize_user( wp_unslash( $_POST['log'] ) ) : '', 'user_password' => isset( $_POST['pwd'] ) ? (string) wp_unslash( $_POST['pwd'] ) : '', // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Passwords must not be altered. 'remember' => ! empty( $_POST['rememberme'] ), ), is_ssl() ); if ( is_wp_error( $user ) ) { self::$errors['login'] = __( 'Wrong username/email or password.', 'fillnova' ); return; } wp_safe_redirect( self::target( 'login_redirect' ) ); exit; } if ( ! get_option( 'users_can_register' ) ) { self::$errors['register'] = __( 'Registration is closed on this site.', 'fillnova' ); return; } $login = isset( $_POST['user_login'] ) ? sanitize_user( wp_unslash( $_POST['user_login'] ), true ) : ''; $email = isset( $_POST['user_email'] ) ? sanitize_email( wp_unslash( $_POST['user_email'] ) ) : ''; $pass = isset( $_POST['user_pass'] ) ? (string) wp_unslash( $_POST['user_pass'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Passwords must not be altered. $name = isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : ''; if ( '' === $login || ! validate_username( $login ) ) { self::$errors['register'] = __( 'Please choose a valid username (letters, numbers, - and _).', 'fillnova' ); } elseif ( username_exists( $login ) ) { self::$errors['register'] = __( 'This username is taken. Please choose another one.', 'fillnova' ); } elseif ( ! is_email( $email ) ) { self::$errors['register'] = fillnova_message( 'email' ); } elseif ( email_exists( $email ) ) { self::$errors['register'] = __( 'An account with this email already exists. Try logging in.', 'fillnova' ); } elseif ( strlen( $pass ) < 8 ) { self::$errors['register'] = __( 'Please use a password with at least 8 characters.', 'fillnova' ); } if ( ! empty( self::$errors['register'] ) ) { return; } $id = wp_insert_user( array( 'user_login' => $login, 'user_email' => $email, 'user_pass' => $pass, 'first_name' => $name, 'role' => get_option( 'default_role', 'subscriber' ), ) ); if ( is_wp_error( $id ) ) { self::$errors['register'] = $id->get_error_message(); return; } wp_new_user_notification( $id, null, 'admin' ); wp_set_current_user( $id ); wp_set_auth_cookie( $id, false, is_ssl() ); wp_safe_redirect( self::target( 'register_redirect' ) ); exit; } /** * Shared wrapper. * * @param string $inner Inner HTML. * @param string $kind Kind. * @return string */ protected static function wrap( $inner, $kind ) { if ( 'no' !== fillnova_get_setting( 'load_css', 'yes' ) ) { wp_enqueue_style( 'fillnova', FILLNOVA_URL . 'assets/css/fillnova.css', array(), fillnova_asset_ver( 'assets/css/fillnova.css' ) ); } $err = isset( self::$errors[ $kind ] ) ? '
' . esc_html( sprintf( __( 'You are logged in as %s.', 'fillnova' ), $u->display_name ) ) . ' ' . esc_html__( 'Log out', 'fillnova' ) . '
', 'login' ); } // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Refill after a failed attempt. $log = isset( $_POST['log'] ) ? sanitize_user( wp_unslash( $_POST['log'] ) ) : ''; $html = '' . esc_html( $msg ) . '
', 'register' ); } // phpcs:disable WordPress.Security.NonceVerification.Missing -- Refill after a failed attempt. $login = isset( $_POST['user_login'] ) ? sanitize_user( wp_unslash( $_POST['user_login'] ) ) : ''; $email = isset( $_POST['user_email'] ) ? sanitize_email( wp_unslash( $_POST['user_email'] ) ) : ''; $name = isset( $_POST['first_name'] ) ? sanitize_text_field( wp_unslash( $_POST['first_name'] ) ) : ''; // phpcs:enable $html = '