This repository was archived by the owner on Sep 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
645723d
commit 39c3845
Showing
47 changed files
with
5,894 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"projects": { | ||
"default": "campus-unb" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
# Project dependencies | ||
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git | ||
node_modules | ||
package-lock.json | ||
.cache/ | ||
.firebase/ | ||
|
||
# Build directory | ||
public/ | ||
/functions | ||
static/admin/*.bundle.* | ||
.DS_Store | ||
yarn-error.log | ||
*.env.* | ||
*.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"database": {"rules": "packages/campus-enrollment-database/rules.json"}, | ||
"functions": {"source": "packages/campus-enrollment-functions"}, | ||
"hosting": {"public": "packages/campus-enrollment-frontend/build"} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "campus-enrollment-database", | ||
"version": "0.0.0-alpha", | ||
"private": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"rules": { | ||
"netlify-subdomain": { | ||
".validate": "newData.isString()", | ||
".read": "root.child('tokens/'+auth.uid).isString()" | ||
}, | ||
"tasks": { | ||
"$task": { | ||
".read": "root.child('tokens/'+auth.uid).isString() && data.child('createdBy').val() === auth.uid", | ||
".validate": "newData.child('type').isString()", | ||
"status": { | ||
".validate": "newData.val() === 'queue' || newData.val() === 'done' || newData.val() === 'error' || newData.val() === 'skipped'" | ||
}, | ||
"createdBy": {".validate": "root.child('tokens/'+newData.val()).isString()"}, | ||
"createdAt": {".validate": "newData.isNumber()"}, | ||
"updatedAt": {".validate": "newData.isNumber()"} | ||
} | ||
}, | ||
"invite": { | ||
".read": "root.child('tokens/'+auth.uid).isString()", | ||
"$sha256": { | ||
".read": "true", | ||
".write": "root.child('tokens/'+auth.uid).isString() && $sha256.length === 64 && $sha256 === $sha256.toLowerCase()", | ||
".validate": "!data.exists() && newData.hasChildren(['email'])", | ||
"email": { | ||
".validate": "newData.isString() && newData.val().contains('@') && newData.val() === newData.val().toLowerCase()" | ||
}, | ||
"full_name": { | ||
".validate": "newData.isString()" | ||
}, | ||
"$other": {".validate": false} | ||
} | ||
}, | ||
"update": { | ||
".read": "root.child('tokens/'+auth.uid).isString()", | ||
"$push": { | ||
".write": "root.child('tokens/'+auth.uid).isString() && newData.child('user_id').isString()", | ||
"user_id": { | ||
".validate": "newData.isString()" | ||
}, | ||
"email": { | ||
".validate": "newData.isString() && newData.val().contains('@') && newData.val() === newData.val().toLowerCase()" | ||
}, | ||
"full_name": { | ||
".validate": "newData.isString()" | ||
}, | ||
"$other": {".validate": false} | ||
} | ||
}, | ||
"retire": { | ||
".read": "root.child('tokens/'+auth.uid).isString()", | ||
"$push": { | ||
".write": "root.child('tokens/'+auth.uid).isString()", | ||
".validate": "newData.child('user_id').isString()", | ||
"user_id": { | ||
".validate": "newData.isString()" | ||
} | ||
} | ||
}, | ||
"tokens": { | ||
"$uid": { | ||
".validate": "newData.isString() || !newData.exists()" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"parser": "babel-eslint", | ||
"extends": [ | ||
"../../.eslintrc.json", | ||
"plugin:react/recommended" | ||
], | ||
"env": { | ||
"browser": true | ||
}, | ||
"rules": { | ||
"react/prop-types": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# dependencies | ||
node_modules | ||
package-lock.json | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
*.log* | ||
.firebase/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"name": "campus-enrollment-frontend", | ||
"version": "0.0.0-alpha", | ||
"homepage": "https://matricula.campus.kunst.cloud/", | ||
"private": true, | ||
"scripts": { | ||
"dev": "react-scripts start", | ||
"lint": "eslint 'src'", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test --env=jsdom" | ||
}, | ||
"dependencies": { | ||
"firebase": "^5.3.1", | ||
"invariant": "^2.2.4", | ||
"react": "^16.4.2", | ||
"react-dom": "^16.4.2", | ||
"react-redux": "^5.0.7", | ||
"react-scripts": "1.1.4", | ||
"rebass": "^2.1.0", | ||
"redux": "^4.0.0", | ||
"redux-implicit-oauth2": "^1.2.1", | ||
"redux-logger": "^3.0.6", | ||
"redux-thunk": "^2.3.0", | ||
"reline": "^1.0.0-beta.3", | ||
"styled-components": "^3.4.1" | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta name="theme-color" content="#000000"> | ||
<!-- | ||
manifest.json provides metadata used when your web app is added to the | ||
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>React App</title> | ||
<style> | ||
body { | ||
margin: 0; | ||
padding: 0; | ||
font-family: sans-serif; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<noscript> | ||
You need to enable JavaScript to run this app. | ||
</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
} | ||
], | ||
"start_url": "./index.html", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
12 changes: 12 additions & 0 deletions
12
packages/campus-enrollment-frontend/src/api/getFirebaseToken.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import invariant from 'invariant' | ||
import http from './http' | ||
|
||
const getFirebaseToken = async token => { | ||
invariant(token, 'getFirebaseToken: input token is missing') | ||
const res = await http.get('token', {auth: {token}, credentials: 'include'}) | ||
const {access_token} = res | ||
invariant(access_token, 'getFirebaseToken: output token is missing') | ||
return access_token | ||
} | ||
|
||
export default getFirebaseToken |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const API_URL = 'https://us-east1-campus-unb.cloudfunctions.net' | ||
|
||
const headersByMethod = { | ||
'HEAD': {}, | ||
'GET': {Accept: 'application/json'}, | ||
'LINK': {Accept: 'application/json'}, | ||
'UNLINK': {Accept: 'application/json'}, | ||
'DELETE': {Accept: 'application/json'}, | ||
'POST': {Accept: 'application/json', 'Content-Type': 'application/json'}, | ||
'PUT': {Accept: 'application/json', 'Content-Type': 'application/json'}, | ||
'PATCH': {Accept: 'application/json', 'Content-Type': 'application/json'}, | ||
} | ||
|
||
const isString = value => typeof value === 'string' | ||
const JSONEncode = body => isString(body) ? body : JSON.stringify(body) | ||
|
||
const api = Object.keys(headersByMethod).reduce((api, method) => { | ||
api[method.toLowerCase()] = async (path, {auth, raw, ...options} = {}) => { | ||
if(typeof path !== 'string') throw new Error(`api.${method}: Missing Path`) | ||
const body = JSONEncode(options.body) | ||
const headers = new Headers({ | ||
...headersByMethod[method], | ||
...options.headers, | ||
...createAuth(auth), | ||
}) | ||
const {href} = new URL(path, API_URL) | ||
const response = await fetch(href, {...options, method, headers, body}) | ||
if(raw) return response | ||
let json = {} | ||
try{json = await response.json()}catch(e){/* swallow */} | ||
|
||
if(json.error){ | ||
const err = new Error(json.error_message || json.error_code || json.error) | ||
err.code = json.error_code | ||
throw err | ||
} | ||
|
||
return Array.isArray(json) | ||
? {items: json, http: response} | ||
: {...json, http: response} | ||
} | ||
return api | ||
}, {}) | ||
|
||
export default api | ||
|
||
const createAuth = ({username, password, token} = {}) => { | ||
const key = 'Authorization' | ||
if(typeof token === 'string') return {[key]: new TokenAuth(token)} | ||
if(typeof username === 'string' && typeof password === 'string'){ | ||
return {[key]: new BasicAuth(username, password)} | ||
} | ||
return {} | ||
} | ||
|
||
export class BasicAuth { | ||
constructor(username, password){ | ||
if(!username) throw new Error('BasicAuth: Missing Username') | ||
if(!password) throw new Error('BasicAuth: Missing Password') | ||
this.username = username | ||
this.password = password | ||
this.toString.bind(this) | ||
} | ||
toString(){ | ||
// [TODO]: replace btoa with propper base64, people use emoji etc | ||
return 'Basic ' + btoa(`${this.username}:${this.password}`) | ||
} | ||
} | ||
|
||
export class TokenAuth { | ||
constructor(token){ | ||
if(!token) throw new Error('TokenAuth: Missing Token') | ||
this.token = token | ||
this.toString.bind(this) | ||
} | ||
toString(){ | ||
return 'Bearer ' + this.token | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export {default as getFirebaseToken} from './getFirebaseToken' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react' | ||
import {Provider as RebassProvider} from 'rebass' | ||
import {Provider as ReduxProvider} from 'react-redux' | ||
import {Provider as FirebaseProvider} from './Firebase' | ||
import store from '../store' | ||
import firebase from '../firebase' | ||
import Home from './Home' | ||
|
||
/* eslint-disable no-mixed-operators */ | ||
|
||
export default class App extends React.Component { | ||
/* globals process */ | ||
static defaultProps = {isTest: process.env.NODE_ENV === 'test'} | ||
render(){ | ||
const {isTest, store: overideStore} = this.props | ||
return ( | ||
<ReduxProvider store={isTest && overideStore || store}> | ||
<FirebaseProvider value={firebase}> | ||
<RebassProvider> | ||
<Home/> | ||
</RebassProvider> | ||
</FirebaseProvider> | ||
</ReduxProvider> | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/campus-enrollment-frontend/src/components/App.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* eslint-env jest */ | ||
|
||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import App from './App' | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div') | ||
ReactDOM.render(<App />, div) | ||
ReactDOM.unmountComponentAtNode(div) | ||
}) |
Oops, something went wrong.