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,7 +174,13 @@ impl Handler for AuthHandler {
{
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
if !auth_success {
if let Some(auth) = req.headers.get::<Authorization<Basic>>() {
if let Some(ref password) = auth.password {
auth_success =
@ -183,6 +189,7 @@ impl Handler for AuthHandler {
.insert::<SessionKey>(Session { username: auth.username.clone() });
}
}
}
// Auth via Session
if !auth_success {
@ -193,7 +200,6 @@ impl Handler for AuthHandler {
if !auth_success {
return Err(Error::from(ErrorKind::AuthenticationRequired).into());
}
}
self.handler.handle(req)