feature/gresiq-v1
claude/smbcloud-github-app-k9641p
development
feature/apps
feature/build-release
feature/ci-docs
feature/ci-ruby-gems
feature/cicd
feature/completion
feature/dist-nuget
feature/fix-ci-sdk-pypi-rubygem
feature/fix-clippy-on-stable-channel
feature/fix-deployment-script
feature/github-email
feature/gresiq-v1
feature/project-new-structure
feature/rsync-deploy
feature/ruby-runner
feature/sdk-npm
feature/sdk-workflows
feature/smbcloud-cli-release-npm
feature/smbcloud-deploy
feature/wasm
main
release/v0.7.4
| 1 | use { |
| 2 | crate::client_credentials::{ClientCredentials, base_url_builder as tenant_base_url_builder}, |
| 3 | reqwest::Client, |
| 4 | smbcloud_model::{ |
| 5 | error_codes::ErrorResponse, |
| 6 | login::{AccountStatus, LoginParams, UserParam}, |
| 7 | }, |
| 8 | smbcloud_network::{environment::Environment, network::request_login}, |
| 9 | smbcloud_networking::{ |
| 10 | constants::{PATH_USERS_SIGN_IN, SMB_USER_AGENT}, |
| 11 | smb_base_url_builder, |
| 12 | smb_client::SmbClient, |
| 13 | }, |
| 14 | }; |
| 15 | |
| 16 | pub async fn login( |
| 17 | env: Environment, |
| 18 | client: (&SmbClient, &str), |
| 19 | username: String, |
| 20 | password: String, |
| 21 | ) -> Result<AccountStatus, ErrorResponse> { |
| 22 | let login_params = LoginParams { |
| 23 | user: UserParam { |
| 24 | email: username, |
| 25 | password, |
| 26 | }, |
| 27 | }; |
| 28 | let builder = Client::new() |
| 29 | .post(build_smb_login_url(env, client)) |
| 30 | .json(&login_params) |
| 31 | .header("User-agent", SMB_USER_AGENT); |
| 32 | request_login(builder).await |
| 33 | } |
| 34 | |
| 35 | pub async fn login_with_client( |
| 36 | env: Environment, |
| 37 | client: ClientCredentials<'_>, |
| 38 | username: String, |
| 39 | password: String, |
| 40 | ) -> Result<AccountStatus, ErrorResponse> { |
| 41 | let login_params = LoginParams { |
| 42 | user: UserParam { |
| 43 | email: username, |
| 44 | password, |
| 45 | }, |
| 46 | }; |
| 47 | let builder = Client::new() |
| 48 | .post(build_login_url_with_client(env, client)) |
| 49 | .json(&login_params) |
| 50 | .header("User-agent", client.app_id); |
| 51 | request_login(builder).await |
| 52 | } |
| 53 | |
| 54 | pub(crate) fn build_smb_login_url(env: Environment, client: (&SmbClient, &str)) -> String { |
| 55 | let mut url_builder = smb_base_url_builder(env, client); |
| 56 | url_builder.add_route(PATH_USERS_SIGN_IN); |
| 57 | url_builder.build() |
| 58 | } |
| 59 | |
| 60 | fn build_login_url_with_client(env: Environment, client: ClientCredentials<'_>) -> String { |
| 61 | let mut url_builder = tenant_base_url_builder(env, client); |
| 62 | url_builder.add_route("v1/client/users/sign_in"); |
| 63 | url_builder.build() |
| 64 | } |