Commit c1363a8a authored by JayCay's avatar JayCay

Confirmation email works!

parent 01829092
...@@ -26,7 +26,8 @@ from profs import views as profs_views ...@@ -26,7 +26,8 @@ from profs import views as profs_views
urlpatterns = [ urlpatterns = [
url(r'^signup/$', accounts_views.signup, name='signup'), url(r'^signup/$', accounts_views.signup, name='signup'),
url(r'^account_activation_sent/$', accounts_views.account_activation_sent, name='account_activation_sent'), url(r'^account_activation_sent/$', accounts_views.account_activation_sent, name='account_activation_sent'),
url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',accounts_views.activate, name='activate'), url(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
accounts_views.activate, name='activate'),
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),
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-11-04 09:28
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email_confirmed', models.BooleanField(default=False)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
from django.contrib.sites.shortcuts import get_current_site
from django.contrib.auth import login as auth_login from django.contrib.auth import login as auth_login
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.sites.shortcuts import get_current_site
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from django.utils.encoding import force_bytes from django.utils.encoding import force_bytes, force_text
from django.utils.http import urlsafe_base64_encode from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.template.loader import render_to_string 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
#@login_required @login_required
#def home(request): def home(request):
# return render(request, 'reviews_index') return render(request, 'reviews_index')
def signup(request): def signup(request):
if request.method == 'POST': if request.method == 'POST':
...@@ -21,7 +23,7 @@ def signup(request): ...@@ -21,7 +23,7 @@ def signup(request):
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('account_activation_email.html', { message = 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)),
...@@ -34,7 +36,7 @@ def signup(request): ...@@ -34,7 +36,7 @@ def signup(request):
return render(request, 'templates/signup.html', {'form' : form}) return render(request, 'templates/signup.html', {'form' : form})
def account_activation_sent(request): def account_activation_sent(request):
return render(request, 'account_activation_sent.html') return render(request, 'templates/account_activation_sent.html')
def activate(request, uidb64, token): def activate(request, uidb64, token):
try: try:
...@@ -47,7 +49,7 @@ def activate(request, uidb64, token): ...@@ -47,7 +49,7 @@ def activate(request, uidb64, token):
user.is_active = True user.is_active = True
user.profile.email_confirmed= True user.profile.email_confirmed= True
user.save() user.save()
login(request, user) auth_login(request, user)
return redirect('reviews_index') return redirect('reviews_index')
else: else:
return render(request, '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 %}
<p>The confirmation link was invalid, possibly because it has already been used.</p> <p>The confirmation link was invalid, possibly because it has already been used.</p>
......
{% extends templates/base.html %} {% extends 'templates/base.html' %}
{% block content %} {% block content %}
<p>Please confirm your email address to complete the registration.</p> <p>Please confirm your email address to complete the registration.</p>
......
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