2 files changed
+27
-18
smbpndk-cli/src/account/forgot/mod.rs
+14
-13
@@ -56,6 +56,18 @@ pub async fn process_forgot() -> Result<CommandResult> {
56
}
57
}
58
59
+#[derive(Debug, Serialize)]
60
+pub struct Param {
61
+ pub(crate) user: UserUpdatePassword,
62
+}
63
+
64
+#[derive(Debug, Serialize)]
65
+pub struct UserUpdatePassword {
66
+ pub(crate) reset_password_token: String,
67
+ pub(crate) password: String,
68
+ pub(crate) password_confirmation: String,
69
+}
70
+
71
async fn input_code() -> Result<CommandResult> {
72
let security_code = Input::<String>::with_theme(&ColorfulTheme::default())
73
.with_prompt("Code")
@@ -82,20 +94,9 @@ async fn input_code() -> Result<CommandResult> {
94
.unwrap();
95
let password_confirmation = String::from(&new_password);
96
85
- #[derive(Debug, Serialize)]
86
- struct Param {
87
- user: User,
88
- }
89
-
90
- #[derive(Debug, Serialize)]
91
- struct User {
92
- reset_password_token: String,
93
- password: String,
94
- password_confirmation: String,
95
- }
96
-
97
+ // Should reuse this somehow
98
let params = Param {
98
- user: User {
99
+ user: UserUpdatePassword {
100
reset_password_token: security_code,
101
password: new_password,
102
password_confirmation,
smbpndk-cli/src/account/login/process.rs
+13
-5
@@ -3,7 +3,7 @@ use crate::account::{
3
model::{Data, Status, User},
4
signup::{
5
do_signup, GithubEmail, Provider, SignupGithubParams, SignupMethod, SignupUserGithub,
6
- },
6
+ }, forgot::{Param, UserUpdatePassword},
7
};
8
use anyhow::{anyhow, Result};
9
use console::{style, Term};
@@ -11,6 +11,7 @@ use dialoguer::{theme::ColorfulTheme, Confirm, Input, Password, Select};
11
use log::debug;
12
use reqwest::{Client, Response, StatusCode};
13
use serde::{Deserialize, Serialize};
14
+use serde_json::json;
15
use smbpndk_model::CommandResult;
16
use smbpndk_utils::email_validation;
17
use spinners::Spinner;
@@ -387,12 +388,19 @@ async fn input_reset_password_token() -> Result<CommandResult> {
388
style("Resetting password...").green().bold().to_string(),
389
);
390
391
+ let password_confirmation = password.clone();
392
+
393
+ let params = Param {
394
+ user: UserUpdatePassword {
395
+ reset_password_token: token,
396
+ password,
397
+ password_confirmation,
398
+ },
399
+ };
400
+
401
let response = Client::new()
402
.put(build_smb_reset_password_url())
392
- .body(format!(
393
- "reset_password_token={}&password={}",
394
- token, password
395
- ))
403
+ .json(¶ms)
404
.header("Accept", "application/json")
405
.header("Content-Type", "application/x-www-form-urlencoded")
406
.send()