main
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 | reqwest::Client, |
| 3 | smbcloud_model::{ |
| 4 | error_codes::ErrorResponse, |
| 5 | login::{AccountStatus, LoginParams, UserParam}, |
| 6 | }, |
| 7 | smbcloud_network::{environment::Environment, network::request_login}, |
| 8 | smbcloud_networking::{ |
| 9 | constants::{PATH_USERS_SIGN_IN, SMB_USER_AGENT}, |
| 10 | smb_client::SmbClient, |
| 11 | }, |
| 12 | url_builder::URLBuilder, |
| 13 | }; |
| 14 | |
| 15 | pub async fn login( |
| 16 | env: Environment, |
| 17 | client: (&SmbClient, &str), |
| 18 | username: String, |
| 19 | password: String, |
| 20 | ) -> Result<AccountStatus, ErrorResponse> { |
| 21 | let login_params = LoginParams { |
| 22 | user: UserParam { |
| 23 | email: username, |
| 24 | password, |
| 25 | }, |
| 26 | }; |
| 27 | let builder = Client::new() |
| 28 | .post(build_smb_login_url(env, client)) |
| 29 | .json(&login_params) |
| 30 | .header("User-agent", SMB_USER_AGENT); |
| 31 | request_login(builder).await |
| 32 | } |
| 33 | |
| 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 | } |