use crate::prelude::*;
use rive_models::{
account::{AccountInfo, EmailVerification},
data::{
ChangeEmailData, ChangePasswordData, ConfirmAccountDeletionData, CreateAccountData,
PasswordResetData, ResendVerificationData, SendPasswordResetData,
},
};
impl Client {
pub async fn create_account(&self, data: CreateAccountData) -> Result<()> {
self.client
.post(ep!(self, "/auth/account/create"))
.json(&data)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn resend_verification(&self, data: ResendVerificationData) -> Result<()> {
self.client
.post(ep!(self, "/auth/account/reverify"))
.json(&data)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn confirm_account_deletion(&self, data: ConfirmAccountDeletionData) -> Result<()> {
self.client
.put(ep!(self, "/auth/account/delete"))
.json(&data)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn delete_account(&self) -> Result<()> {
self.client
.post(ep!(self, "/auth/account/delete"))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn fetch_account(&self) -> Result<AccountInfo> {
Ok(self
.client
.get(ep!(self, "/auth/account/"))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn disable_account(&self) -> Result<()> {
self.client
.post(ep!(self, "/auth/account/disable"))
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn change_password(&self, data: ChangePasswordData) -> Result<()> {
self.client
.patch(ep!(self, "/auth/account/change/password"))
.json(&data)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn change_email(&self, data: ChangeEmailData) -> Result<()> {
self.client
.patch(ep!(self, "/auth/account/change/email"))
.json(&data)
.auth(&self.authentication)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn verify_email(&self, code: impl Into<String>) -> Result<EmailVerification> {
Ok(self
.client
.post(ep!(self, "/auth/account/verify/{}", code.into()))
.send()
.await?
.process_error()
.await?
.json()
.await?)
}
pub async fn send_password_reset(&self, data: SendPasswordResetData) -> Result<()> {
self.client
.post(ep!(self, "/auth/account/reset_password"))
.json(&data)
.send()
.await?
.process_error()
.await?;
Ok(())
}
pub async fn password_reset(&self, data: PasswordResetData) -> Result<()> {
self.client
.patch(ep!(self, "/auth/account/reset_password"))
.json(&data)
.send()
.await?
.process_error()
.await?;
Ok(())
}
}