Refactor login and reset password URL builders
- Move URL construction logic to new public functions using URLBuilder - Add missing error codes to ErrorCode enum in smbcloud-model
keypair34 committed
May 5, 2026 at 22:40 UTC
2107f6bf01eb18bf197e395196342fe93b8c51f8
3 files changed
+41
-10
crates/smbcloud-auth/src/login.rs
+13
-4
@@ -7,9 +7,9 @@ use {
7
smbcloud_network::{environment::Environment, network::request_login},
8
smbcloud_networking::{
9
constants::{PATH_USERS_SIGN_IN, SMB_USER_AGENT},
10
- smb_base_url_builder,
10
smb_client::SmbClient,
11
},
12
+ url_builder::URLBuilder,
13
};
14
15
pub async fn login(
@@ -31,8 +31,17 @@ pub async fn login(
31
request_login(builder).await
32
}
33
34
-pub(crate) fn build_smb_login_url(env: Environment, client: (&SmbClient, &str)) -> String {
35
- let mut url_builder = smb_base_url_builder(env, client);
36
- url_builder.add_route(PATH_USERS_SIGN_IN);
34
+pub fn build_login_url(env: Environment, client_id: &str, client_secret: &str) -> String {
35
+ let mut url_builder = URLBuilder::new();
36
+ url_builder
37
+ .set_protocol(&env.api_protocol())
38
+ .set_host(&env.api_host())
39
+ .add_param("client_id", client_id)
40
+ .add_param("client_secret", client_secret)
41
+ .add_route(PATH_USERS_SIGN_IN);
42
url_builder.build()
43
}
44
+
45
+pub(crate) fn build_smb_login_url(env: Environment, client: (&SmbClient, &str)) -> String {
46
+ build_login_url(env, client.0.id(), client.1)
47
+}
crates/smbcloud-auth/src/resend_reset_password_instruction.rs
+18
-6
@@ -2,9 +2,8 @@ use {
2
reqwest::Client,
3
smbcloud_model::{account::SmbAuthorization, error_codes::ErrorResponse},
4
smbcloud_network::{environment::Environment, network::request},
5
- smbcloud_networking::{
6
- constants::PATH_RESET_PASSWORD_INSTRUCTIONS, smb_base_url_builder, smb_client::SmbClient,
7
- },
5
+ smbcloud_networking::{constants::PATH_RESET_PASSWORD_INSTRUCTIONS, smb_client::SmbClient},
6
+ url_builder::URLBuilder,
7
};
8
9
pub async fn resend_reset_password_instruction(
@@ -24,11 +23,24 @@ pub async fn resend_reset_password_instruction(
23
request(builder).await
24
}
25
26
+pub fn build_resend_reset_password_instructions_url(
27
+ env: Environment,
28
+ client_id: &str,
29
+ client_secret: &str,
30
+) -> String {
31
+ let mut url_builder = URLBuilder::new();
32
+ url_builder
33
+ .set_protocol(&env.api_protocol())
34
+ .set_host(&env.api_host())
35
+ .add_param("client_id", client_id)
36
+ .add_param("client_secret", client_secret)
37
+ .add_route(PATH_RESET_PASSWORD_INSTRUCTIONS);
38
+ url_builder.build()
39
+}
40
+
41
fn build_smb_resend_reset_password_instructions_url(
42
env: Environment,
43
client: (&SmbClient, &str),
44
) -> String {
31
- let mut url_builder = smb_base_url_builder(env, client);
32
- url_builder.add_route(PATH_RESET_PASSWORD_INSTRUCTIONS);
33
- url_builder.build()
45
+ build_resend_reset_password_instructions_url(env, client.0.id(), client.1)
46
}
crates/smbcloud-model/src/account.rs
+10
@@ -55,8 +55,12 @@ pub struct SmbAuthorization {
55
pub enum ErrorCode {
56
EmailNotFound = 1000,
57
EmailUnverified = 1001,
58
+ EmailConfirmationFailed = 1002,
59
PasswordNotSet = 1003,
60
GithubNotLinked = 1004,
61
+ EmailAlreadyExist = 1005,
62
+ InvalidPassword = 1006,
63
+ HostedMailAccountUnverified = 1007,
64
}
65
66
impl Display for ErrorCode {
@@ -64,8 +68,14 @@ impl Display for ErrorCode {
68
match self {
69
ErrorCode::EmailNotFound => write!(f, "Email not found."),
70
ErrorCode::EmailUnverified => write!(f, "Email not verified."),
71
+ ErrorCode::EmailConfirmationFailed => write!(f, "Email confirmation failed."),
72
ErrorCode::PasswordNotSet => write!(f, "Password not set."),
73
ErrorCode::GithubNotLinked => write!(f, "Github not connected."),
74
+ ErrorCode::EmailAlreadyExist => write!(f, "Email already exists."),
75
+ ErrorCode::InvalidPassword => write!(f, "Invalid password."),
76
+ ErrorCode::HostedMailAccountUnverified => {
77
+ write!(f, "Hosted mail account not fully activated yet.")
78
+ }
79
}
80
}
81
}