feat: support mini program phone authorization binding
This commit is contained in:
@@ -67,6 +67,12 @@ pub struct BindWechatPhoneInput {
|
||||
pub verify_code: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct BindWechatVerifiedPhoneInput {
|
||||
pub user_id: String,
|
||||
pub phone_number: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct CreateRefreshSessionInput {
|
||||
pub user_id: String,
|
||||
|
||||
@@ -627,6 +627,33 @@ impl PhoneAuthService {
|
||||
activated_new_user,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn bind_wechat_verified_phone(
|
||||
&self,
|
||||
input: BindWechatVerifiedPhoneInput,
|
||||
) -> Result<BindWechatPhoneResult, PhoneAuthError> {
|
||||
let normalized_phone = normalize_mainland_china_phone_number(&input.phone_number)?;
|
||||
let current_user = self
|
||||
.store
|
||||
.find_by_user_id(&input.user_id)
|
||||
.map_err(map_password_error_to_phone_error)?
|
||||
.ok_or(PhoneAuthError::UserNotFound)?;
|
||||
if current_user.user.binding_status != AuthBindingStatus::PendingBindPhone {
|
||||
return Err(PhoneAuthError::UserStateMismatch);
|
||||
}
|
||||
if !current_user.user.wechat_bound {
|
||||
return Err(PhoneAuthError::UserStateMismatch);
|
||||
}
|
||||
|
||||
let (merged_user, activated_new_user) = self
|
||||
.store
|
||||
.bind_wechat_phone_to_user(&input.user_id, normalized_phone)?;
|
||||
|
||||
Ok(BindWechatPhoneResult {
|
||||
user: merged_user,
|
||||
activated_new_user,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl WechatAuthStateService {
|
||||
|
||||
Reference in New Issue
Block a user