diff --git a/src/index.js b/src/index.js
index 396f4a0..01ff80a 100644
--- a/src/index.js
+++ b/src/index.js
@@ -10,7 +10,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
-import { HashRouter, Route, Switch } from 'react-router-dom'
+import { BrowserRouter, Route, Switch } from 'react-router-dom'
import "ionicons/dist/css/ionicons.min.css";
import "font-awesome/css/font-awesome.min.css";
import "simple-line-icons/css/simple-line-icons.css";
@@ -28,11 +28,11 @@ setupI18n();
ReactDOM.render(
(
-
+
-
+
),
document.getElementById('root')
);
diff --git a/src/views/Login.js b/src/views/Login.js
index f9263ad..c00666d 100644
--- a/src/views/Login.js
+++ b/src/views/Login.js
@@ -8,18 +8,19 @@
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
-import React, { Component, Fragment } from 'react';
-import { Redirect } from 'react-router-dom';
-import sha from 'sha.js';
+import React, { Component, Fragment } from "react";
+import { Redirect } from "react-router-dom";
+import sha from "sha.js";
import { api } from "../utils";
-import logo from '../img/logo.svg';
+import logo from "../img/logo.svg";
import { routes } from "../routes";
import ForgotPassword from "../components/login/ForgotPassword";
-import { translate } from 'react-i18next';
+import { translate } from "react-i18next";
+import config from "../config";
class Login extends Component {
state = {
- password: '',
+ password: "",
error: false,
cookiesEnabled: false
};
@@ -41,19 +42,22 @@ class Login extends Component {
if(e.keyCode === 13)
this.authenticate();
else
- this.setState({ password: e.target.value })
+ this.setState({ password: e.target.value });
};
/**
* Try to authenticate the user
*/
- authenticate = () => {
+ authenticate = e => {
+ // Prevent the page from reloading when the user gets redirected
+ e.preventDefault();
+
// 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 });
+ this.setState({ password: "", error: false });
// Send the password to the API to authenticate the user
api.authenticate(hashedPassword)
@@ -67,9 +71,14 @@ class Login extends Component {
api.loggedIn = true;
+ if(config.fakeAPI) {
+ // When using the fake API, set the cookie ourselves
+ document.cookie = "user_id=;";
+ }
+
// Redirect to the page the user was originally going to, or if that doesn't exist, go to home
- const redirect = this.props.location.state.from || '/';
- this.props.history.push(redirect);
+ const locationState = this.props.location.state || "/";
+ this.props.history.push(locationState.from.pathname);
})
// If there was an error, tell the user they used the wrong password
.catch(() => this.setState({ error: true }));
@@ -83,16 +92,16 @@ class Login extends Component {
const { t } = this.props;
return (
-
+
-
+
-
-
+
+
Pi-hole
@@ -115,7 +124,7 @@ class Login extends Component {
{
// If cookies are not enabled (or detected), show a warning
!this.state.cookiesEnabled ?
-
+
{t("Verify that cookies are allowed for {{host}}", { host: window.location.host })}
: null
@@ -135,7 +144,7 @@ class Login extends Component {