feat: check emails as well
This commit is contained in:
parent
e83adea4fe
commit
9c54a2f919
1 changed files with 25 additions and 4 deletions
|
@ -46,14 +46,23 @@ pub async fn post_new_account(mut req: Request<State>) -> tide::Result {
|
|||
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!["*"]) {
|
||||
let filter_dn = format!("(uid={})", &user);
|
||||
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 !rs.is_empty() {
|
||||
return Ok(json!({"result": "error", "error": "username not available"}).into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
ldap.unbind()?;
|
||||
|
@ -70,11 +79,23 @@ pub async fn post_new_account(mut req: Request<State>) -> tide::Result {
|
|||
FROM accounts_pending
|
||||
WHERE user == ?
|
||||
"#,
|
||||
).bind(user).fetch_all(pool).await {
|
||||
).bind(&user).fetch_all(pool).await {
|
||||
if !results.is_empty(){
|
||||
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())
|
||||
|
|
Loading…
Reference in a new issue