Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/00-team/heydari
Browse files Browse the repository at this point in the history
  • Loading branch information
SadraTghvi committed Oct 5, 2024
2 parents 60d92c2 + 4a9e175 commit 9eafde2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ DATABASE_URL="sqlite://main.db"
RUST_LOG="info"
SIMURGH_API_KEY="simurgh.00-team.org project api key"
SIMURGH_PROJECT="simurgh.00-team.org project id"
HEIMDALL_TOKEN="heimdall.00-team.org site token"
2 changes: 2 additions & 0 deletions config/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ server {
}

location / {
access_log syslog:server=unix:/usr/share/nginx/socks/heimdall.dog.heydari.sock,tag=H,nohostname heimdall;

proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Client-Ip $remote_addr;
Expand Down
10 changes: 10 additions & 0 deletions src/api/verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ async fn verification(
let code = utils::get_random_string(Config::CODE_ABC, 5);
log::info!("code: {code}");

#[cfg(not(debug_assertions))]
utils::heimdall_message(
&format!(
"action: {:?}\nphone: {}\ncode: {code}",
body.action, body.phone
),
"verification",
)
.await;

utils::send_sms(
&body.phone,
&format!("heydari-mi.com\nyour login code: {code}"),
Expand Down
17 changes: 10 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::env::var as evar;
use std::sync::OnceLock;

#[derive(Debug)]
Expand All @@ -7,6 +6,7 @@ pub struct Config {
pub simurgh_project: i64,
pub simurgh_host: String,
pub simurgh_auth: String,
pub heimdall_token: String,
}

impl Config {
Expand All @@ -17,6 +17,12 @@ impl Config {
b"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
}

macro_rules! evar {
($name:literal) => {
std::env::var($name).expect(concat!($name, " was not found in env"))
};
}

pub fn config() -> &'static Config {
static STATE: OnceLock<Config> = OnceLock::new();

Expand All @@ -28,14 +34,11 @@ pub fn config() -> &'static Config {
.to_string();

STATE.get_or_init(|| Config {
simurgh_project: evar("SIMURGH_PROJECT")
.expect("no SIMURGH_PROJECT")
simurgh_project: evar!("SIMURGH_PROJECT")
.parse::<i64>()
.expect("invalid SIMURGH_PROJECT"),
simurgh_auth: format!(
"api-key {}",
evar("SIMURGH_API_KEY").expect("no SIMURGH_API_KEY")
),
simurgh_auth: format!("api-key {}", evar!("SIMURGH_API_KEY")),
simurgh_host,
heimdall_token: evar!("HEIMDALL_TOKEN"),
})
}
17 changes: 17 additions & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,23 @@ pub async fn simurgh_request(
}
}

pub async fn heimdall_message(text: &str, tag: &str) {
let client = awc::Client::new();
let request = client
.post(format!("https://heimdall.00-team.org/api/sites/messages/"))
.insert_header(("authorization", config().heimdall_token.as_str()));

#[derive(Serialize)]
struct Message {
text: String,
tag: String,
}

let _ = request
.send_json(&Message { text: text.to_string(), tag: tag.to_string() })
.await;
}

pub trait CutOff {
fn cut_off(&mut self, len: usize);
}
Expand Down

0 comments on commit 9eafde2

Please sign in to comment.