aboutsummaryrefslogtreecommitdiff
path: root/src/actions/firebase.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/actions/firebase.js')
-rw-r--r--src/actions/firebase.js82
1 files changed, 79 insertions, 3 deletions
diff --git a/src/actions/firebase.js b/src/actions/firebase.js
index a9da36a..7c4a4ad 100644
--- a/src/actions/firebase.js
+++ b/src/actions/firebase.js
@@ -4,9 +4,25 @@ import { firebase, firestore } from '../firebase.js';
export const AUTH_FAIL = 'AUTH_FAIL';
export const AUTH_SUCCESS = 'AUTH_SUCCESS';
export const AUTH_SIGN_OUT = 'AUTH_SIGN_OUT';
+export const CREATE_ACCOUNT = 'CREATE_ACCOUNT';
+export const ADMIN_LISTENER = 'ADMIN_LISTENER';
+export const IS_ADMIN = 'IS_ADMIN';
+export const ADMIN_CONTROLS = 'ADMIN_CONTROLS';
+export const UPDATE_ADMIN = 'UPDATE_ADMIN';
const auth = firebase.auth();
+export const createAccount = (_email, _password) => (dispatch) => {
+ var authTrue = false;
+ firebase.auth().createUserWithEmailAndPassword(_email, _password).then(() => {
+ dispatch(signIn(_email, _password));
+ })
+ .catch((error) => {
+ // Handle Errors here.
+ alert(error.code + ": " + error.message);
+ });
+}
+
export const signIn = (_email, _password) => (dispatch) => {
auth.signInWithEmailAndPassword(_email, _password).then(() => {
var user = auth.currentUser;
@@ -22,6 +38,13 @@ export const signIn = (_email, _password) => (dispatch) => {
dispatch(authSuccess(user));
dispatch(snapshotHours())
dispatch(snapshotRegisteredCompetitions());
+ //Admin controls
+ if( user.uid === 'rxKROQAukzchWuueDLwA9c0YmsT2' || //Lucy Wood
+ user.uid === 'sAVjlnSAETaP5VtTKGhfBKHKeQF2' //Michael Foiani
+ )
+ {
+ dispatch(adminListener());
+ }
})
.catch((error) => {
dispatch(authFail(error.code));
@@ -29,6 +52,19 @@ export const signIn = (_email, _password) => (dispatch) => {
}
+export const adminListener = () => (dispatch, getState) => {
+ document.onkeyup = function(e) {
+ if(e.altKey && e.which == 65) {
+ var docRef = firestore.collection('keys').doc('adminKey');
+ docRef.get().then((doc) => {
+ if(prompt('Enter admin password') == doc.data().password) {
+ dispatch(adminControls());
+ }
+ });
+ }
+ }
+}
+
export const authFail = (errorCode) => {
alert(errorCode);
return {
@@ -50,6 +86,17 @@ export const authSuccess = (_user) => {
}
}
+export const adminControls = () => (dispatch) => {
+ dispatch(updateAdmin());
+}
+
+export const updateAdmin = () => {
+ return {
+ type: UPDATE_ADMIN,
+ payload: true
+ }
+}
+
export const signOut = () => (dispatch) => {
auth.signOut().then(() => {
dispatch(authSignOut());
@@ -62,7 +109,10 @@ export const authSignOut = () => {
payload: false,
code: "Signed Out User",
uid: "",
- userEmail: ""
+ userEmail: "",
+ isAdmin: false,
+ requests: [],
+ compList: []
}
}
//End Firebase Auth
@@ -107,6 +157,8 @@ export const updateHours = (hours, reqHours) => {
export const REGISTER_COMP = 'REGISTER_COMP';
export const SNAPSHOT_REGISTERED_COMPETITIONS = 'SNAPSHOT_REGISTERED_COMPETITIONS';
export const UPDATE_REGISTERED_COMPETITIONS = 'UPDATE_REGISTERED_COMPETITIONS';
+export const FETCH_ALL_REQUESTS = 'FETCH_ALL_REQUESTS';
+export const FETCH_ADMIN_REQUESTS = 'FETCH_ADMIN_REQUESTS';
export const registerComp = (compName) => (dispatch, getState) => {
var docRef = firestore.collection('competitions').doc(compName);
@@ -149,7 +201,28 @@ export const updateRegisteredCompetitions = (registeredComps) => {
}
}
-export const REQUEST_HOURS = 'REQUEST_HOURS';
+export const fetchAllRequests = () => (dispatch) => {
+ var docRef = firestore.collection('requests');
+
+ docRef.onSnapshot((query) => {
+ var requests = [];
+ query.forEach((doc) => {
+ requests.push(doc.data());
+ });
+ console.log(requests);
+ dispatch(fetchAdminRequests(requests));
+ });
+}
+
+export const fetchAdminRequests = (requests) => {
+ return {
+ type: FETCH_ADMIN_REQUESTS,
+ payload: requests
+ }
+}
+
+export const REQUEST_HOURS = 'REQUEST_HOURS';
+export const APPROVE_HOURS = 'APPROVE_HOURS';
export const requestHours = (_time, _trainee, _date) => (dispatch, getState) => {
var docRef = firestore.collection('requests');
@@ -174,6 +247,10 @@ export const requestHours = (_time, _trainee, _date) => (dispatch, getState) =>
});
}
+export const approveHours = () => (dispatch, getState) => {
+ alert("Admin :)");
+}
+
export const CREATE_FOURM_POST = 'CREATE_FOURM_POST';
export const SNAPSHOT_FOURM = 'SNAPSHOT_FOURM';
export const UPDATE_FOURM_POSTS = 'UPDATE_FOURM_POSTS';
@@ -197,7 +274,6 @@ export const snapshotFourms = () => (dispatch) => {
query.forEach((doc) => {
fourmPosts.push(doc.data());
});
- console.log(fourmPosts);
dispatch(updateFourmPosts(fourmPosts));
});
}