Skip to content

Commit

Permalink
Merge pull request #158 from ZeusWPI/feature/registration-hook
Browse files Browse the repository at this point in the history
Basic webhook functionality on registration
  • Loading branch information
rien authored Oct 22, 2021
2 parents bd624f6 + 5194c11 commit 26de28f
Show file tree
Hide file tree
Showing 12 changed files with 289 additions and 13 deletions.
129 changes: 117 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ urlencoding = "2.1"
toml = "0.5"
rand = "0.8"
regex = "1.0"
reqwest = { version = "0.11.0", features = [ "json" ] }
rocket = { version = "0.5.0-rc.1", features = [ "json", "secrets" ] }
serde = "1.0"
serde_json = "1.0"
Expand Down
2 changes: 2 additions & 0 deletions Rocket.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ maximum_pending_users = 25
secret_key = "1vwCFFPSdQya895gNiO556SzmfShG6MokstgttLvwjw="
bcrypt_cost = 4
seed_database = true
webhook_url = "http://localhost:8080/hook"

[debug.databases.postgresql_database]
url = "postgresql://zauth:zauth@localhost/zauth"
Expand All @@ -30,6 +31,7 @@ port = 8000
# base_url = # URL where the application is hosten (e.g. https://auth.zeus.gent)
# mail_from = # From header to set when sending emails (e.g. [email protected])
# mail_server = # domain of the SMTP server used to send mail (e.g. smtp.zeus.gent)
# webhook_url = # hook to post new (approved) user's details to

# See src/config.rs for all the possible config values and their defaults

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{
devShell = mkShell {
buildInputs = [
rust-bin.nightly.latest.default
(rust-bin.nightly.latest.default.override { extensions = [ "rust-analyzer-preview" "rust-src" ]; })
openssl.dev
pkg-config
docker-compose
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Config {
pub mail_from: String,
pub mail_server: String,
pub maximum_pending_users: usize,
pub webhook_url: Option<String>,
}

impl Config {
Expand Down
3 changes: 3 additions & 0 deletions src/controllers/users_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::ephemeral::session::{
};
use crate::errors::Either::{self, Left, Right};
use crate::errors::{InternalError, OneOf, Result, ZauthError};
use crate::hooker::Hooker;
use crate::mailer::Mailer;
use crate::models::user::*;
use crate::views::accepter::Accepter;
Expand Down Expand Up @@ -219,6 +220,7 @@ pub async fn set_approved<'r>(
username: String,
_session: AdminSession,
mailer: &'r State<Mailer>,
hooker: &'r State<Hooker>,
conf: &'r State<Config>,
db: DbConn,
) -> Result<impl Responder<'r, 'static>> {
Expand All @@ -227,6 +229,7 @@ pub async fn set_approved<'r>(

let login_url = uri!(conf.base_url(), new_session);

hooker.user_approved(&user).await?;
mailer
.create(
&user,
Expand Down
3 changes: 3 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use rocket::tokio::sync::mpsc::error::{SendError, TrySendError};
use std::convert::Infallible;
use validator::ValidationErrors;

use crate::models::user::User;
use crate::views::accepter::Accepter;

#[derive(Error, Debug)]
Expand Down Expand Up @@ -203,6 +204,8 @@ pub enum InternalError {
InvalidEmail(#[from] lettre::address::AddressError),
#[error("Mailer error")]
MailError(#[from] lettre::error::Error),
#[error("Hooker stopped processing items")]
HookerStopped(#[from] SendError<User>),
#[error("Mailer stopped processing items")]
MailerStopped(#[from] SendError<Message>),
#[error("Mail queue full")]
Expand Down
Loading

0 comments on commit 26de28f

Please sign in to comment.