Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created Login Page #1

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion client/src/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react'
import {Route, Routes} from "react-router-dom";
import { BrowserRouter, Route, Routes } from 'react-router-dom';
import ImageUpload from './components/ImageUpload';
import LoginPage from './pages/LoginPage/LoginPage';

function App() {
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<LoginPage/>} />
<Route path = "/grading" element = {<ImageUpload/>} />
</Routes>
</BrowserRouter>
);
}

Expand Down
39 changes: 39 additions & 0 deletions client/src/pages/LoginPage/LoginPage.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.login__form {
background: #7F5AF0;
border-radius: 5px;
box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
padding: 30px;
margin: 0 auto;
text-align: center;
}
body {
background-color: black;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}


/* Define the styles for the input fields */
.login_form input {
width: 100%;
padding: 12px;
margin: 8px 0;
box-sizing: border-box;
border-radius: 5px;
border: none;
font-size: 1.2em;
}

/* Define the styles for the submit button */
.login_form button {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 5px;
cursor: pointer;
}
28 changes: 28 additions & 0 deletions client/src/pages/LoginPage/LoginPage.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import './LoginPage.css';

const LoginForm = () => {
return(
<>
<div className="login__form">
<form>
<input type="text" placeholder="Username" />
<input type="password" placeholder="Password" />
<button type="submit">Login</button>
</form>
</div>
</>
);
};

const LoginPage = () => {
return(
<>
<div className="login__container">
<LoginForm />
</div>
</>
);
};

export default LoginPage;
Empty file removed client/src/views/grading.jsx
Empty file.
1 change: 1 addition & 0 deletions server/app/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'main_app',
]

MIDDLEWARE = [
Expand Down
3 changes: 2 additions & 1 deletion server/app/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path('admin/', admin.site.urls),
path('', include('main_app.urls')),
]
2 changes: 2 additions & 0 deletions server/app/main_app/templates/homepage.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h1>Welcome, {{ user.username }}</h1>
<a href="{% url 'logout' %}">Logout</a>
7 changes: 7 additions & 0 deletions server/app/main_app/templates/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<form method="post">
{% csrf_token %}
{% if error %}<p style="color: red">{{ error }}</p>{% endif %}
<input type="text" name="username" placeholder="Username">
<input type="password" name="password" placeholder="Password">
<input type="submit" value="Login">
</form>
9 changes: 9 additions & 0 deletions server/app/main_app/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from django.urls import path
from . import views

urlpatterns = [
# ...
path('login/', views.login_view, name='login'),
path('logout/', views.logout_view, name='logout'),
# ...
]
22 changes: 21 additions & 1 deletion server/app/main_app/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
from django.shortcuts import render
from django.shortcuts import render, redirect, get_list_or_404
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect

# Create your views here.
def login_view(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['password']
user = authenticate(request, username=username, password=password)
if user is not None:
login(request, user)
return redirect('home')
else:
return render(request, 'login.html', {'error': 'Invalid login'})
else:
return render(request, 'login.html')

@login_required
def logout_view(request):
logout(request)
return redirect('login')