feat: new module for user signup

This commit is contained in:
silver 2023-06-04 13:27:15 +01:00
parent 686df5ac03
commit 894b6d42e5
3 changed files with 70 additions and 0 deletions

View file

@ -1,5 +1,6 @@
use skynet_ldap_server::methods::account_update::post_update_ldap; use skynet_ldap_server::methods::account_update::post_update_ldap;
use skynet_ldap_server::{db_init, get_config, State}; use skynet_ldap_server::{db_init, get_config, State};
use skynet_ldap_server::methods::account_new::post_new_account;
#[async_std::main] #[async_std::main]
async fn main() -> tide::Result<()> { async fn main() -> tide::Result<()> {
@ -19,6 +20,8 @@ async fn main() -> tide::Result<()> {
app.at("/ldap/update").post(post_update_ldap); app.at("/ldap/update").post(post_update_ldap);
app.at("/ldap/new").post(post_new_account);
app.listen(host_port).await?; app.listen(host_port).await?;
Ok(()) Ok(())
} }

View file

@ -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<String>
}
/// Handles initial detail entering page
pub async fn post_new_account(mut req: Request<State>) -> 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())
}

View file

@ -1 +1,2 @@
pub mod account_update; pub mod account_update;
pub mod account_new;