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

Jarvis Website #1228

Open
wants to merge 7 commits into
base: master
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
Empty file added .gitmodules
Empty file.
5 changes: 5 additions & 0 deletions jarvis_website/jarvis_site/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
To run the server call:
1. Start virtual environment
- source env/bin/activate
2. pip install django
3. python manage.py runserver
Binary file added jarvis_website/jarvis_site/db.sqlite3
Binary file not shown.
Empty file.
3 changes: 3 additions & 0 deletions jarvis_website/jarvis_site/downloads/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 jarvis_website/jarvis_site/downloads/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class DownloadsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'downloads'
15 changes: 15 additions & 0 deletions jarvis_website/jarvis_site/downloads/auth_backends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User


class UsernameOrEmailBackend(ModelBackend):
def authenticate(self, request, username=None, password=None, **kwargs):
try:
user = User.objects.get(
email=username) if '@' in username else User.objects.get(username=username)
except User.DoesNotExist:
return None

if user.check_password(password):
return user
return None
64 changes: 64 additions & 0 deletions jarvis_website/jarvis_site/downloads/forums.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from django import forms
from django.contrib.auth.models import User
from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.password_validation import validate_password
from django.core.exceptions import ValidationError


class UpdateEmailForm(forms.ModelForm):
class Meta:
model = User
fields = ['email']
widgets = {
'email': forms.EmailInput(attrs={'class': 'form-control'}),
}


class ChangePasswordForm(PasswordChangeForm):
old_password = forms.CharField(
widget=forms.PasswordInput(attrs={'class': 'form-control'}))
new_password1 = forms.CharField(
widget=forms.PasswordInput(attrs={'class': 'form-control'}))
new_password2 = forms.CharField(
widget=forms.PasswordInput(attrs={'class': 'form-control'}))


class DeleteAccountForm(forms.Form):
password = forms.CharField(
label='Password',
widget=forms.PasswordInput(attrs={'class': 'form-control'}),
)


class CreateAccountForm(forms.ModelForm):
password1 = forms.CharField(
label="Password",
widget=forms.PasswordInput,
help_text="Your password must contain at least 8 characters, cannot be too common, and cannot be entirely numeric.",
)
password2 = forms.CharField(
label="Confirm Password",
widget=forms.PasswordInput,
help_text="Enter the same password as above, for verification.",
)

class Meta:
model = User
fields = ["username", "email"]

def clean_password1(self):
password = self.cleaned_data.get("password1")
try:
validate_password(password) # Validate the password
except ValidationError as e:
self.add_error("password1", e)
return password

def clean(self):
cleaned_data = super().clean()
password1 = cleaned_data.get("password1")
password2 = cleaned_data.get("password2")
if password1 and password2 and password1 != password2:
self.add_error(
"password2", "The two password fields didn’t match.")
return cleaned_data
Empty file.
3 changes: 3 additions & 0 deletions jarvis_website/jarvis_site/downloads/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.
173 changes: 173 additions & 0 deletions jarvis_website/jarvis_site/downloads/templates/downloads/account.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Account</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}

/* Navbar */
nav {
background-color: #333;
color: white;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
}

nav a {
color: white;
text-decoration: none;
font-size: 1.2rem;
font-weight: bold;
}

nav .nav-links {
display: flex;
gap: 15px;
}

nav .nav-links a {
background-color: #0078d7;
padding: 8px 12px;
border-radius: 5px;
font-size: 1rem;
}

nav .nav-links a:hover {
background-color: #0056a3;
}

.container {
max-width: 800px;
margin: 50px auto;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}

h1 {
color: #333;
}

p {
color: #555;
font-size: 1.2rem;
}

.links {
margin: 30px 0;
}

.links a {
display: inline-block;
margin: 10px;
background-color: #0078d7;
color: white;
padding: 10px 15px;
border-radius: 5px;
font-weight: bold;
text-decoration: none;
font-size: 1rem;
}

.links a:hover {
background-color: #0056a3;
}

.logout-button {
margin-top: 20px;
background-color: #d9534f;
color: white;
padding: 10px 15px;
border: none;
border-radius: 5px;
font-weight: bold;
font-size: 1rem;
cursor: pointer;
}

.logout-button:hover {
background-color: #c9302c;
}

/* Account Actions */
.account-actions {
margin: 30px 0;
display: flex;
justify-content: center;
gap: 20px;
}

.account-actions .btn {
display: inline-block;
background-color: #f0ad4e;
color: white;
padding: 10px 15px;
border-radius: 5px;
text-decoration: none;
font-weight: bold;
font-size: 1rem;
}

.account-actions .btn:hover {
background-color: #ec971f;
}

.account-actions .btn.danger {
background-color: #d9534f;
}

.account-actions .btn.danger:hover {
background-color: #c9302c;
}
</style>
</head>
<body>
<!-- Navbar -->
<nav>
<a href="/">JarvisCLI</a>
<div class="nav-links">
<a href="/forums/">Forums</a>
<a href="/account/">Account</a>
<a href="/logout/">Logout</a>
</div>
</nav>

<!-- Account Details -->
<div class="container">
<h1>Welcome, {{ user.username }}!</h1>
<p>Email: {{ user.email }}</p>
<p>Joined: {{ user.date_joined }}</p>

<!-- Navigation Links -->
<div class="links">
<a href="{% url 'my_posts' %}">My Posts</a>
<a href="{% url 'my_replies' %}">My Replies</a>
<a href="{% url 'my_likes' %}">My Likes</a>
</div>

<!-- Account Actions -->
<div class="account-actions">
<a href="{% url 'update_email' %}" class="btn">Update Email</a>
<a href="{% url 'change_password' %}" class="btn">Change Password</a>
<a href="{% url 'delete_account' %}" class="btn danger">Delete Account</a>
</div>

<!-- Logout Form -->
<form action="{% url 'logout' %}" method="post" style="display: inline;">
{% csrf_token %}
<button type="submit" class="logout-button">Logout</button>
</form>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Change Password</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f9;
}

/* Navbar */
nav {
background-color: #333;
color: white;
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 20px;
}

nav a {
color: white;
text-decoration: none;
font-size: 1.2rem;
font-weight: bold;
}

nav .nav-links {
display: flex;
gap: 15px;
}

nav .nav-links a {
background-color: #0078d7;
padding: 8px 12px;
border-radius: 5px;
font-size: 1rem;
}

nav .nav-links a:hover {
background-color: #0056a3;
}

.container {
max-width: 600px;
margin: 50px auto;
background-color: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
text-align: center;
}

h1 {
color: #333;
font-size: 2rem;
}

form {
margin-top: 20px;
}

input {
width: 100%;
padding: 10px;
margin-bottom: 15px;
border: 1px solid #ddd;
border-radius: 5px;
}

button {
background-color: #0078d7;
color: white;
padding: 10px 15px;
border: none;
border-radius: 5px;
font-size: 1rem;
cursor: pointer;
}

button:hover {
background-color: #0056a3;
}
</style>
</head>
<body>
<!-- Navbar -->
<nav>
<a href="/">JarvisCLI</a>
<div class="nav-links">
<a href="/forums/">Forums</a>
<a href="/account/">Account</a>
<a href="/logout/">Logout</a>
</div>
</nav>

<!-- Main Content -->
<div class="container">
<h1>Change Password</h1>
<p>Please enter your current password and your new password.</p>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit">Change Password</button>
</form>
</div>
</body>
</html>
Loading