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

test

parent 59d8eeb5
...@@ -106,6 +106,7 @@ AUTH_PASSWORD_VALIDATORS = [ ...@@ -106,6 +106,7 @@ AUTH_PASSWORD_VALIDATORS = [
}, },
] ]
LOGIN_URL = '/login/'
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/ # https://docs.djangoproject.com/en/1.11/topics/i18n/
...@@ -135,6 +136,6 @@ STATICFILES_DIRS = [ ...@@ -135,6 +136,6 @@ STATICFILES_DIRS = [
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
LOGIN_REDIRECT_URL = 'reviews_index' LOGIN_REDIRECT_URL = 'reviews_index'
LOGOUT_REDIRECT_URL = 'reviews_index' LOGOUT_REDIRECT_URL = 'homepage'
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
\ No newline at end of file
...@@ -31,6 +31,8 @@ urlpatterns = [ ...@@ -31,6 +31,8 @@ urlpatterns = [
url(r'^login/$', auth_views.LoginView.as_view(template_name='templates/login.html'), name='login'), 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'^logout/$', auth_views.LogoutView.as_view(), name='logout'),
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
url(r'^$', reviews_views.index, name="reviews_index"), url(r'^$', reviews_views.index, name="homepage"),
url(r'^profs/', profs_views.index, name="profs_index"), 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 ...@@ -10,9 +10,17 @@ from django.template.loader import render_to_string
from accounts.forms import SignUpForm from accounts.forms import SignUpForm
from accounts.tokens import account_activation_token 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 @login_required
def home(request): def home(request):
return render(request, 'reviews_index') return render(request, 'homepage')
def signup(request): def signup(request):
if request.method == 'POST': if request.method == 'POST':
...@@ -22,14 +30,43 @@ def signup(request): ...@@ -22,14 +30,43 @@ def signup(request):
user.is_active = False user.is_active = False
user.save() user.save()
current_site = get_current_site(request) current_site = get_current_site(request)
subject = 'Activate your Academe Account' # subject = 'Activate your Academe Account'
message = render_to_string('templates/account_activation_email.html', { mess = render_to_string('templates/account_activation_email.html', {
'user': user, 'user': user,
'domain': current_site.domain, 'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)), 'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user), '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') return redirect('account_activation_sent')
else: else:
form = SignUpForm() form = SignUpForm()
...@@ -50,6 +87,6 @@ def activate(request, uidb64, token): ...@@ -50,6 +87,6 @@ def activate(request, uidb64, token):
user.profile.email_confirmed= True user.profile.email_confirmed= True
user.save() user.save()
auth_login(request, user) auth_login(request, user)
return redirect('reviews_index') return redirect('homepage')
else: else:
return render(request, 'templates/account_activation_invalid.html') return render(request, 'templates/account_activation_invalid.html')
No preview for this file type
{% extends 'templates/base.html' %} {% extends 'templates/base.html' %}
{% block content %} {% block content %}
<center><h1>Profs</h1></center> <center><h1>Professors</h1></center>
<table style="border: 1px solid black"> <!-- Create the table rows -->
<tr> {% for prof in profs %}
<th>First Name</th> <ul style="text-align: center; list-style: none; padding: 0">
<th>Last Name</th> <li><a href="{% url 'profs_getProf' prof_id=prof.id %}">{{ prof.first_name}} {{ prof.last_name }}</a></li>
</tr> </ul>
<!-- Create the table rows --> {% endfor %}
{% for prof in profs %}
<tr> <!-- Form for making a new review -->
<th>{{ prof.first_name }}</th> <h1>New Review</h1>
<th>{{ prof.last_name }}</th> <form method="POST">
</tr> {% csrf_token %}
{% endfor %} {{ review_form.as_p }}
</table> <button type="submit">Save</button>
</form>
<!-- Make the form for uploading a new prof --> <!-- Make the form for uploading a new prof -->
<h1>New prof</h1> <!-- <h1>New prof</h1>
<form method="POST"> <form method="POST">
{% csrf_token %} {% csrf_token %}
{{ prof_form.as_p }} {{ prof_form.as_p }}
<button type="submit">Save</button> <button type="submit">Save</button>
</form> </form> -->
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -3,14 +3,34 @@ from django.urls import reverse ...@@ -3,14 +3,34 @@ from django.urls import reverse
from profs.models import Prof from profs.models import Prof
from profs.forms import ProfForm 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. # Create your views here.
def index(request): 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'): if(request.method=='POST'):
form = ProfForm(request.POST) form = ReviewForm(request.POST)
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
# Return to profs_index using reverse so only need to change url in settings.py
return redirect(reverse('profs_index')) return redirect(reverse('profs_index'))
profs = Prof.objects.all() profs = Prof.objects.all()
return render(request, 'profs/index.html', {'prof_form':ProfForm, 'profs': profs}) 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.shortcuts import render, redirect
from django.contrib.auth.decorators import login_required
from django.urls import reverse from django.urls import reverse
from .models import Review from .models import Review
from profs.models import Prof from profs.models import Prof
from .forms import ReviewForm from .forms import ReviewForm
# Create your views here. @login_required()
def index(request): def index(request):
if(request.method=='POST'): if(request.method=='POST'):
form = ReviewForm(request.POST) form = ReviewForm(request.POST)
if(form.is_valid()): if(form.is_valid()):
form.save() form.save()
# Return to reviews index so that no more post on refresh # Return to reviews index so that no more post on refresh
return redirect(reverse('reviews_index')) return redirect(reverse('homepage'))
reviews = Review.objects.all() reviews = Review.objects.all()
profs = Prof.objects.all() profs = Prof.objects.all()
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -4,19 +4,40 @@ ...@@ -4,19 +4,40 @@
<head> <head>
<title>Academe</title> <title>Academe</title>
<link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}"> <link rel="stylesheet" type="text/css" href="{% static 'css/main.css' %}">
<link rel="stylesheet" type="text/css" href="{% static 'css/bootstrap.min.css' %}">
</head> </head>
<body> <body>
<h1><center>Academe</center></h1> <nav class="navbar navbar-light navbar-toggleable-md bg-faded">
<nav> <div class="container">
<ul> <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav"><span class="navbar-toggler-icon"></span></button>
<li><a href="{% url 'reviews_index' %}">Home</a></li> <a class="navbar-brand" href="{% url 'homepage' %}">Academe</a>
<li><a href="{% url 'profs_index' %}">Profs</a></li> <div class="collapse navbar-collapse" id="navbarNav">
<li><a href="{% url 'login' %}">Log in</a></li> <ul class="navbar-nav mr-auto">
<li><a href="{% url 'logout' %}">Log out</a></li <li class="nav-item">
<li><a href="{% url 'signup' %}">Sign Up</a></li> <a class="nav-link" href="{% url 'profs_index' %}">Professors</a>
<li>{{ user.username }}</li> </li>
</ul> </ul>
</nav> <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 %} {% block content %}
{% endblock %} {% endblock %}
</body> </body>
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
{% block content %} {% block content %}
<div class="container"> <div class="container">
<h1 class="text-center logo my-4"> <h1 class="text-center logo my-4">
<a href="{% url 'reviews_index'%}">Academe</a> <a href="{% url 'homepage'%}">Academe</a>
</h1> </h1>
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-lg-4 col-md-6 col-sm-8"> <div class="col-lg-4 col-md-6 col-sm-8">
<div class="card"> <div class="">
<div class="card-body"> <div class="card-body">
<h3 class="card-title">Log in</h3> <h3 class="card-title">Log in</h3>
<form method="post" novalidate> <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