[WordPress] 外掛分享: Password Reset with Code for WordPress REST API

WordPress 外掛 Password Reset with Code for WordPress REST API 的封面圖片。

前言介紹

  • 這款 WordPress 外掛「Password Reset with Code for WordPress REST API」是 2020-05-08 上架。
  • 目前有 1000 個安裝啟用數。
  • 上一次更新是 2023-08-22,距離現在已有 619 天。超過一年沒更新,安裝要確認版本是否可用。以及後續維護問題!
  • 外掛最低要求 WordPress 4.6 以上版本才可以安裝。
  • 外掛要求網站主機運作至少需要 PHP 版本 5.4 以上。
  • 有 10 人給過評分。
  • 還沒有人在論壇上發問,可能目前使用數不多,還沒有什麼大問題。

外掛協作開發者

dominic_ks | wpamitkumar |

外掛標籤

wp-api | password reset |

內容簡介

這是一個簡單的外掛程式,可以在 WordPress REST API 中使用代碼添加重設密碼功能。 此過程是一個兩步驟的流程:

用戶請求重設密碼。一個四位數的代碼將發送到他們註冊的電子郵件地址。
當用戶設置新密碼時,輸入代碼,只有當代碼有效且未過期時才設置新密碼

還可以檢查代碼的有效性,而不必重置密碼,這使設置密碼方式或者檢查代碼並重置密碼(如果需要的話)成為可能。

默認設置為使用四位數字代碼,生存期為15分鐘,之後需要請求一個新的代碼。

端點

外掛程式將兩個新端點添加到REST API中:

端點:/wp-json/bdpwr/v1/reset-password
- HTTP動詞:POST
- 參數(全部必填):
- 電子郵件

端點:/wp-json/bdpwr/v1/set-password
- HTTP動詞:POST
- 參數(全部必填):
- 電子郵件
- 密碼
- 代碼

端點:/wp-json/bdpwr/v1/validate-code
- HTTP動詞:POST
- 參數(全部必填):
- 電子郵件
- 代碼

範例請求(jQuery)
重設密碼
$.ajax({
url: '/wp-json/bdpwr/v1/reset-password',
method: 'POST',
data: {
email: '[email protected]',
},
success: function( response ) {
console.log( response );
},
error: function( response ) {
console.log( response );
},
});

設置新密碼
$.ajax({
url: '/wp-json/bdpwr/v1/set-password',
method: 'POST',
data: {
email: '[email protected]',
code: '1234',
password: 'Pa$$word1',
},
success: function( response ) {
console.log( response );
},
error: function( response ) {
console.log( response );
},
});

驗證代碼
$.ajax({
url: '/wp-json/bdpwr/v1/validate-code',
method: 'POST',
data: {
email: '[email protected]',
code: '1234',
},
success: function( response ) {
console.log( response );
},
error: function( response ) {
console.log( response );
},
});

範例成功回應(JSON)
重設密碼
{
"data": {
"status": 200
},
"message": "A password reset email has been sent to your email address."
}

設置新密碼
{
"data": {
"status": 200
},
"message": "Password reset successfully."
}

驗證代碼
{
"data": {
"status": 200
},
"message": "The code supplied is valid."
}

範例錯誤回應(JSON)
重設密碼
{
"code": "bad_email",
"message": "No user found with this email address.",
"data": {
"status": 500
}
}

設置新密碼
{
"code": "bad_request",
"message": "You must request a password reset code before you try to set a new password.",
"data": {
"status": 500
}
}

原文外掛簡介

A simple plugin that adds a password reset facility to the WordPress REST API using a code. The process is a two step process:

User requests a password reset. A code is emailed to their registered email address
The user enters the code when setting a new password, which is only set if the code is valid and has not expired

It is also possible to check the validity of a code without resetting the password which enables the possibility of setting the password by other means, or having a two stage process for checking the code and resetting the password if desired.
Default settings are to use an 8 digit code consisting of numbers, upper and lower case letters and special characters, which has a life span of 15 minutes, afterwhich a new code would need to be requested. By default a user can attempt to use or validate a code up to 3 times before automatically invalidating it.
Endpoints
The plugin adds two new endpoints to the REST API:

Endpoint: /wp-json/bdpwr/v1/reset-password
— HTTP Verb: POST
— Parameters (all required):
— email

/wp-json/bdpwr/v1/set-password
— HTTP Verb: POST
— Parameters (all required):
— email
— password
— code

/wp-json/bdpwr/v1/validate-code
— HTTP Verb: POST
— Parameters (all required):
— email
— code

Example Requests (jQuery)
Reset Password
$.ajax({
url: '/wp-json/bdpwr/v1/reset-password',
method: 'POST',
data: {
email: '[email protected]',
},
success: function( response ) {
console.log( response );
},
error: function( response ) {
console.log( response );
},
});

Set New Password
$.ajax({
url: '/wp-json/bdpwr/v1/set-password',
method: 'POST',
data: {
email: '[email protected]',
code: '1234',
password: 'Pa$$word1',
},
success: function( response ) {
console.log( response );
},
error: function( response ) {
console.log( response );
},
});

Validate Code
$.ajax({
url: '/wp-json/bdpwr/v1/validate-code',
method: 'POST',
data: {
email: '[email protected]',
code: '1234',
},
success: function( response ) {
console.log( response );
},
error: function( response ) {
console.log( response );
},
});

Example Success Responses (JSON)
Reset Password
{
"data": {
"status": 200
},
"message": "A password reset email has been sent to your email address."
}

Set New Password
{
"data": {
"status": 200
},
"message": "Password reset successfully."
}

Validate Code
{
"data": {
"status": 200
},
"message": "The code supplied is valid."
}

Example Error Responses (JSON)
Reset Password
{
"code": "bad_email",
"message": "No user found with this email address.",
"data": {
"status": 500
}
}

Set New Password
{
"code": "bad_request",
"message": "You must request a password reset code before you try to set a new password.",
"data": {
"status": 500
}
}

Validate Code
{
"code": "bad_request",
"message": "The reset code provided is not valid.",
"data": {
"status": 500
}
}

Filters
A number of WordPress filters have been added to help customise the process, please feel free to request additional filters or submit a pull request with any that you required.
Filter the length of the code
add_filter( 'bdpwr_code_length' , function( $length ) {
return 4;
}, 10 , 1 );

Filter Expiration Time
add_filter( 'bdpwr_code_expiration_seconds' , function( $seconds ) {
return 900;
}, 10 , 1 );

Filter the date format used by the plugin to display expiration times
add_filter( 'bdpwd_date_format' , function( $format ) {
return 'H:i';
}, 10 , 1 );

Filter the reset email subject
add_filter( 'bdpwr_code_email_subject' , function( $subject ) {
return 'Password Reset';
}, 10 , 1 );

Filter the email content
add_filter( 'bdpwr_code_email_text' , function( $text , $email , $code , $expiry ) {
return $text;
}, 10 , 4 );

Filter maximum attempts allowed to use a reset code, default is 3, -1 for unlimmited
add_filter( 'bdpwr_max_attempts' , function( $attempts ) {
return 3;
}, 10 , 4 );

Filter whether to include upper and lowercase letters in the code as well as numbers, default is false
add_filter( 'bdpwr_include_letters' , function( $include ) {
return false;
}, 10 , 4 );

Filter the characters to be used when generating a code, you can use any string you want, default is 0123456789
add_filter( 'bdpwr_selection_string' , function( $string ) {
return '0123456789';
}, 10 , 4 );

Filter the WP roles allowed to reset their password with this plugin, default is any, example below shows removing administrators
add_filter( 'bdpwr_allowed_roles' , function( $roles ) {

$key = array_search( 'administrator' , $roles );

if( $key !== false ) {
unset( $roles[ $key ] );
}

return $roles;

}, 10 , 1 );

Filter to add custom namespace for REST API
add_filter( 'bdpwr_route_namespace' , function( $route_namespace ) {
return 'xyz/v1';
}, 10 , 1 );

Credits

Plugin icon / banner image by Sincerely Media

各版本下載點

  • 方法一:點下方版本號的連結下載 ZIP 檔案後,登入網站後台左側選單「外掛」的「安裝外掛」,然後選擇上方的「上傳外掛」,把下載回去的 ZIP 外掛打包檔案上傳上去安裝與啟用。
  • 方法二:透過「安裝外掛」的畫面右方搜尋功能,搜尋外掛名稱「Password Reset with Code for WordPress REST API」來進行安裝。

(建議使用方法二,確保安裝的版本符合當前運作的 WordPress 環境。


0.0.2 | 0.0.3 | 0.0.4 | 0.0.5 | 0.0.6 | 0.0.7 | 0.0.8 | 0.0.9 | trunk | 0.0.10 | 0.0.11 | 0.0.12 | 0.0.13 | 0.0.14 | 0.0.15 | 0.0.16 |

延伸相關外掛(你可能也想知道)

  • JWT Authentication for WP REST API 》此外掛使用 JSON Web Tokens (JWT) 做為驗證方式,擴充了 WP REST API 。JSON Web Tokens 是一種開放且具有行業標準的方法,用來在兩方之間安全地傳遞聲明。,...。
  • ACF to REST API 》此 WordPress 外掛在WordPress REST API中提供了Advanced Custom Fields的端點, 詳細資訊請參閱GitHub:https://github.com/airesvsg/acf-to-rest-api/。
  • REST API Log 》這是一款針對 WordPress REST API v2 的外掛程式,可記錄 REST API 的請求和回應紀錄。, 功能包括:, , WordPress 管理頁面,用於查看和搜尋日誌條目, API 端...。
  • REST API Meta Support 》此外掛可以自動將 WordPress REST API 的文章(/wp-json/wp/v2/posts)或頁面(/wp-json/wp/v2/pages) POST 中的 meta 欄位所包含的元數據自動存儲於建立的...。
  • WP API Menus 》此外掛擴充了 WordPress JSON REST API,並提供 WordPress 註冊選單的新路徑。, 現在提供的新路徑如下:, , /menus 所有已註冊選單的清單。, /menus/
  • WP REST API – Pure Taxonomies 》現在您不需要額外的請求來獲取分類信息(term_id、name、slug、term_group、term_taxonomy_id、taxonomy、description、parent、count、filter),其ID已經在...。
  • ACF to WP-API 》此外掛能夠將文章、頁面、自定義文章類型、評論、附件和分類法詞彙中的所有 ACF 欄位,整合進 WP-API 輸出中的「acf」鍵下。此外,此外掛亦會新增一個/option...。
  • WP REST API Cache 》啟用 WordPress REST API 快取並提升應用程式的速度。, 詳情請參閱 GitHub:http://github.com/airesvsg/wp-rest-api-cache。
  • WP API Yoast SEO 》在一般的文章或頁面請求中返回 Yoast 文章或頁面的元數據。將元數據儲存在回傳資料的 yoast_meta 欄位中。。
  • SearchWP API 》此外掛可透過 WordPress REST API 和 SearchWP 執行進階搜尋。, 為 WordPress REST API 新增了一個端點,以透過 SearchWP 進行搜尋 - SearchWP 是改善 WordPr...。
  • WP Custom REST API Generator 》WP Custom REST API Generator 外掛提供一個介面在 WordPress 的管理面板中,允許使用者控制所有可用的文章類型的作者資訊、特色圖片、自訂欄位和分類法是否...。
  • REST API Multiple Post Types 》若 WordPress 外掛中的文章類型使用 WordPress REST API(在聲明文章類型時,show_in_rest 必須設為 true),則可以使用 /wp/v2/posts 進行查詢。, 查詢範例,...。
  • User Data Fields For JWT Authentication 》,原文描述並未完成,缺少後續內容。。
  • WP REST API – All Terms 》這個外掛將會新增一個單獨的 WordPress REST API(v2)端點,其中包含所有可用的術語(所有已使用的類別、標籤和自訂分類法)。, 當您需要在應用程式中建立一...。
  • WP-REST-API Menus 》此外掛新增了「路徑」或「終點」至 WP REST API,以 JSON 格式檢索選單資料。, 此為 Claudio La Barbera (http://www.claudiolabarbera.com) 的 WP-REST-API ...。

文章
Filter
Apply Filters
Mastodon