Skip to content

Commit

Permalink
Merge branch 'development' into events-with-activitystream
Browse files Browse the repository at this point in the history
  • Loading branch information
ege-kaya committed Dec 10, 2021
2 parents 9d1aefa + b70a41e commit b2b63bb
Show file tree
Hide file tree
Showing 24 changed files with 274 additions and 21 deletions.
2 changes: 1 addition & 1 deletion backend/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'eventposts',
'profiles',
'corsheaders',
'actstream',
'frontend',
]

SITE_ID = 1
Expand Down
1 change: 1 addition & 0 deletions backend/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
path('api/', include('authentication.urls')),
path('api/', include('eventposts.urls')),
path('api/', include('profiles.urls')),
path('', include('frontend.urls'))
]
10 changes: 10 additions & 0 deletions backend/frontend/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": [
["@babel/plugin-transform-runtime",
{
"regenerator": true
}
]
]
}
Empty file added backend/frontend/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions backend/frontend/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/frontend/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class FrontendConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'frontend'
Empty file.
3 changes: 3 additions & 0 deletions backend/frontend/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 75 additions & 0 deletions backend/frontend/static/frontend/bundle.js

Large diffs are not rendered by default.

86 changes: 86 additions & 0 deletions backend/frontend/static/frontend/bundle.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/

/**
* A better abstraction over CSS.
*
* @copyright Oleg Isonen (Slobodskoi) / Isonen 2014-present
* @website https://github.com/cssinjs/jss
* @license MIT
*/

/**
* React Router DOM v6.0.1
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/**
* React Router v6.0.1
*
* Copyright (c) Remix Software Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/

/** @license MUI v5.1.0
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v0.20.2
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v16.13.1
* react-is.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/** @license React v17.0.2
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
1 change: 1 addition & 0 deletions backend/frontend/static/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!doctype html><html lang="en"><head><title></title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="viewport" content="initial-scale=1,width=device-width"/><script defer="defer" src="bundle.js"></script></head><body><div id="app" class=""></div></body></html>
17 changes: 17 additions & 0 deletions backend/frontend/templates/frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Django REST with React</title>
<link rel="stylesheet" href="https://rsms.me/inter/inter.css">

</head>
<body>
<div id="app">
<!-- React will load here -->
</div>
</body>
{% load static %}
<script src="{% static "frontend/bundle.js" %}"></script>
</html>
3 changes: 3 additions & 0 deletions backend/frontend/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions backend/frontend/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path
from . import views


urlpatterns = [
path('', views.index ),
]
5 changes: 5 additions & 0 deletions backend/frontend/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.shortcuts import render


def index(request):
return render(request, 'frontend/index.html')
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"private": true,
"scripts": {
"dev": "webpack --mode development --entry ./src/index.js --output-path ./static/frontend",
"build": "webpack --mode production --entry ./src/index.js --output-path ./static/frontend",
"build": "webpack --mode production --entry ./src/index.js --output-path ../backend/frontend/static/frontend",
"start": "webpack serve --config ./webpack.config.js --mode development --open"
},
"keywords": [],
Expand Down Expand Up @@ -35,6 +35,7 @@
"date-fns": "^2.25.0",
"joi": "^17.4.2",
"lodash": "^4.17.21",
"notistack": "^2.0.3",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router-dom": "^6.0.1",
Expand Down
21 changes: 21 additions & 0 deletions frontend/src/Controllers/AuthInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const headers = {}

export const setHeaders = (accessToken, refreshToken) =>{
headers.access = accessToken
headers.refresh = refreshToken
headers.accessTimeStamp = new Date().getTime()
}

export const getToken = async _=>{
if(headers.accessTimeStamp === null) return false
if(new Date().getTime()-headers.accessTimeStamp < 1000*60*5) return headers.access
const options = {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({refresh:headers.refresh})
}
return fetch("http://34.68.66.109/api/token/refresh/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
.then(r=>r.access)
}
8 changes: 4 additions & 4 deletions frontend/src/Controllers/LoginController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function obtainToken(username_in, password_in){
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username:username_in,password:password_in})
}
return fetch("http://34.122.205.8/api/token/obtain/",options)
return fetch("http://34.68.66.109/api/token/obtain/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
}
Expand All @@ -14,7 +14,7 @@ export function refreshToken(refresh_token){
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({refresh:refresh_token})
}
return fetch("http://34.122.205.8/api/token/refresh/",options)
return fetch("http://34.68.66.109/api/token/refresh/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
}
Expand All @@ -25,7 +25,7 @@ export function postResetPassword(email){
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: email})
}
return fetch("http://34.122.205.8/api/password/reset/",options)
return fetch("http://34.68.66.109/api/password/reset/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
}
Expand All @@ -35,7 +35,7 @@ export function postResetPasswordConfirmation(newPassword,token){
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: newPassword, token: token})
}
return fetch("http://34.122.205.8/api/password/reset/confirm/",options)
return fetch("http://34.68.66.109/api/password/reset/confirm/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
}
10 changes: 8 additions & 2 deletions frontend/src/Controllers/SignUpController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ const SignUpFunction = values =>{
headers: { 'Accept': 'application/json','Content-Type': 'application/json'},
body: JSON.stringify(values)
}
return fetch("http://34.122.205.8/api/user/create/",options)
return fetch("http://34.68.66.109/api/user/create/",options)
.then(response=>response.json())
.then(r=>{console.log(r); return r})
.then(r=>{
if(Array.isArray(r.username))
throw new Error('Something went wrong');
console.log(r);
return r
})

}

export default SignUpFunction
1 change: 1 addition & 0 deletions frontend/src/Views/Home/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
import ArrowBackIosIcon from '@mui/icons-material/ArrowBackIos';
import {getSampleEvents} from "../../Controllers/SampleEventController";
import EventInfoCard from "./EventCard";
import {getToken} from "../../Controllers/AuthInfo";
function Homepage() {
const [sports, setSports] = useState([{}])
const [events, setEvents] = useState([{}])
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/Views/Login/Login.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import * as React from "react";
import Button from "@mui/material/Button";
import {Grid, Paper, TextField, Typography, Box, SvgIcon} from "@mui/material";
import {Grid, Paper, TextField, Typography, Box} from "@mui/material";
import {Link, useNavigate} from 'react-router-dom'
import {Icon} from '@mui/material';
import Joi from 'joi'
import {obtainToken} from "../../Controllers/LoginController";
import {useState} from "react";
import {Alert} from "@mui/lab";
import {setHeaders, getToken} from "../../Controllers/AuthInfo";

const initialState = {
username: {
Expand Down Expand Up @@ -51,6 +50,7 @@ export default function LoginPage(props){
setState(newState)
}
else{
setHeaders(r.refresh, r.access)
navigate("/")
}
})
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/Views/Shared/Layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import {Outlet} from 'react-router-dom'
import Header from './Header'
import {createTheme, ThemeProvider} from "@mui/material/styles";
import { SnackbarProvider} from 'notistack';



Expand All @@ -11,11 +12,12 @@ const Layout = () => {
return (
<React.Fragment>
<ThemeProvider theme={theme}>

<div>
<Header loggedIn={false}/>
<Outlet />
</div>
<SnackbarProvider maxSnack={3}>
<div>
<Header loggedIn={false}/>
<Outlet />
</div>
</SnackbarProvider>
</ThemeProvider>
</React.Fragment>
)
Expand Down
15 changes: 10 additions & 5 deletions frontend/src/Views/Signup/Index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Joi from 'joi'
import {useNavigate} from 'react-router-dom'
import image from '../../logos/reb und(400 x 100 px).png'
import SignUpFunction from "../../Controllers/SignUpController";
import {useSnackbar} from "notistack";


const useStyles = makeStyles(theme => createStyles({
Expand Down Expand Up @@ -128,6 +129,8 @@ export default function SignUp() {
const classes = useStyles()
const navigate = useNavigate()
const [state, setState] = useState(initialState)
const { enqueueSnackbar } = useSnackbar();


const getValue = state => ({
username: state.username.value,
Expand Down Expand Up @@ -168,11 +171,13 @@ export default function SignUp() {
const result = schema.validate(value, {abortEarly: false})
if(result.error)return
SignUpFunction(value).then(_=>{
navigate("/profile/"+value.username)
}
)


navigate("/profile/"+value.username)
enqueueSnackbar("Your account is successfully created.", {variant: "success"})
})
.catch(e=>{
enqueueSnackbar("An error occured in the server.", {variant: "error"})
console.log(e)
})
}

return (
Expand Down

0 comments on commit b2b63bb

Please sign in to comment.