Skip to content

Commit

Permalink
merged emailconfirmation in nodeshot.community.profiles #130
Browse files Browse the repository at this point in the history
  • Loading branch information
nemesifier committed Sep 7, 2014
1 parent ee67fc8 commit 610e41d
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 91 deletions.
Empty file.
13 changes: 0 additions & 13 deletions nodeshot/community/emailconfirmation/admin.py

This file was deleted.

5 changes: 0 additions & 5 deletions nodeshot/community/emailconfirmation/signals.py

This file was deleted.

14 changes: 0 additions & 14 deletions nodeshot/community/emailconfirmation/views.py

This file was deleted.

29 changes: 19 additions & 10 deletions nodeshot/community/profiles/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,30 @@ class UserAdmin(BaseUserAdmin):
]


class PasswordResetAdmin(admin.ModelAdmin):
pass
list_display = ('user', 'timestamp', 'reset', 'temp_key')


admin.site.register(Profile, UserAdmin)
admin.site.register(PasswordReset, PasswordResetAdmin)


if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailAddress
from .models import EmailAddress, EmailConfirmation

class EmailAddressAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'verified', 'primary')

class EmailConfirmationAdmin(admin.ModelAdmin):
list_display = ('__unicode__', 'key_expired')

admin.site.register((EmailAddress,), EmailAddressAdmin)
admin.site.register((EmailConfirmation,), EmailConfirmationAdmin)

class EmailAddressInline(admin.StackedInline):
model = EmailAddress
extra = 0

UserAdmin.inlines = [EmailAddressInline] + UserAdmin.inlines
UserAdmin.fieldsets[1][1]['fields'].remove('email')


class PasswordResetAdmin(admin.ModelAdmin):
pass
list_display = ('user', 'timestamp', 'reset', 'temp_key')


admin.site.register(Profile, UserAdmin)
admin.site.register(PasswordReset, PasswordResetAdmin)
6 changes: 2 additions & 4 deletions nodeshot/community/profiles/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
User = get_user_model()

from .models import PasswordReset
from .settings import settings, EMAIL_CONFIRMATION

if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailAddress
from .settings import EMAIL_CONFIRMATION


__all__ = [
Expand All @@ -27,6 +24,7 @@ class ResetPasswordForm(forms.Form):
def clean_email(self):
""" ensure email is in the database """
if EMAIL_CONFIRMATION:
from .models import EmailAddress
condition = EmailAddress.objects.filter(email__iexact=self.cleaned_data["email"], verified=True).count() == 0
else:
condition = User.objects.get(email__iexact=self.cleaned_data["email"], is_active=True).count() == 0
Expand Down
2 changes: 1 addition & 1 deletion nodeshot/community/profiles/html_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def password_reset_from_key(request, uidb36, key, **kwargs):


if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailConfirmation, EmailAddress
from .models import EmailConfirmation, EmailAddress
from django.contrib.auth import login

def confirm_email(request, confirmation_key):
Expand Down
13 changes: 3 additions & 10 deletions nodeshot/community/profiles/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
# part of the code of this app is based on pinax.account

from nodeshot.core.base.utils import check_dependencies
from ..settings import settings, EMAIL_CONFIRMATION

if EMAIL_CONFIRMATION:
check_dependencies(
dependencies='nodeshot.community.emailconfirmation',
module='nodeshot.community.profiles'
)
from ..settings import EMAIL_CONFIRMATION


from .profile import Profile
from .social_link import SocialLink
from .password_reset import PasswordReset
from .emailconfirmation import *

__all__ = ['Profile', 'SocialLink', 'PasswordReset']

Expand Down Expand Up @@ -44,8 +38,7 @@ def new_user(sender, **kwargs):


if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.signals import email_confirmed
from nodeshot.community.emailconfirmation.models import EmailConfirmation
from ..signals import email_confirmed

@receiver(email_confirmed, sender=EmailConfirmation)
def activate_user(sender, email_address, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,21 @@

from django.contrib.sites.models import Site

from .signals import email_confirmed, email_confirmation_sent
from ..signals import email_confirmed, email_confirmation_sent

try:
from django.utils.timezone import now
except ImportError:
now = datetime.datetime.now

try:
User = settings.AUTH_USER_MODEL
except AttributeError:
from django.contrib.auth.models import User

__all__ = [
'EmailAddress',
'EmailConfirmation'
]

# this code based in-part on django-registration

class EmailAddressManager(models.Manager):

def add_email(self, user, email):
try:
email_address = self.create(user=user, email=email)
Expand Down Expand Up @@ -62,8 +60,7 @@ def get_users_for(self, email):


class EmailAddress(models.Model):

user = models.ForeignKey(User)
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='email_set')
email = models.EmailField()
verified = models.BooleanField(default=False)
primary = models.BooleanField(default=False)
Expand Down Expand Up @@ -96,6 +93,7 @@ def __unicode__(self):
return u"%s (%s)" % (self.email, self.user)

class Meta:
app_label = 'profiles'
verbose_name = _("email address")
verbose_name_plural = _("email addresses")
unique_together = (
Expand All @@ -104,7 +102,6 @@ class Meta:


class EmailConfirmationManager(models.Manager):

def generate_key(self, email):
"""
Generate a new email confirmation key and return it.
Expand Down Expand Up @@ -144,13 +141,12 @@ def send_confirmation(self, email_address):
current_site = Site.objects.get_current()
# check for the url with the dotted view path
try:
path = reverse("emailconfirmation.views.confirm_email",
args=[confirmation.key])
path = reverse("emailconfirmation.views.confirm_email", args=[confirmation.key])
except NoReverseMatch:
# or get path with named urlconf instead
path = reverse(
"emailconfirmation_confirm_email", args=[confirmation.key])
protocol = getattr(settings, "DEFAULT_HTTP_PROTOCOL", "http")
protocol = settings.PROTOCOL
activate_url = u"%s://%s%s" % (
protocol,
unicode(current_site.domain),
Expand Down Expand Up @@ -183,7 +179,6 @@ def delete_expired_confirmations(self):


class EmailConfirmation(models.Model):

email_address = models.ForeignKey(EmailAddress)
created_at = models.DateTimeField()
key = models.CharField(max_length=40)
Expand All @@ -192,14 +187,14 @@ class EmailConfirmation(models.Model):

def key_expired(self):
confirmation_days = getattr(settings, 'EMAIL_CONFIRMATION_DAYS', 7)
expiration_date = self.created_at + datetime.timedelta(
days=confirmation_days)
expiration_date = self.created_at + datetime.timedelta(days=confirmation_days)
return expiration_date <= timezone.now()
key_expired.boolean = True

def __unicode__(self):
return u"confirmation for %s" % self.email_address

class Meta:
app_label = 'profiles'
verbose_name = _("email confirmation")
verbose_name_plural = _("email confirmations")
4 changes: 2 additions & 2 deletions nodeshot/community/profiles/models/password_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from nodeshot.core.base.utils import now

from .profile import Profile as User
from ..settings import settings


Expand All @@ -20,6 +19,7 @@ def create_for_user(self, user):
""" create password reset for specified user """
# support passing email address too
if type(user) is unicode:
from .profile import Profile as User
user = User.objects.get(email=user)

temp_key = token_generator.make_token(user)
Expand Down Expand Up @@ -48,7 +48,7 @@ class PasswordReset(models.Model):
"""
Password reset Key
"""
user = models.ForeignKey(User, verbose_name=_("user"))
user = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_("user"))

temp_key = models.CharField(_("temp_key"), max_length=100)
timestamp = models.DateTimeField(_("timestamp"), default=now)
Expand Down
6 changes: 3 additions & 3 deletions nodeshot/community/profiles/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.utils.translation import ugettext_lazy as _

from nodeshot.core.base.utils import now
from ..settings import settings, EMAIL_CONFIRMATION, REQUIRED_FIELDS
from ..settings import settings, EMAIL_CONFIRMATION, REQUIRED_FIELDS as PROFILE_REQUIRED_FIELDS
from ..signals import password_changed

import re
Expand Down Expand Up @@ -63,7 +63,7 @@ class Profile(AbstractBaseUser, PermissionsMixin):
objects = UserManager()

USERNAME_FIELD = 'username'
REQUIRED_FIELDS = REQUIRED_FIELDS
REQUIRED_FIELDS = PROFILE_REQUIRED_FIELDS

class Meta:
verbose_name = _('user')
Expand Down Expand Up @@ -102,7 +102,7 @@ def add_email(self):
Add email to DB and sends a confirmation mail if PROFILE_EMAL_CONFIRMATION is True
"""
if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailAddress
from . import EmailAddress
self.is_active = False
self.save()
EmailAddress.objects.add_email(self, self.email)
Expand Down
2 changes: 1 addition & 1 deletion nodeshot/community/profiles/models/social_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SocialLink(BaseDate):
url = models.URLField(_('url'))
description = models.CharField(_('description'), max_length=128, blank=True)

class Meta:
class Meta: #NOQA
app_label = 'profiles'
db_table = 'profiles_social_links'
unique_together = ('user', 'url')
Expand Down
2 changes: 1 addition & 1 deletion nodeshot/community/profiles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
NOTIFICATIONS_INSTALLED = 'nodeshot.community.notifications' in settings.INSTALLED_APPS

if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailAddress
from .models import EmailAddress


__all__ = [
Expand Down
9 changes: 6 additions & 3 deletions nodeshot/community/profiles/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import django.dispatch
from django.dispatch import Signal


user_logged_in = django.dispatch.Signal(providing_args=["request", "user"])
password_changed = django.dispatch.Signal(providing_args=["user",])
user_logged_in = Signal(providing_args=["request", "user"])
password_changed = Signal(providing_args=["user",])

email_confirmed = Signal(providing_args=["email_address"])
email_confirmation_sent = Signal(providing_args=["confirmation"])
6 changes: 2 additions & 4 deletions nodeshot/community/profiles/social_auth_extra/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@

from social_auth.models import UserSocialAuth

from ..settings import settings, EMAIL_CONFIRMATION

if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailAddress
from ..settings import EMAIL_CONFIRMATION


def load_extra_data(backend, details, response, uid, user, social_user=None,
Expand All @@ -19,6 +16,7 @@ def load_extra_data(backend, details, response, uid, user, social_user=None,
UserSocialAuth.get_social_auth(backend.name, uid)

if kwargs['is_new'] and EMAIL_CONFIRMATION:
from ..models import EmailAddress
emailaddress = EmailAddress(**{
'user': user,
'email': user.email,
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion nodeshot/community/profiles/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

if EMAIL_CONFIRMATION:
from nodeshot.core.nodes.models import Node
from nodeshot.community.emailconfirmation.models import EmailAddress, EmailConfirmation
from .models import EmailAddress, EmailConfirmation

from .models import Profile as User
from .models import PasswordReset, SocialLink
Expand Down
2 changes: 1 addition & 1 deletion nodeshot/community/profiles/urls.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf.urls import patterns, url
from .settings import settings, EMAIL_CONFIRMATION
from .settings import EMAIL_CONFIRMATION


urlpatterns = patterns('nodeshot.community.profiles.views',
Expand Down
2 changes: 1 addition & 1 deletion nodeshot/community/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def permission_denied(self, request):


if EMAIL_CONFIRMATION:
from nodeshot.community.emailconfirmation.models import EmailAddress, EmailConfirmation
from .models import EmailAddress, EmailConfirmation

class AccountEmailList(CustomDataMixin, generics.ListCreateAPIView):
"""
Expand Down
1 change: 0 additions & 1 deletion nodeshot/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
'nodeshot.community.participation',
'nodeshot.community.notifications',
'nodeshot.community.profiles',
'nodeshot.community.emailconfirmation',
'nodeshot.community.mailing',
'nodeshot.networking.net',
'nodeshot.networking.links',
Expand Down

0 comments on commit 610e41d

Please sign in to comment.