gets a 422 back from forgejo from user creation request
This commit is contained in:
parent
022f0e6325
commit
bafc93f6af
3 changed files with 17 additions and 8 deletions
|
@ -36,6 +36,7 @@ pub async fn post_signup(
|
|||
Form(form): Form<SignupForm>,
|
||||
) -> Result<impl IntoResponse, CreateUserError> {
|
||||
let user = validate_signup(&form).await?;
|
||||
dbg!(&*SIGNUP_KEY, &user);
|
||||
session.insert(&SIGNUP_KEY, user).await.unwrap();
|
||||
|
||||
Ok(Redirect::to(
|
||||
|
@ -46,7 +47,8 @@ pub async fn post_signup(
|
|||
/// Redirected from Stripe with the receipt of payment.
|
||||
pub async fn payment_success(session: Session, receipt: Option<Path<String>>) -> impl IntoResponse {
|
||||
let user: User = session.get(&SIGNUP_KEY).await.unwrap().unwrap_or_default();
|
||||
|
||||
// dbg!(&session);
|
||||
dbg!(&*SIGNUP_KEY, &user);
|
||||
if receipt.is_none() {
|
||||
log::info!("Got {:?} from the session, but no receipt.", &user);
|
||||
return CreateUserError(CreateUserErrorKind::BadPayment).into_response();
|
||||
|
@ -58,11 +60,15 @@ pub async fn payment_success(session: Session, receipt: Option<Path<String>>) ->
|
|||
return CreateUserError(CreateUserErrorKind::NoFormFound).into_response();
|
||||
}
|
||||
|
||||
if !confirm_payment(&receipt) {
|
||||
if confirm_payment(&receipt) {
|
||||
log::info!("Confirmed payment from {}", &receipt);
|
||||
} else {
|
||||
return CreateUserError(CreateUserErrorKind::BadPayment).into_response();
|
||||
}
|
||||
|
||||
if !create_user(&user) {
|
||||
if create_user(&user) {
|
||||
log::info!("Created user {user:?}");
|
||||
} else {
|
||||
return CreateUserError(CreateUserErrorKind::AlreadyExists).into_response();
|
||||
}
|
||||
// TODO: store the receipt into a durable store to prevent re-use after creating
|
||||
|
@ -85,8 +91,11 @@ fn create_user(user: &User) -> bool {
|
|||
.expect("Could not find $ADD_USER_ENDPOINT in environment");
|
||||
let auth_header = format!("token {token}");
|
||||
let user: ForgejoUser = user.into();
|
||||
let resp = ureq::post(&format!("http://{url}/api/v1/admin/users"))
|
||||
dbg!(&user);
|
||||
let resp = ureq::post(&format!("{url}/api/v1/admin/users"))
|
||||
.set("Authorization", &auth_header)
|
||||
.set("Content-Type", "application/json")
|
||||
.set("accept", "application/json")
|
||||
.send_json(user)
|
||||
.unwrap();
|
||||
resp.status() == 201
|
||||
|
|
|
@ -34,7 +34,7 @@ async fn main() {
|
|||
// just for signups
|
||||
let session_store = MemoryStore::default();
|
||||
let session_layer = SessionManagerLayer::new(session_store)
|
||||
.with_secure(true)
|
||||
.with_secure(false)
|
||||
.with_expiry(Expiry::OnInactivity(time::Duration::hours(2)));
|
||||
|
||||
// the core application, defining the routes and handlers
|
||||
|
|
|
@ -44,10 +44,10 @@ impl Display for User {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Deserialize, Serialize, Default)]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, Default)]
|
||||
pub struct ForgejoUser<'u> {
|
||||
pub username: &'u str,
|
||||
pub full_name: Option<&'u str>,
|
||||
pub full_name: String,
|
||||
pub email: &'u str,
|
||||
pub password: &'u str,
|
||||
pub must_change_password: bool,
|
||||
|
@ -57,7 +57,7 @@ impl<'u> From<&'u User> for ForgejoUser<'u> {
|
|||
fn from(user: &'u User) -> Self {
|
||||
Self {
|
||||
username: &user.username,
|
||||
full_name: user.displayname.as_deref(),
|
||||
full_name: user.displayname.to_owned().unwrap_or(user.username.clone()),
|
||||
email: &user.email,
|
||||
password: &user.password,
|
||||
must_change_password: false,
|
||||
|
|
Loading…
Reference in a new issue