feat(sms): align provider and verification flow
This commit is contained in:
@@ -21,7 +21,7 @@ trait ServicePart1b {
|
||||
$confirm = (string) ($post['password_confirm'] ?? '');
|
||||
$username = sanitize_user(wp_unslash((string) ($post['user_login'] ?? '')), true);
|
||||
|
||||
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
||||
if (!\AKSRT\Sms\SMS::is_phonenumber($phone)) {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'aksrt')];
|
||||
}
|
||||
if (!$verification_completed) {
|
||||
@@ -159,26 +159,18 @@ trait ServicePart1b {
|
||||
* @param array $post (phone, code)
|
||||
* @return array
|
||||
*/
|
||||
public static function bind_phone(array $post): array {
|
||||
public static function bind_phone(array $post, bool $verification_completed = false): array {
|
||||
if (!is_user_logged_in()) {
|
||||
return ['success' => false, 'error' => __('请先登录', 'aksrt')];
|
||||
}
|
||||
|
||||
$phone = sanitize_text_field((string) ($post['phone'] ?? ''));
|
||||
$code = sanitize_text_field((string) ($post['code'] ?? ''));
|
||||
|
||||
if (!preg_match('/^1[3-9]\d{9}$/', $phone)) {
|
||||
if (!\AKSRT\Sms\SMS::is_phonenumber($phone)) {
|
||||
return ['success' => false, 'error' => __('手机号格式不正确', 'aksrt')];
|
||||
}
|
||||
|
||||
// 验证 SMS 验证码
|
||||
if (class_exists('\AKSRT\Sms\SMS')) {
|
||||
$verify_result = \AKSRT\Sms\SMS::get_instance()->verify_code($phone, $code);
|
||||
if (empty($verify_result['success'])) {
|
||||
return ['success' => false, 'error' => $verify_result['message'] ?? __('验证码不正确', 'aksrt')];
|
||||
}
|
||||
} else {
|
||||
return ['success' => false, 'error' => __('短信服务不可用', 'aksrt')];
|
||||
if (!$verification_completed) {
|
||||
return ['success' => false, 'error' => __('验证码错误或已过期', 'aksrt')];
|
||||
}
|
||||
|
||||
// 检查手机号是否已被其他用户绑定
|
||||
|
||||
Reference in New Issue
Block a user