Revision 751d24cf

b/snf-astakos-app/astakos/im/activation_backends.py
45 45
from astakos.im.models import AstakosUser, Invitation
46 46
from astakos.im.forms import *
47 47
from astakos.im.util import get_invitation
48
from astakos.im.functions import send_verification, send_admin_notification, activate, SendMailError
49
from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, MODERATION_ENABLED, SITENAME, DEFAULT_ADMIN_EMAIL, RE_USER_EMAIL_PATTERNS
48
from astakos.im.functions import send_verification, send_activation, \
49
    send_admin_notification, activate, SendMailError
50
from astakos.im.settings import INVITATIONS_ENABLED, DEFAULT_CONTACT_EMAIL, \
51
    DEFAULT_FROM_EMAIL, MODERATION_ENABLED, SITENAME, DEFAULT_ADMIN_EMAIL, RE_USER_EMAIL_PATTERNS
50 52

  
51 53
import socket
52 54
import logging
......
100 102
        return globals()[formclass](initial_data, instance=instance, request=request)
101 103
    
102 104
    def handle_activation(self, user, \
103
                          verification_template_name='im/activation_email.txt', \
105
                          activation_template_name='im/activation_email.txt', \
104 106
                          greeting_template_name='im/welcome_email.txt', \
105 107
                          admin_email_template_name='im/admin_notification.txt', \
106 108
                          switch_accounts_email_template_name='im/switch_accounts_email.txt'):
......
127 129
                    activate(user, greeting_template_name)
128 130
                    return RegistationCompleted()
129 131
                else:
130
                    send_verification(user, verification_template_name)
132
                    send_activation(user, activation_template_name)
131 133
                    return VerificationSent()
132 134
            else:
133 135
                send_admin_notification(user, admin_email_template_name)
b/snf-astakos-app/astakos/im/functions.py
44 44
from urllib import quote
45 45
from urlparse import urljoin
46 46
from smtplib import SMTPException
47
from datetime import datetime
47 48

  
48 49
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, SITENAME, BASEURL, DEFAULT_ADMIN_EMAIL
49 50
from astakos.im.models import Invitation, AstakosUser
......
74 75
    else:
75 76
        logger.info('Sent activation %s', user)
76 77

  
78
def send_activation(user, template_name='im/activation_email.txt'):
79
    send_verification(user, template_name)
80
    user.activation_sent = datetime.now()
81
    user.save()
82

  
77 83
def send_admin_notification(user, template_name='im/admin_notification.txt'):
78 84
    """
79 85
    Send email to DEFAULT_ADMIN_EMAIL to notify for a new user registration.
b/snf-astakos-app/astakos/im/management/commands/listusers.py
54 54
            dest='pending',
55 55
            default=False,
56 56
            help="List only users pending activation"),
57
        make_option('-n',
58
            action='store_true',
59
            dest='pending_send_mail',
60
            default=False,
61
            help="List only users who have not received activation"),
57 62
        )
58 63
    
59 64
    def handle(self, *args, **options):
......
63 68
        users = AstakosUser.objects.all()
64 69
        if options['pending']:
65 70
            users = users.filter(is_active=False)
71
        elif options['pending_send_mail']:
72
            users = users.filter(is_active=False, activation_sent=None)
66 73
        
67 74
        labels = ('id', 'email', 'real name', 'active', 'admin', 'provider', 'groups')
68
        columns = (3, 24, 24, 6, 5, 12,  24)
75
        columns = (3, 24, 24, 6, 5, 12, 24)
69 76
        
70 77
        if not options['csv']:
71 78
            line = ' '.join(l.rjust(w) for l, w in zip(labels, columns))
b/snf-astakos-app/astakos/im/management/commands/sendactivation.py
33 33

  
34 34
from django.core.management.base import BaseCommand, CommandError
35 35

  
36
from astakos.im.functions import send_verification, SendMailError
36
from astakos.im.functions import send_activation, SendMailError
37 37

  
38 38
from ._common import get_user
39 39

  
......
55 55
                continue
56 56
            
57 57
            try:
58
                send_verification(user)
58
                send_activation(user)
59 59
            except SendMailError, e:
60 60
                raise CommandError(e.message)
61 61
            
b/snf-astakos-app/astakos/im/migrations/0010_auto__add_field_astakosuser_activation_sent__chg_field_service_url.py
1
# encoding: utf-8
2
import datetime
3
from south.db import db
4
from south.v2 import SchemaMigration
5
from django.db import models
6

  
7
class Migration(SchemaMigration):
8

  
9
    def forwards(self, orm):
10
        
11
        # Adding field 'AstakosUser.activation_sent'
12
        db.add_column('im_astakosuser', 'activation_sent', self.gf('django.db.models.fields.DateTimeField')(null=True, blank=True), keep_default=False)
13

  
14
        # Changing field 'Service.url'
15
        db.alter_column('im_service', 'url', self.gf('django.db.models.fields.FilePathField')(max_length=100))
16

  
17

  
18
    def backwards(self, orm):
19
        
20
        # Deleting field 'AstakosUser.activation_sent'
21
        db.delete_column('im_astakosuser', 'activation_sent')
22

  
23
        # Changing field 'Service.url'
24
        db.alter_column('im_service', 'url', self.gf('django.db.models.fields.URLField')(max_length=200))
25

  
26

  
27
    models = {
28
        'auth.group': {
29
            'Meta': {'object_name': 'Group'},
30
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
31
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
32
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
33
        },
34
        'auth.permission': {
35
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
36
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
37
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
38
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
39
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
40
        },
41
        'auth.user': {
42
            'Meta': {'object_name': 'User'},
43
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
44
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
45
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
46
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
47
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
48
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
49
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
50
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
51
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
52
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
53
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
54
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
55
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
56
        },
57
        'contenttypes.contenttype': {
58
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
59
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
60
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
61
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
62
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
63
        },
64
        'im.approvalterms': {
65
            'Meta': {'object_name': 'ApprovalTerms'},
66
            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 5, 30, 9, 16, 18, 742353)', 'db_index': 'True'}),
67
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
68
            'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
69
        },
70
        'im.astakosuser': {
71
            'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
72
            'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
73
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
74
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
75
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
76
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
77
            'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
78
            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
79
            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
80
            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
81
            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '100'}),
82
            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
83
            'level': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
84
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
85
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
86
            'updated': ('django.db.models.fields.DateTimeField', [], {}),
87
            'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
88
        },
89
        'im.emailchange': {
90
            'Meta': {'object_name': 'EmailChange'},
91
            'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
92
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
93
            'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
94
            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 5, 30, 9, 16, 18, 743926)'}),
95
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchange_user'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
96
        },
97
        'im.invitation': {
98
            'Meta': {'object_name': 'Invitation'},
99
            'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
100
            'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
101
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
102
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
103
            'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
104
            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
105
            'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
106
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
107
        },
108
        'im.service': {
109
            'Meta': {'object_name': 'Service'},
110
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
111
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
112
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
113
            'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
114
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
115
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
116
            'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
117
        }
118
    }
119

  
120
    complete_apps = ['im']
b/snf-astakos-app/astakos/im/migrations/0011_set_old_activation_sent.py
1
# encoding: utf-8
2
import datetime
3
from south.db import db
4
from south.v2 import DataMigration
5
from django.db import models
6

  
7
class Migration(DataMigration):
8

  
9
    def forwards(self, orm):
10
        # set old users activation date sent to epoch
11
        for u in orm.AstakosUser.objects.all():
12
            u.activation_sent = datetime.datetime.utcfromtimestamp(0)
13
            u.save()
14

  
15
    def backwards(self, orm):
16
        # set old users activation date sent to None
17
        for u in orm.AstakosUser.objects.all():
18
            if u.activation_sent == datetime.datetime.utcfromtimestamp(0):
19
                u.activation_sent = None
20
                u.save()
21

  
22
    models = {
23
        'auth.group': {
24
            'Meta': {'object_name': 'Group'},
25
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
26
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
27
            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
28
        },
29
        'auth.permission': {
30
            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
31
            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
32
            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
33
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
34
            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
35
        },
36
        'auth.user': {
37
            'Meta': {'object_name': 'User'},
38
            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
39
            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
40
            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
41
            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
42
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
43
            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
44
            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
45
            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
46
            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
47
            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
48
            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
49
            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
50
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
51
        },
52
        'contenttypes.contenttype': {
53
            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
54
            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
55
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
56
            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
57
            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
58
        },
59
        'im.approvalterms': {
60
            'Meta': {'object_name': 'ApprovalTerms'},
61
            'date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 5, 30, 9, 25, 25, 741532)', 'db_index': 'True'}),
62
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
63
            'location': ('django.db.models.fields.CharField', [], {'max_length': '255'})
64
        },
65
        'im.astakosuser': {
66
            'Meta': {'object_name': 'AstakosUser', '_ormbases': ['auth.User']},
67
            'activation_sent': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
68
            'affiliation': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
69
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
70
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
71
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
72
            'date_signed_terms': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
73
            'email_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
74
            'has_credits': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
75
            'has_signed_terms': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
76
            'invitations': ('django.db.models.fields.IntegerField', [], {'default': '100'}),
77
            'is_verified': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
78
            'level': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
79
            'provider': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}),
80
            'third_party_identifier': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
81
            'updated': ('django.db.models.fields.DateTimeField', [], {}),
82
            'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['auth.User']", 'unique': 'True', 'primary_key': 'True'})
83
        },
84
        'im.emailchange': {
85
            'Meta': {'object_name': 'EmailChange'},
86
            'activation_key': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '40', 'db_index': 'True'}),
87
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
88
            'new_email_address': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
89
            'requested_at': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime(2012, 5, 30, 9, 25, 25, 743284)'}),
90
            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'emailchange_user'", 'unique': 'True', 'to': "orm['im.AstakosUser']"})
91
        },
92
        'im.invitation': {
93
            'Meta': {'object_name': 'Invitation'},
94
            'code': ('django.db.models.fields.BigIntegerField', [], {'db_index': 'True'}),
95
            'consumed': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
96
            'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
97
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
98
            'inviter': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'invitations_sent'", 'null': 'True', 'to': "orm['im.AstakosUser']"}),
99
            'is_consumed': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
100
            'realname': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
101
            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
102
        },
103
        'im.service': {
104
            'Meta': {'object_name': 'Service'},
105
            'auth_token': ('django.db.models.fields.CharField', [], {'max_length': '32', 'null': 'True', 'blank': 'True'}),
106
            'auth_token_created': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
107
            'auth_token_expires': ('django.db.models.fields.DateTimeField', [], {'null': 'True'}),
108
            'icon': ('django.db.models.fields.FilePathField', [], {'max_length': '100', 'blank': 'True'}),
109
            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
110
            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
111
            'url': ('django.db.models.fields.FilePathField', [], {'max_length': '100'})
112
        }
113
    }
114

  
115
    complete_apps = ['im']
b/snf-astakos-app/astakos/im/models.py
91 91
    has_signed_terms = models.BooleanField('Agree with the terms?', default=False)
92 92
    date_signed_terms = models.DateTimeField('Signed terms date', null=True, blank=True)
93 93
    
94
    activation_sent = models.DateTimeField('Activation sent data', null=True, blank=True)
95
    
94 96
    __has_signed_terms = False
95 97
    __groupnames = []
96 98
    
......
144 146
                self.provider = 'local'
145 147
        report_user_event(self)
146 148
        self.validate_unique_email_isactive()
149
        if self.is_active and self.activation_sent:
150
            # reset the activation sent
151
            self.activation_sent = None
147 152
        super(AstakosUser, self).save(**kwargs)
148 153
        
149 154
        # set group if does not exist

Also available in: Unified diff