start e-mail authentication
This commit is contained in:
parent
4f968e5d1c
commit
50bee498ae
27
ofu_app/apps/registration/migrations/0001_initial.py
Normal file
27
ofu_app/apps/registration/migrations/0001_initial.py
Normal file
@ -0,0 +1,27 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.2 on 2017-10-29 11:07
|
||||
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)),
|
||||
],
|
||||
),
|
||||
]
|
||||
@ -9,6 +9,8 @@ from django.contrib.auth import login
|
||||
from django.contrib.auth.models import User
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.http import urlsafe_base64_decode
|
||||
from django.core.mail import send_mail
|
||||
from django.shortcuts import HttpResponse
|
||||
|
||||
|
||||
def signup(request):
|
||||
@ -18,16 +20,26 @@ def signup(request):
|
||||
user = form.save(commit=False)
|
||||
user.is_active = False
|
||||
user.save()
|
||||
current_site = get_current_site(request)
|
||||
current_site = request.META['HTTP_HOST']
|
||||
subject = 'Activate Your MySite Account'
|
||||
message = render_to_string('registration/account_activation_email.jinja', {
|
||||
'user': user,
|
||||
'domain': current_site.domain,
|
||||
'domain': current_site,
|
||||
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
|
||||
'token': account_activation_token.make_token(user),
|
||||
})
|
||||
user.email_user(subject, message)
|
||||
return redirect('account_activation_sent')
|
||||
|
||||
res = send_mail(
|
||||
'Subject here',
|
||||
'Here is the message.',
|
||||
'signup.basta@gmail.com',
|
||||
['mgoetz1995@gmail.com'],
|
||||
fail_silently=False,
|
||||
)
|
||||
# res = send_mail(from_email="signup.basta@gmail.com", recipient_list=[user.username], subject=subject, message=message)
|
||||
return HttpResponse('%s' % res)
|
||||
# user.email_user(subject, message)
|
||||
# return redirect('account_activation_sent')
|
||||
else:
|
||||
form = SignUpForm()
|
||||
return render(request, 'registration/signup.jinja', {'form': form})
|
||||
@ -45,9 +57,9 @@ def activate(request, uidb64, token):
|
||||
user.profile.email_confirmed = True
|
||||
user.save()
|
||||
login(request, user)
|
||||
return redirect('home')
|
||||
return render(request, 'registration/account_activation_success.jinja')
|
||||
else:
|
||||
return render(request, 'account_activation_invalid.html')
|
||||
return render(request, 'registration/account_activation_invalid.jinja')
|
||||
|
||||
|
||||
def account_activation_sent(request):
|
||||
|
||||
@ -39,6 +39,7 @@ INSTALLED_APPS = [
|
||||
'apps.food',
|
||||
'apps.events',
|
||||
'apps.donar',
|
||||
'apps.registration',
|
||||
'rest_framework',
|
||||
]
|
||||
|
||||
@ -165,7 +166,12 @@ MEDIA_URL = '/media/'
|
||||
|
||||
LOGIN_REDIRECT_URL = 'home'
|
||||
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
|
||||
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
|
||||
EMAIL_HOST = 'smtp.gmail.com'
|
||||
EMAIL_HOST_USER = 'signup.basta@gmail.com'
|
||||
EMAIL_HOST_PASSWORD = '1/SL^QzlSuP<`8gkP4Fd'
|
||||
EMAIL_PORT = '587'
|
||||
EMAIL_USE_TLS = True
|
||||
|
||||
ACCOUNT_EMAIL_UNIQUE = True
|
||||
ACCOUNT_EMAIL_CONFIRMATION_REQUIRED = True
|
||||
|
||||
@ -3,5 +3,5 @@ Hi {{ user.username }},
|
||||
|
||||
Please click on the link below to confirm your registration:
|
||||
|
||||
http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
|
||||
http://{{ domain }}{{ url('activate', args=[uid, token]) }}
|
||||
{% endautoescape %}
|
||||
@ -0,0 +1,11 @@
|
||||
{% extends 'base.jinja' %}
|
||||
|
||||
{% block headline %}<h3 class="text-center">BaStA Login</h3>{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-12 text-center p-3 bg-light text-dark">
|
||||
<h3>Fail</h3>
|
||||
<p>Your user account couldn't be activated</p>
|
||||
<p>Please try it again or inform the Administrator.</p>
|
||||
</div>
|
||||
{% endblock %}
|
||||
@ -0,0 +1,11 @@
|
||||
{% extends 'base.jinja' %}
|
||||
|
||||
{% block headline %}<h3 class="text-center">BaStA Login</h3>{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="col-12 text-center p-3 bg-light text-dark">
|
||||
<h3>Success</h3>
|
||||
<p>Your user account is now activated.</p>
|
||||
<a href="{{ url('home') }}">Click here to show home</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user