feat: check emails as well
This commit is contained in:
parent
e83adea4fe
commit
9c54a2f919
1 changed files with 25 additions and 4 deletions
|
@ -46,8 +46,8 @@ pub async fn post_new_account(mut req: Request<State>) -> tide::Result {
|
||||||
ldap.simple_bind("", "")?.success()?;
|
ldap.simple_bind("", "")?.success()?;
|
||||||
|
|
||||||
|
|
||||||
let dn = format!("uid={},ou=users,dc=skynet,dc=ie", user);
|
let filter_dn = format!("(uid={})", &user);
|
||||||
if let Ok(x) = ldap.search(&dn, Scope::Base, "(objectClass=*)", vec!["*"]) {
|
if let Ok(x) = ldap.search("ou=users,dc=skynet,dc=ie", Scope::OneLevel, &filter_dn, vec!["*"]) {
|
||||||
if let Ok((rs, _res)) = x.success(){
|
if let Ok((rs, _res)) = x.success(){
|
||||||
if !rs.is_empty() {
|
if !rs.is_empty() {
|
||||||
return Ok(json!({"result": "error", "error": "username not available"}).into())
|
return Ok(json!({"result": "error", "error": "username not available"}).into())
|
||||||
|
@ -55,6 +55,15 @@ pub async fn post_new_account(mut req: Request<State>) -> tide::Result {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let filter_email = format!("(mail={})", mail);
|
||||||
|
if let Ok(x) = ldap.search("ou=users,dc=skynet,dc=ie", Scope::OneLevel, &filter_email, vec!["*"]) {
|
||||||
|
if let Ok((rs, _res)) = x.success(){
|
||||||
|
if !rs.is_empty() {
|
||||||
|
return Ok(json!({"result": "error", "error": "email in use"}).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// done with ldap
|
// done with ldap
|
||||||
ldap.unbind()?;
|
ldap.unbind()?;
|
||||||
|
|
||||||
|
@ -70,12 +79,24 @@ pub async fn post_new_account(mut req: Request<State>) -> tide::Result {
|
||||||
FROM accounts_pending
|
FROM accounts_pending
|
||||||
WHERE user == ?
|
WHERE user == ?
|
||||||
"#,
|
"#,
|
||||||
).bind(user).fetch_all(pool).await {
|
).bind(&user).fetch_all(pool).await {
|
||||||
if !results.is_empty(){
|
if !results.is_empty(){
|
||||||
return Ok(json!({"result": "error", "error": "username not available"}).into())
|
return Ok(json!({"result": "error", "error": "username not available"}).into())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Ok(results) = sqlx::query_as::<_, AccountsPending>(
|
||||||
|
r#"
|
||||||
|
SELECT *
|
||||||
|
FROM accounts_pending
|
||||||
|
WHERE mail == ?
|
||||||
|
"#,
|
||||||
|
).bind(&mail).fetch_all(pool).await {
|
||||||
|
if !results.is_empty(){
|
||||||
|
return Ok(json!({"result": "error", "error": "email in use"}).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Ok(json!({"result": "success"}).into())
|
Ok(json!({"result": "success"}).into())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue