diff --git a/src/utils.js b/src/utils.js
index d4ac9ba..c122e4f 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -173,7 +173,7 @@ export const api = {
if(config.fakeAPI)
apiLocation = window.location.host + process.env.PUBLIC_URL + "/fakeAPI";
else if(config.developmentMode)
- apiLocation = "pi.hole/admin/api";
+ apiLocation = "pi.hole:8000/admin/api";
else
apiLocation = window.location.hostname + (window.location.port ? ':' + window.location.port : '') + "/admin/api";
diff --git a/src/views/Login.js b/src/views/Login.js
index 1f294c9..d39d083 100644
--- a/src/views/Login.js
+++ b/src/views/Login.js
@@ -29,20 +29,32 @@ export default class Login extends Component {
this.setState({ cookiesEnabled: true });
}
+ /**
+ * Called when the user types into the password box.
+ * If they clicked Enter, try to authenticate them.
+ * Otherwise update the password in the state.
+ *
+ * @param e the event
+ */
handlePasswordChange = e => {
if(e.keyCode === 13)
- this.onAuth();
+ this.authenticate();
else
this.setState({ password: e.target.value })
};
- onAuth = () => {
+ /**
+ * Try to authenticate the user
+ */
+ authenticate = () => {
// Hash the password twice before sending to the API
let hashedPassword = sha("sha256").update(this.state.password).digest("hex");
hashedPassword = sha("sha256").update(hashedPassword).digest("hex");
+ // Clear the state
this.setState({ password: '', error: false });
+ // Send the password to the API to authenticate the user
api.authenticate(hashedPassword)
.then(data => {
// Verify status
@@ -58,10 +70,12 @@ export default class Login extends Component {
const redirect = this.props.location.state.from || '/';
this.props.history.push(redirect);
})
+ // If there was an error, tell the user they used the wrong password
.catch(() => this.setState({ error: true }));
};
render() {
+ // If the user is already logged in, then go to the home page
if(api.loggedIn)
return
Sign in to start your session
{
+ // If the user tried to go to a protected page and is not logged in,
+ // tell them they will be redirected once login is successful
this.props.location.state && this.props.location.state.from.pathname in routes ?
(
{window.location.host}
@@ -119,7 +136,8 @@ export default class Login extends Component {