Skip to content

Commit

Permalink
feat: closes #2, signup with email & password + email verification
Browse files Browse the repository at this point in the history
  • Loading branch information
erictheise committed Mar 18, 2020
1 parent 3d4e2f3 commit d90e875
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
2 changes: 1 addition & 1 deletion accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class UserSocialNetworkInline(admin.TabularInline):

class CustomUserAdmin(UserAdmin):
UserAdmin.fieldsets = (
(None, {'fields': ('username', 'password')}),
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'middle_name', 'last_name', 'bio', 'city', 'state', 'postal_code', 'country', 'url', 'geom',)}),
('Free text fields', {'fields': ('notes',)}),
('Permissions', {'fields': ('is_active', 'is_staff', 'is_superuser', 'groups', 'user_permissions')}),
Expand Down
15 changes: 13 additions & 2 deletions accounts/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.gis.db import models
from django.db.models.signals import pre_save
from django.dispatch import receiver
from django.contrib.auth.models import AbstractUser, UserManager
from django_countries.fields import CountryField
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -70,7 +71,7 @@ class User(AbstractUser):
# created_at: would normally add this but django-registration gives us date_joined
updated_at = models.DateTimeField(auto_now=True)

USERNAME_FIELD = 'username'
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []

@classmethod
Expand All @@ -81,6 +82,16 @@ class Meta:
db_table = 'auth_user'


# Because User extends AbstractUser the underlying model includes a `username` field with a `unique` constraint.
# Because we don't use it, PostgreSQL complains that uniqueness is violated when an empty string comes in. This
# relies on the pre_save signal to set the `username` field equal to the `email` field. `username` does not and
# should never elsewhere appear in the codebase.
@receiver(pre_save, sender=User)
def mirror_username_from_email(sender, instance, *args, **kwargs):
instance.username = instance.email



class UserSocialNetwork(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
socialnetwork = models.ForeignKey(SocialNetwork, on_delete=models.CASCADE)
Expand Down
2 changes: 2 additions & 0 deletions cmdi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_LOGOUT_REDIRECT_URL = '/maps/'
ACCOUNT_EMAIL_VERIFICATION = 'mandatory'
ACCOUNT_EMAIL_SUBJECT_PREFIX = ''
ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 1
ACCOUNT_LOGIN_ON_EMAIL_CONFIRMATION = True

WSGI_APPLICATION = 'cmdi.wsgi.application'

Expand Down
4 changes: 4 additions & 0 deletions templates/account/email/email_confirmation_subject.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% load i18n %}
{% autoescape off %}
{% blocktrans %}Please activate your new Platform Coop account within 24 hours{% endblocktrans %}
{% endautoescape %}
15 changes: 15 additions & 0 deletions templates/account/verification_sent.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "account/base.html" %}

{% load i18n %}

{% block title %}{% trans "Verify Your E-mail Address" %}{% endblock %}

{% block content %}
<div class="page-header">
<p><a class="link--inverse" href="{% url 'index' %}">Home</a></p>
<h1>{% trans "Verify Your E-mail Address" %}</h1>
</div>

<p>{% blocktrans %}We have sent an e-mail to you for verification. Follow the link provided to finalize the signup process. Please contact us if you do not receive it within a few minutes.{% endblocktrans %}</p>

{% endblock %}

0 comments on commit d90e875

Please sign in to comment.