-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Email verification #3405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Email verification #3405
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from __future__ import absolute_import | ||
|
||
from datetime import timedelta | ||
|
||
from django.conf import settings | ||
from django.db import models | ||
from django.utils import timezone | ||
from django.utils.crypto import get_random_string | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from sentry.db.models import FlexibleForeignKey, Model, sane_repr | ||
|
||
CHARACTERS = u'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | ||
|
||
|
||
class UserEmail(Model): | ||
|
||
user = FlexibleForeignKey(settings.AUTH_USER_MODEL, | ||
related_name='emails') | ||
email = models.EmailField(_('email address')) | ||
validation_hash = models.CharField(max_length=32) | ||
date_hash_added = models.DateTimeField(default=timezone.now) | ||
is_verified = models.BooleanField( | ||
_('verified'), default=False, | ||
help_text=_('Designates whether this user has confirmed their email.')) | ||
|
||
class Meta: | ||
app_label = 'sentry' | ||
db_table = 'sentry_useremail' | ||
unique_together = (('user', 'email'),) | ||
|
||
__repr__ = sane_repr('user_id', 'email') | ||
|
||
def set_hash(self): | ||
self.date_hash_added = timezone.now() | ||
self.validation_hash = get_random_string(32, CHARACTERS) | ||
|
||
def hash_is_valid(self): | ||
return self.validation_hash and self.date_hash_added > timezone.now() - timedelta(hours=48) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from __future__ import absolute_import | ||
|
||
from django.db import IntegrityError | ||
from django.db.models.signals import post_save | ||
|
||
from sentry.models import User, UserEmail | ||
|
||
|
||
def create_user_email(instance, created, **kwargs): | ||
if created: | ||
try: | ||
UserEmail.objects.create(email=instance.email, user=instance) | ||
except IntegrityError: | ||
pass | ||
|
||
post_save.connect( | ||
create_user_email, | ||
sender=User, | ||
dispatch_uid="create_user_email", | ||
weak=False | ||
) |
632 changes: 632 additions & 0 deletions
632
src/sentry/south_migrations/0259_auto__add_useremail__add_unique_useremail_user_email.py
Large diffs are not rendered by default.
Oops, something went wrong.
618 changes: 618 additions & 0 deletions
618
src/sentry/south_migrations/0260_populate_email_addresses.py
Large diffs are not rendered by default.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
src/sentry/templates/sentry/account/confirm_email/failure.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "sentry/bases/auth.html" %} | ||
|
||
{% load crispy_forms_tags %} | ||
{% load i18n %} | ||
|
||
{% block title %}{% trans "Confirm Email" %} | {{ block.super }}{% endblock %} | ||
|
||
{% block auth_main %} | ||
<h2>{% trans "Oops, something happened" %}</h2> | ||
|
||
<p> | ||
{% url 'sentry-account-settings' as settings_url %} | ||
{% blocktrans %} | ||
There was an error confirming your email. Please try again or visit your <a href={{ settings_url }}>Account Settings</a> to resend the verification email. | ||
{% endblocktrans %} | ||
</p> | ||
{% endblock %} |
21 changes: 21 additions & 0 deletions
21
src/sentry/templates/sentry/account/confirm_email/send.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{% extends "sentry/bases/auth.html" %} | ||
|
||
{% load crispy_forms_tags %} | ||
{% load i18n %} | ||
|
||
{% block title %}{% trans "Confirm Email" %} | {{ block.super }}{% endblock %} | ||
|
||
{% block auth_main %} | ||
|
||
{% if has_unverified_emails %} | ||
<h2>{% trans "Confirmation sent" %}</h2> | ||
<p>{% trans "A verification email has been sent to " %}<strong>{{ request.user.email }}</strong>.</p> | ||
{% else %} | ||
<h2>{% trans "Already confirmed" %}</h2> | ||
<p> | ||
{% blocktrans with user_email=request.user.email %} | ||
Your email <strong>{{ user_email }}</strong> has already been verified. | ||
{% endblocktrans %} | ||
</p> | ||
{% endif %} | ||
{% endblock %} |
12 changes: 12 additions & 0 deletions
12
src/sentry/templates/sentry/account/confirm_email/success.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{% extends "sentry/bases/auth.html" %} | ||
|
||
{% load crispy_forms_tags %} | ||
{% load i18n %} | ||
|
||
{% block title %}{% trans "Confirm Email" %} | {{ block.super }}{% endblock %} | ||
|
||
{% block auth_main %} | ||
<h2>{% trans "Confirmation successful" %}</h2> | ||
<p>{% trans "Thanks for confirming your email." %}</p> | ||
<a class="btn btn-primary" href="{% url 'sentry-login' %}">{% trans "Sign in" %}</a> | ||
{% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% if is_new_user %} | ||
Thanks for signing up for Sentry! | ||
{% endif %} | ||
|
||
Please confirm your email ({{ user.username|safe }}) by clicking the link below: | ||
|
||
{{ url|safe }} | ||
|
||
This link will expire in 48 hours. | ||
|
||
{% if is_new_user %} | ||
If you did not sign up, you may simply ignore this email. | ||
{% else %} | ||
If you did not make this request, you may simply ignore this email. | ||
{% endif %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,6 +183,10 @@ def init_all_applications(): | |
url(r'^register/$', AuthLoginView.as_view(), | ||
name='sentry-register'), | ||
url(r'^account/sudo/$', SudoView.as_view(), name='sentry-sudo'), | ||
url(r'^account/confirm-email/$', accounts.start_confirm_email, | ||
name='sentry-account-confirm-email-send'), | ||
url(r'^account/confirm-email/(?P<user_id>[\d]+)/(?P<hash>[0-9a-zA-Z]+)/$', accounts.confirm_email, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't the |
||
name='sentry-account-confirm-email'), | ||
url(r'^account/recover/$', accounts.recover, | ||
name='sentry-account-recover'), | ||
url(r'^account/recover/confirm/(?P<user_id>[\d]+)/(?P<hash>[0-9a-zA-Z]+)/$', accounts.recover_confirm, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
type='user.confirm_email',
below this line to get sweet sweetmail.{queued,sent}
logging events.If you run tests and they wig out or something doesn't work, rebasing off of
origin/master
will fix it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done. thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍