casdoor_sdk/apis/
verification_api.rs1
2
3use reqwest;
4
5use crate::{apis::ResponseContent, models};
6use super::{Error, configuration};
7
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11#[serde(untagged)]
12pub enum ApiControllerSendVerificationCodeError {
13 UnknownValue(serde_json::Value),
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize)]
18#[serde(untagged)]
19pub enum ApiControllerVerifyCaptchaError {
20 UnknownValue(serde_json::Value),
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25#[serde(untagged)]
26pub enum ApiControllerVerifyCodeError {
27 UnknownValue(serde_json::Value),
28}
29
30
31pub async fn send_verification_code(configuration: &configuration::Configuration) -> Result<models::Userinfo, Error<ApiControllerSendVerificationCodeError>> {
32 let local_var_configuration = configuration;
33
34 let local_var_client = &local_var_configuration.client;
38
39 let local_var_uri_str = format!("{}/api/send-verification-code", local_var_configuration.base_path);
40 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
41
42 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
43 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
44 }
45
46 let local_var_req = local_var_req_builder.build()?;
47 let local_var_resp = local_var_client.execute(local_var_req).await?;
48
49 let local_var_status = local_var_resp.status();
50 let local_var_content = local_var_resp.text().await?;
51
52 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
53 serde_json::from_str(&local_var_content).map_err(Error::from)
54 } else {
55 let local_var_entity: Option<ApiControllerSendVerificationCodeError> = serde_json::from_str(&local_var_content).ok();
56 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
57 Err(Error::ResponseError(local_var_error))
58 }
59}
60
61pub async fn verify_captcha(configuration: &configuration::Configuration) -> Result<models::Userinfo, Error<ApiControllerVerifyCaptchaError>> {
62 let local_var_configuration = configuration;
63
64 let local_var_client = &local_var_configuration.client;
68
69 let local_var_uri_str = format!("{}/api/verify-captcha", local_var_configuration.base_path);
70 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
71
72 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
73 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
74 }
75
76 let local_var_req = local_var_req_builder.build()?;
77 let local_var_resp = local_var_client.execute(local_var_req).await?;
78
79 let local_var_status = local_var_resp.status();
80 let local_var_content = local_var_resp.text().await?;
81
82 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
83 serde_json::from_str(&local_var_content).map_err(Error::from)
84 } else {
85 let local_var_entity: Option<ApiControllerVerifyCaptchaError> = serde_json::from_str(&local_var_content).ok();
86 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
87 Err(Error::ResponseError(local_var_error))
88 }
89}
90
91pub async fn verify_code(configuration: &configuration::Configuration) -> Result<models::Userinfo, Error<ApiControllerVerifyCodeError>> {
92 let local_var_configuration = configuration;
93
94 let local_var_client = &local_var_configuration.client;
98
99 let local_var_uri_str = format!("{}/api/verify-code", local_var_configuration.base_path);
100 let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
101
102 if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
103 local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
104 }
105
106 let local_var_req = local_var_req_builder.build()?;
107 let local_var_resp = local_var_client.execute(local_var_req).await?;
108
109 let local_var_status = local_var_resp.status();
110 let local_var_content = local_var_resp.text().await?;
111
112 if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
113 serde_json::from_str(&local_var_content).map_err(Error::from)
114 } else {
115 let local_var_entity: Option<ApiControllerVerifyCodeError> = serde_json::from_str(&local_var_content).ok();
116 let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
117 Err(Error::ResponseError(local_var_error))
118 }
119}
120