Adding some message fields to LoginResponse

invite_instances
Dessalines 2021-12-04 15:39:50 -05:00
parent 52b8e73390
commit 438efe1ad6
4 changed files with 38 additions and 10 deletions

View File

@ -102,6 +102,8 @@ impl Perform for Login {
&context.secret().jwt_secret,
&context.settings().hostname,
)?),
verify_email_sent: false,
registration_created: false,
})
}
}
@ -290,6 +292,8 @@ impl Perform for SaveUserSettings {
&context.secret().jwt_secret,
&context.settings().hostname,
)?),
verify_email_sent: false,
registration_created: false,
})
}
}
@ -338,6 +342,8 @@ impl Perform for ChangePassword {
&context.secret().jwt_secret,
&context.settings().hostname,
)?),
verify_email_sent: false,
registration_created: false,
})
}
}
@ -806,6 +812,8 @@ impl Perform for PasswordChange {
&context.secret().jwt_secret,
&context.settings().hostname,
)?),
verify_email_sent: false,
registration_created: false,
})
}
}

View File

@ -83,6 +83,8 @@ pub struct LoginResponse {
/// This is None in response to `Register` if email verification is enabled, and in response to
/// `DeleteAccount`.
pub jwt: Option<String>,
pub registration_created: bool,
pub verify_email_sent: bool,
}
#[derive(Serialize, Deserialize)]

View File

@ -247,7 +247,7 @@ impl PerformCrud for Register {
}
// Log the user in directly if email verification is not required
let jwt = if email_verification {
let login_response = if email_verification {
send_verification_email(
inserted_local_user.id,
// we check at the beginning of this method that email is set
@ -256,15 +256,29 @@ impl PerformCrud for Register {
context,
)
.await?;
None
LoginResponse {
jwt: None,
verify_email_sent: true,
registration_created: false,
}
} else if require_application {
LoginResponse {
jwt: None,
verify_email_sent: false,
registration_created: true,
}
} else {
Some(Claims::jwt(
inserted_local_user.id.0,
&context.secret().jwt_secret,
&context.settings().hostname,
)?)
LoginResponse {
jwt: Some(Claims::jwt(
inserted_local_user.id.0,
&context.secret().jwt_secret,
&context.settings().hostname,
)?),
verify_email_sent: false,
registration_created: false,
}
};
// TODO this needs a "registration created" type response
Ok(LoginResponse { jwt })
Ok(login_response)
}
}

View File

@ -47,6 +47,10 @@ impl PerformCrud for DeleteAccount {
})
.await??;
Ok(LoginResponse { jwt: None })
Ok(LoginResponse {
jwt: None,
verify_email_sent: false,
registration_created: false,
})
}
}