diff --git a/src/main.rs b/src/main.rs index 959e639..8e5f91b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,6 @@ use skynet_ldap_server::methods::account_update::post_update_ldap; use skynet_ldap_server::{db_init, get_config, State}; +use skynet_ldap_server::methods::account_new::post_new_account; #[async_std::main] async fn main() -> tide::Result<()> { @@ -18,6 +19,8 @@ async fn main() -> tide::Result<()> { let mut app = tide::with_state(state); app.at("/ldap/update").post(post_update_ldap); + + app.at("/ldap/new").post(post_new_account); app.listen(host_port).await?; Ok(()) diff --git a/src/methods/account_new.rs b/src/methods/account_new.rs new file mode 100644 index 0000000..44f0c4d --- /dev/null +++ b/src/methods/account_new.rs @@ -0,0 +1,66 @@ +use crate::State; +use ldap3::exop::PasswordModify; +use ldap3::{LdapConn, Mod, Scope, SearchEntry}; +use std::collections::HashSet; +use tide::prelude::{json, Deserialize}; +use tide::Request; + +#[derive(Debug, Deserialize)] +pub struct LdapNewUser { + user: String, + // email that is used on wolves + mail: String, + name_first : String, + name_second : String, + discord: Option +} + +/// Handles initial detail entering page +pub async fn post_new_account(mut req: Request) -> tide::Result { + // check if username exists + // search ldap and local + // send back that that username is in use + + // check local if email exists (periodic sync) + // if not then request info on individual user + // if there is no email matching still send 200 back + // if there is then send email with link to the account + + // save user details in the db + + let LdapNewUser { + user, + mail, + name_first, + name_second, + discord + } = req.body_json().await?; + + let config = &req.state().config; + + // easier to give each request its own connection + let mut ldap = LdapConn::new(&config.ldap_host)?; + + // ldap3 docs say a blank username and pass is an anon bind + ldap.simple_bind("", "")?.success()?; + + + let dn = format!("uid={},ou=users,dc=skynet,dc=ie", user); + if let Ok(x) = ldap.search(&dn, Scope::Base, "(objectClass=*)", vec!["*"]) { + if let Ok((rs, _res)) = x.success(){ + if !rs.is_empty() { + return Ok(json!({"result": "error", "error": "username not available"}).into()) + } + } + } + + // done with ldap + ldap.unbind()?; + + // now check local + + + + + Ok(json!({"result": "success"}).into()) +} diff --git a/src/methods/mod.rs b/src/methods/mod.rs index d799d9a..db17a92 100644 --- a/src/methods/mod.rs +++ b/src/methods/mod.rs @@ -1 +1,2 @@ pub mod account_update; +pub mod account_new;