Commit caa09bab authored by Gab De Jesus's avatar Gab De Jesus

test

parent 59d8eeb5
......@@ -106,6 +106,7 @@ AUTH_PASSWORD_VALIDATORS = [
},
]
LOGIN_URL = '/login/'
# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/
......@@ -135,6 +136,6 @@ STATICFILES_DIRS = [
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
LOGIN_REDIRECT_URL = 'reviews_index'
LOGOUT_REDIRECT_URL = 'reviews_index'
LOGOUT_REDIRECT_URL = 'homepage'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
\ No newline at end of file
......@@ -31,6 +31,8 @@ urlpatterns = [
url(r'^login/$', auth_views.LoginView.as_view(template_name='templates/login.html'), name='login'),
url(r'^logout/$', auth_views.LogoutView.as_view(), name='logout'),
url(r'^admin/', admin.site.urls),
url(r'^$', reviews_views.index, name="reviews_index"),
url(r'^profs/', profs_views.index, name="profs_index"),
url(r'^$', reviews_views.index, name="homepage"),
url(r'reviews/$', reviews_views.index, name="reviews_index"),
url(r'^prof/$', profs_views.index, name="profs_index"),
url(r'^prof/(?P<prof_id>[0-9]+)/$', profs_views.getProf, name="profs_getProf"),
]
......@@ -10,9 +10,17 @@ from django.template.loader import render_to_string
from accounts.forms import SignUpForm
from accounts.tokens import account_activation_token
# Import the following for sending emails
import smtplib
from string import Template
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@login_required
def home(request):
return render(request, 'reviews_index')
return render(request, 'homepage')
def signup(request):
if request.method == 'POST':
......@@ -22,14 +30,43 @@ def signup(request):
user.is_active = False
user.save()
current_site = get_current_site(request)
subject = 'Activate your Academe Account'
message = render_to_string('templates/account_activation_email.html', {
# subject = 'Activate your Academe Account'
mess = render_to_string('templates/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})
user.email_user(subject, message)
#set up smtp
s = smtplib.SMTP(host='smtp.gmail.com', port=587)
s.starttls()
MY_ADDRESS = "academe.obf@gmail.com"
s.login(MY_ADDRESS, "Thisisthetester")
with open("templates/account_activation_email.txt", encoding="utf-8") as template_file:
template_file_content = template_file.read()
template_file = Template(template_file_content)
msg = MIMEMultipart() # create a message
message = template_file.substitute(content = str(mess))
# Setup parameters
msg['From'] = MY_ADDRESS
msg['To'] = user.email
print(user.email)
msg['Subject'] = "Academe Account Activation"
msg.attach(MIMEText(message, 'plain'))
s.send_message(msg)
del msg
s.quit()
# user.email_user(subject, mess)
return redirect('account_activation_sent')
else:
form = SignUpForm()
......@@ -50,6 +87,6 @@ def activate(request, uidb64, token):
user.profile.email_confirmed= True
user.save()
auth_login(request, user)
return redirect('reviews_index')
return redirect('homepage')
else:
return render(request, 'templates/account_activation_invalid.html')
No preview for this file type
{% extends 'templates/base.html' %}
{% block content %}
<center><h1>Profs</h1></center>
<table style="border: 1px solid black">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<!-- Create the table rows -->
{% for prof in profs %}
<tr>
<th>{{ prof.first_name }}</th>
<th>{{ prof.last_name }}</th>
</tr>
{% endfor %}
</table>
<!-- Make the form for uploading a new prof -->
<h1>New prof</h1>
<form method="POST">
{% csrf_token %}
{{ prof_form.as_p }}
<button type="submit">Save</button>
</form>
{% extends 'templates/base.html' %}
{% block content %}
<center><h1>Professors</h1></center>
<!-- Create the table rows -->
{% for prof in profs %}
<ul style="text-align: center; list-style: none; padding: 0">
<li><a href="{% url 'profs_getProf' prof_id=prof.id %}">{{ prof.first_name}} {{ prof.last_name }}</a></li>
</ul>
{% endfor %}
<!-- Form for making a new review -->
<h1>New Review</h1>
<form method="POST">
{% csrf_token %}
{{ review_form.as_p }}
<button type="submit">Save</button>
</form>
<!-- Make the form for uploading a new prof -->
<!-- <h1>New prof</h1>
<form method="POST">
{% csrf_token %}
{{ prof_form.as_p }}
<button type="submit">Save</button>
</form> -->
{% endblock %}
\ No newline at end of file
from django.shortcuts import render, redirect
from django.urls import reverse
from profs.models import Prof
from profs.forms import ProfForm
# Create your views here.
def index(request):
if(request.method=='POST'):
form = ProfForm(request.POST)
if(form.is_valid()):
form.save()
# Return to profs_index using reverse so only need to change url in settings.py
return redirect(reverse('profs_index'))
profs = Prof.objects.all()
return render(request, 'profs/index.html', {'prof_form':ProfForm, 'profs': profs})
from django.shortcuts import render, redirect
from django.urls import reverse
from profs.models import Prof
from profs.forms import ProfForm
from reviews.models import Review
from reviews.forms import ReviewForm
from django.contrib.auth.decorators import login_required
# Create your views here.
def index(request):
# Make a prof
# if(request.method=='POST'):
# form = ProfForm(request.POST)
# if(form.is_valid()):
# form.save()
# # Return to profs_index using reverse so only need to change url in settings.py
# return redirect(reverse('profs_index'))
# Make a new review
if(request.method=='POST'):
form = ReviewForm(request.POST)
if(form.is_valid()):
form.save()
return redirect(reverse('profs_index'))
profs = Prof.objects.all()
return render(request, 'profs/index.html', {'review_form': ReviewForm, 'profs': profs})
# Display the page of a prof using id passed through url
@login_required
def getProf(request, prof_id):
prof = Prof.objects.get(pk=prof_id)
reviews = Review.objects.filter(prof=prof)
return render(request, 'profs/prof.html', {'review_form': ReviewForm, 'prof': prof, 'reviews': reviews})
# return redirect(reverse('homepage'))
from django.shortcuts import render, redirect
from django.urls import reverse
from .models import Review
from profs.models import Prof
from .forms import ReviewForm
# Create your views here.
def index(request):
if(request.method=='POST'):
form = ReviewForm(request.POST)
if(form.is_valid()):
form.save()
# Return to reviews index so that no more post on refresh
return redirect(reverse('reviews_index'))
reviews = Review.objects.all()
profs = Prof.objects.all()
upload_form = ReviewForm()
return render(request, 'reviews/index.html', {'reviews': reviews, 'upload_form': upload_form, 'profs': profs})
from django.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.urls import reverse
from .models import Review
from profs.models import Prof
from .forms import ReviewForm
@login_required()
def index(request):
if(request.method=='POST'):
form = ReviewForm(request.POST)
if(form.is_valid()):
form.save()
# Return to reviews index so that no more post on refresh
return redirect(reverse('homepage'))
reviews = Review.objects.all()
profs = Prof.objects.all()
upload_form = ReviewForm()
return render(request, 'reviews/index.html', {'reviews': reviews, 'upload_form': upload_form, 'profs': profs})
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,19 +4,40 @@
<head>
<title>Academe</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.min.css' %}">
</head>
<body>
<h1><center>Academe</center></h1>
<nav>
<ul>
<li><a href="{% url 'reviews_index' %}">Home</a></li>
<li><a href="{% url 'profs_index' %}">Profs</a></li>
<li><a href="{% url 'login' %}">Log in</a></li>
<li><a href="{% url 'logout' %}">Log out</a></li
<li><a href="{% url 'signup' %}">Sign Up</a></li>
<li>{{ user.username }}</li>
</ul>
</nav>
<nav class="navbar navbar-light navbar-toggleable-md bg-faded">
<div class="container">
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav"><span class="navbar-toggler-icon"></span></button>
<a class="navbar-brand" href="{% url 'homepage' %}">Academe</a>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav mr-auto">
<li class="nav-item">
<a class="nav-link" href="{% url 'profs_index' %}">Professors</a>
</li>
</ul>
<form class="form-inline">
<input type="text" class="form-control" placeholder="Search">
<button class="btn btn-outline-success">Search</button>
<ul class="navbar-nav mr-auto">
{% if user.is_authenticated %}
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Logout</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'login' %}">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'signup' %}">Sign-up</a>
</li>
{% endif %}
</ul>
</form>
</div>
</div>
</nav>
{% block content %}
{% endblock %}
</body>
......
......@@ -3,11 +3,11 @@
{% block content %}
<div class="container">
<h1 class="text-center logo my-4">
<a href="{% url 'reviews_index'%}">Academe</a>
<a href="{% url 'homepage'%}">Academe</a>
</h1>
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 col-sm-8">
<div class="card">
<div class="">
<div class="card-body">
<h3 class="card-title">Log in</h3>
<form method="post" novalidate>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment