Bypass auth requirement for first time flow

This commit is contained in:
Antoine Gersant 2017-07-03 16:15:54 -07:00
parent f90a98d231
commit 3ed2c75b30

View file

@ -174,13 +174,20 @@ impl Handler for AuthHandler {
{ {
let mut auth_success = false; let mut auth_success = false;
// Skip auth for first time setup
if user::count(self.db.deref())? == 0 {
auth_success = true;
}
// Auth via Authorization header // Auth via Authorization header
if let Some(auth) = req.headers.get::<Authorization<Basic>>() { if !auth_success {
if let Some(ref password) = auth.password { if let Some(auth) = req.headers.get::<Authorization<Basic>>() {
auth_success = if let Some(ref password) = auth.password {
user::auth(self.db.deref(), auth.username.as_str(), password.as_str())?; auth_success =
req.extensions user::auth(self.db.deref(), auth.username.as_str(), password.as_str())?;
.insert::<SessionKey>(Session { username: auth.username.clone() }); req.extensions
.insert::<SessionKey>(Session { username: auth.username.clone() });
}
} }
} }
@ -193,7 +200,6 @@ impl Handler for AuthHandler {
if !auth_success { if !auth_success {
return Err(Error::from(ErrorKind::AuthenticationRequired).into()); return Err(Error::from(ErrorKind::AuthenticationRequired).into());
} }
} }
self.handler.handle(req) self.handler.handle(req)