diff --git a/src/public/js/actions/admins.js b/src/public/js/actions/admins.js
new file mode 100644
index 0000000..22759e1
--- /dev/null
+++ b/src/public/js/actions/admins.js
@@ -0,0 +1,8 @@
+import { configureAxios, request } from "../requests"
+
+export function getUsers() {
+ return request(
+ "ADMIN_LIST_USERS",
+ configureAxios().get("/admins/users")
+ )
+}
diff --git a/src/public/js/app.js b/src/public/js/app.js
index 4d914e0..0fafb56 100644
--- a/src/public/js/app.js
+++ b/src/public/js/app.js
@@ -46,6 +46,7 @@ function mapStateToProps(state) {
}
return {
username: state.userStore.get("username"),
+ isAdmin: state.userStore.get("isAdmin"),
torrentCount: torrentCount,
alerts: state.alerts,
}
@@ -60,6 +61,7 @@ function Main(props) {
diff --git a/src/public/js/components/admins/users.js b/src/public/js/components/admins/users.js
new file mode 100644
index 0000000..d17c2c6
--- /dev/null
+++ b/src/public/js/components/admins/users.js
@@ -0,0 +1,64 @@
+import React from "react"
+import { connect } from "react-redux"
+import { bindActionCreators } from "redux"
+import { getUsers } from "../../actions/admins"
+
+function mapStateToProps(state) {
+ return {
+ users : state.adminStore.get("users"),
+ };
+}
+const mapDispatchToProps = (dipatch) =>
+ bindActionCreators({ getUsers }, dipatch)
+
+function AdminView(props) {
+ return (
+
+ );
+}
+
+function UserList(props) {
+ return (
+
+
Users
+
Users
+
+
+
+ # |
+ Name |
+ Admin |
+ Polochon URL |
+ Polochon token |
+
+
+
+ {props.users.map(function(el, index) {
+ return (
+
+ );
+ })}
+
+
+
+ );
+}
+
+function User(props) {
+ const polochonConfig = props.data.get("RawConfig").get("polochon");
+ const polochonURL = polochonConfig ? polochonConfig.get("url") : "-";
+ const polochonToken = polochonConfig ? polochonConfig.get("token") : "-";
+ const admin = props.data.get("Admin") ? "yes" : "no";
+ return (
+
+ {props.data.get("id")} |
+ {props.data.get("Name")} |
+ {admin} |
+ {polochonURL} |
+ {polochonToken} |
+ |
+
+ );
+}
+
+export default connect(mapStateToProps, mapDispatchToProps)(AdminView);
diff --git a/src/public/js/components/navbar.js b/src/public/js/components/navbar.js
index 8226f62..5c44c5d 100644
--- a/src/public/js/components/navbar.js
+++ b/src/public/js/components/navbar.js
@@ -63,7 +63,7 @@ export default class AppNavBar extends React.PureComponent {
{this.state.userLoggedIn &&
}
-
+
{(this.state.displayMoviesSearch && this.state.userLoggedIn) &&
+ {props.isAdmin &&
+
+
+
+ }
diff --git a/src/public/js/reducers/admins.js b/src/public/js/reducers/admins.js
new file mode 100644
index 0000000..caac3b6
--- /dev/null
+++ b/src/public/js/reducers/admins.js
@@ -0,0 +1,12 @@
+import { Map, List, fromJS } from "immutable"
+
+const defaultState = Map({
+ "users": List(),
+});
+
+const handlers = {
+ "ADMIN_LIST_USERS_FULFILLED": (state, action) => state.set("users", fromJS(action.payload.response.data)),
+}
+
+export default (state = defaultState, action) =>
+ handlers[action.type] ? handlers[action.type](state, action) : state;
diff --git a/src/public/js/reducers/index.js b/src/public/js/reducers/index.js
index 8896c3e..f78f06c 100644
--- a/src/public/js/reducers/index.js
+++ b/src/public/js/reducers/index.js
@@ -7,6 +7,7 @@ import showStore from "./show"
import userStore from "./users"
import alerts from "./alerts"
import torrentStore from "./torrents"
+import adminStore from "./admins"
const rootReducer = combineReducers({
routing: routerReducer,
@@ -16,6 +17,7 @@ const rootReducer = combineReducers({
userStore,
alerts,
torrentStore,
+ adminStore,
})
export default rootReducer;
diff --git a/src/public/js/routes.js b/src/public/js/routes.js
index 99ac4b7..4bde093 100644
--- a/src/public/js/routes.js
+++ b/src/public/js/routes.js
@@ -5,18 +5,23 @@ import UserLoginForm from "./components/users/login"
import UserEdit from "./components/users/edit"
import UserSignUp from "./components/users/signup"
import TorrentList from "./components/torrents/list"
+import AdminView from "./components/admins/users"
import { fetchTorrents } from "./actions/torrents"
import { userLogout, getUserInfos } from "./actions/users"
import { fetchMovies, getMovieExploreOptions } from "./actions/movies"
import { fetchShows, fetchShowDetails, getShowExploreOptions } from "./actions/shows"
+import { getUsers } from "./actions/admins"
import store from "./store"
+// Default route
+const defaultRoute = "/movies/explore/yts/seeds";
+
// This function returns true if the user is logged in, false otherwise
function isLoggedIn() {
const state = store.getState();
- const isLogged = state.userStore.isLogged;
+ const isLogged = state.userStore.get("isLogged");
let token = localStorage.getItem("token");
// Let's check if the user has a token, if he does let's assume he's logged
@@ -59,7 +64,16 @@ const loginCheck = function(nextState, replace, next, f = null) {
next();
}
-const defaultRoute = "/movies/explore/yts/seeds";
+const adminCheck = function(nextState, replace, next, f = null) {
+ const state = store.getState();
+ const isAdmin = state.userStore.get("isAdmin");
+ loginCheck(nextState, replace, next, function() {
+ if (!isAdmin) { replace(defaultRoute); }
+ if (f) { f(); }
+ next();
+ })
+}
+
export default function getRoutes(App) {
return {
path: "/",
@@ -207,6 +221,15 @@ export default function getRoutes(App) {
});
},
},
+ {
+ path: "/admin",
+ component: AdminView,
+ onEnter: function(nextState, replace, next) {
+ adminCheck(nextState, replace, next, function() {
+ store.dispatch(getUsers());
+ });
+ },
+ },
],
};
};