@@ -78,8 +78,6 @@ pub async fn process_login(env: Environment, is_logged_in: Option<bool>) -> Resu
7878 }
7979}
8080
81- // Private functions
82-
8381async fn login_with_github ( env : Environment ) -> Result < CommandResult > {
8482 match authorize_github ( & env) . await {
8583 Ok ( result) => process_authorization ( env, result) . await ,
@@ -91,30 +89,26 @@ async fn login_with_github(env: Environment) -> Result<CommandResult> {
9189}
9290
9391async fn process_authorization ( env : Environment , auth : SmbAuthorization ) -> Result < CommandResult > {
94- // What to do if not logged in with GitHub?
95- // Check error_code first
92+ // Handle the account state returned by the OAuth flow before treating it as a login.
9693 if let Some ( error_code) = auth. error_code {
9794 debug ! ( "{}" , error_code) ;
9895 match error_code {
9996 EmailNotFound => return create_new_account ( env, auth. user_email , auth. user_info ) . await ,
10097 EmailUnverified => return send_email_verification ( env, auth. user ) . await ,
10198 PasswordNotSet => {
102- // Only for email and password login
10399 let error = anyhow ! ( "Password not set." ) ;
104100 return Err ( error) ;
105101 }
106102 GithubNotLinked => return connect_github_account ( env, auth) . await ,
107103 }
108104 }
109105
110- // Logged in with GitHub!
111- // Token handling is in the lib.rs account module.
106+ // Token handling lives in the account module.
112107 if let Some ( user) = auth. user {
113108 let spinner = Spinner :: new (
114109 spinners:: Spinners :: SimpleDotsScrolling ,
115110 style ( "Logging you in..." ) . green ( ) . bold ( ) . to_string ( ) ,
116111 ) ;
117- // We're logged in with GitHub.
118112 return Ok ( CommandResult {
119113 spinner,
120114 symbol : "✅" . to_owned ( ) ,
@@ -142,7 +136,6 @@ async fn create_new_account(
142136 }
143137 } ;
144138
145- // Create account if user confirms
146139 if !confirm {
147140 let spinner = Spinner :: new (
148141 spinners:: Spinners :: SimpleDotsScrolling ,
@@ -169,11 +162,10 @@ async fn create_new_account(
169162 return do_signup ( env, & params) . await ;
170163 }
171164
172- Err ( anyhow ! ( "Shouldn't be here ." ) )
165+ Err ( anyhow ! ( "GitHub returned incomplete account details ." ) )
173166}
174167
175168async fn send_email_verification ( env : Environment , user : Option < User > ) -> Result < CommandResult > {
176- // Return early if user is null
177169 if let Some ( user) = user {
178170 let confirm = match Confirm :: with_theme ( & ColorfulTheme :: default ( ) )
179171 . with_prompt ( "Do you want to send a new verification email?" )
@@ -186,16 +178,15 @@ async fn send_email_verification(env: Environment, user: Option<User>) -> Result
186178 }
187179 } ;
188180
189- // Send verification email if user confirms
190181 if !confirm {
191182 let spinner = Spinner :: new (
192183 spinners:: Spinners :: SimpleDotsScrolling ,
193- style ( "Cancel operation ." ) . green ( ) . bold ( ) . to_string ( ) ,
184+ style ( "Cancelled ." ) . green ( ) . bold ( ) . to_string ( ) ,
194185 ) ;
195186 return Ok ( CommandResult {
196187 spinner,
197188 symbol : succeed_symbol ( ) ,
198- msg : succeed_message ( "Doing nothing ." ) ,
189+ msg : succeed_message ( "Cancelled ." ) ,
199190 } ) ;
200191 }
201192 resend_email_verification ( env, user) . await
@@ -238,16 +229,15 @@ async fn connect_github_account(env: Environment, auth: SmbAuthorization) -> Res
238229 }
239230 } ;
240231
241- // Link GitHub account if user confirms
242232 if !confirm {
243233 let spinner = Spinner :: new (
244234 spinners:: Spinners :: SimpleDotsScrolling ,
245- succeed_message ( "Cancel operation ." ) ,
235+ succeed_message ( "Cancelled ." ) ,
246236 ) ;
247237 return Ok ( CommandResult {
248238 spinner,
249239 symbol : succeed_symbol ( ) ,
250- msg : succeed_message ( "Doing nothing ." ) ,
240+ msg : succeed_message ( "Cancelled ." ) ,
251241 } ) ;
252242 }
253243
@@ -278,7 +268,7 @@ async fn connect_github_account(env: Environment, auth: SmbAuthorization) -> Res
278268}
279269
280270async fn login_with_email ( env : Environment ) -> Result < CommandResult > {
281- println ! ( "Provide your login credentials ." ) ;
271+ println ! ( "Enter your login details ." ) ;
282272 let username = match Input :: < String > :: with_theme ( & ColorfulTheme :: default ( ) )
283273 . with_prompt ( "Email" )
284274 . validate_with ( |email : & String | email_validation ( email) )
@@ -293,9 +283,7 @@ async fn login_with_email(env: Environment) -> Result<CommandResult> {
293283
294284 match check_email ( env, client ( ) , & username) . await {
295285 Ok ( auth) => {
296- // Only continue with password input if email is found and confirmed.
297286 if auth. error_code . is_some ( ) {
298- // Check if email is in the database, unconfirmed. Only presents password input if email is found and confirmed.
299287 let spinner = Spinner :: new (
300288 spinners:: Spinners :: SimpleDotsScrolling ,
301289 succeed_message ( "Checking email" ) ,
@@ -382,11 +370,11 @@ async fn after_checking_email_step(
382370 }
383371 _ => {
384372 spinner. stop_and_persist ( & fail_symbol ( ) , fail_message ( "An error occurred." ) ) ;
385- Err ( anyhow ! ( "Idk what happened ." ) )
373+ Err ( anyhow ! ( "The server returned an unexpected account state ." ) )
386374 }
387375 }
388376 }
389- None => Err ( anyhow ! ( "Shouldn't be here ." ) ) ,
377+ None => Err ( anyhow ! ( "The server did not return an account state ." ) ) ,
390378 }
391379}
392380
@@ -421,13 +409,12 @@ async fn action_on_account_status(
421409 }
422410 _ => {
423411 spinner. stop_and_persist ( & fail_symbol ( ) , fail_message ( "An error occurred." ) ) ;
424- Err ( anyhow ! ( "Idk what happened ." ) )
412+ Err ( anyhow ! ( "The server returned an unexpected account state ." ) )
425413 }
426414 }
427415}
428416
429417async fn send_reset_password ( env : Environment , user : Option < User > ) -> Result < CommandResult > {
430- // Return early if user is null
431418 if let Some ( user) = user {
432419 let confirm = match Confirm :: with_theme ( & ColorfulTheme :: default ( ) )
433420 . with_prompt ( "Do you want to reset your password?" )
@@ -440,16 +427,15 @@ async fn send_reset_password(env: Environment, user: Option<User>) -> Result<Com
440427 }
441428 } ;
442429
443- // Send verification email if user confirms
444430 if !confirm {
445431 let spinner = Spinner :: new (
446432 spinners:: Spinners :: SimpleDotsScrolling ,
447- style ( "Cancel operation ." ) . green ( ) . bold ( ) . to_string ( ) ,
433+ style ( "Cancelled ." ) . green ( ) . bold ( ) . to_string ( ) ,
448434 ) ;
449435 return Ok ( CommandResult {
450436 spinner,
451437 symbol : succeed_symbol ( ) ,
452- msg : succeed_message ( "Doing nothing ." ) ,
438+ msg : succeed_message ( "Cancelled ." ) ,
453439 } ) ;
454440 }
455441 resend_reset_password_instruction ( env, user) . await
0 commit comments