mirror of
https://gitlab.com/fabinfra/fabaccess/bffh.git
synced 2024-11-22 06:47:56 +01:00
Implement addUserFallible instead of addUser
This commit is contained in:
parent
ed10b15a10
commit
505afccbf8
@ -48,29 +48,37 @@ impl manage::Server for Users {
|
|||||||
}
|
}
|
||||||
Promise::ok(())
|
Promise::ok(())
|
||||||
}
|
}
|
||||||
fn add_user(
|
fn add_user_fallible(
|
||||||
&mut self,
|
&mut self,
|
||||||
params: manage::AddUserParams,
|
params: manage::AddUserFallibleParams,
|
||||||
mut result: manage::AddUserResults,
|
mut result: manage::AddUserFallibleResults,
|
||||||
) -> Promise<(), ::capnp::Error> {
|
) -> Promise<(), ::capnp::Error> {
|
||||||
let params = pry!(params.get());
|
let params = pry!(params.get());
|
||||||
let username = pry!(params.get_username());
|
let username = pry!(params.get_username());
|
||||||
let password = pry!(params.get_password());
|
let password = pry!(params.get_password());
|
||||||
// FIXME: saslprep passwords & usernames before storing them
|
// FIXME: saslprep passwords & usernames before storing them
|
||||||
|
|
||||||
|
let mut builder = result.get();
|
||||||
|
|
||||||
if !username.is_empty() && !password.is_empty() {
|
if !username.is_empty() && !password.is_empty() {
|
||||||
if self.session.users.get_user(username).is_none() {
|
if self.session.users.get_user(username).is_none() {
|
||||||
let user = db::User::new_with_plain_pw(username, password);
|
let user = db::User::new_with_plain_pw(username, password);
|
||||||
self.session.users.put_user(username, &user);
|
self.session.users.put_user(username, &user);
|
||||||
let mut builder = result.get();
|
let mut builder = builder.init_successful();
|
||||||
User::fill(&self.session, user, builder);
|
User::fill(&self.session, user, builder);
|
||||||
} else {
|
} else {
|
||||||
|
let mut builder = builder.init_failed();
|
||||||
|
builder.set_error(manage::add_user_error::AddUserError::AlreadyExists);
|
||||||
tracing::warn!("Failed to add user: Username taken");
|
tracing::warn!("Failed to add user: Username taken");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if username.is_empty() {
|
if username.is_empty() {
|
||||||
|
let mut builder = builder.init_failed();
|
||||||
|
builder.set_error(manage::add_user_error::AddUserError::UsernameInvalid);
|
||||||
tracing::warn!("Failed to add user: Username empty");
|
tracing::warn!("Failed to add user: Username empty");
|
||||||
} else if password.is_empty() {
|
} else if password.is_empty() {
|
||||||
|
let mut builder = builder.init_failed();
|
||||||
|
builder.set_error(manage::add_user_error::AddUserError::PasswordInvalid);
|
||||||
tracing::warn!("Failed to add user: Password empty");
|
tracing::warn!("Failed to add user: Password empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user