Revision a0be6a0c

b/snf-astakos-app/astakos/im/functions.py
128 128
        msg = 'Sent admin notification for user %s' % user.email
129 129
        logger._log(LOGGING_LEVEL, msg, [])
130 130

  
131
def send_helpdesk_notification(user, template_name='im/helpdesk_notification.txt'):
132
    """
133
    Send email to DEFAULT_CONTACT_EMAIL to notify for a new user activation.
134
    
135
    Raises SendNotificationError
136
    """
137
    if not DEFAULT_CONTACT_EMAIL:
138
        return
139
    message = render_to_string(template_name, {
140
            'user': user,
141
            'baseurl': BASEURL,
142
            'site_name': SITENAME,
143
            'support': DEFAULT_ADMIN_EMAIL})
144
    sender = DEFAULT_FROM_EMAIL
145
    try:
146
        send_mail('%s alpha2 testing account notification' % SITENAME, message, sender, [DEFAULT_CONTACT_EMAIL])
147
    except (SMTPException, socket.error) as e:
148
        logger.exception(e)
149
        raise SendNotificationError()
150
    else:
151
        msg = 'Sent helpdesk admin notification for user %s' % user.email
152
        logger._log(LOGGING_LEVEL, msg, [])
153

  
131 154
def send_invitation(invitation, template_name='im/invitation.txt'):
132 155
    """
133 156
    Send invitation email.
......
273 296
    def __init__(self):
274 297
        self.message = _('Failed to send change email')
275 298
        super(ChangeEmailError, self).__init__()
299

  
300
class SendNotificationError(SendMailError):
301
    def __init__(self):
302
        self.message = _('Failed to send notification email')
303
        super(SendNotificationError, self).__init__()
b/snf-astakos-app/astakos/im/templates/im/helpdesk_notification.txt
1
--- A translation in English follows ---
2

  
3
Έχει ενεργοποιηθεί ο παρακάτω λογαριασμός:
4

  
5
Email:          {{user.email}}
6
First name:     {{user.first_name}}
7
Last name:      {{user.last_name}}
8
Is active:      {{user.is_active}}
9
Level:          {{user.level}}
10
Invitations:    {{user.invitations}}
11

  
12
--
13

  
14
The following account has been activated:
15

  
16
Email:          {{user.email}}
17
First name:     {{user.first_name}}
18
Last name:      {{user.last_name}}
19
Is active:      {{user.is_active}}
20
Level:          {{user.level}}
21
Invitations:    {{user.invitations}}
b/snf-astakos-app/astakos/im/views.py
59 59
from astakos.im.util import get_context, prepare_response, set_cookie, get_query
60 60
from astakos.im.forms import *
61 61
from astakos.im.functions import send_greeting, send_feedback, SendMailError, \
62
    invite as invite_func, logout as auth_logout
62
    invite as invite_func, logout as auth_logout, send_helpdesk_notification
63 63
from astakos.im.settings import DEFAULT_CONTACT_EMAIL, DEFAULT_FROM_EMAIL, COOKIE_NAME, COOKIE_DOMAIN, IM_MODULES, SITENAME, LOGOUT_NEXT, LOGGING_LEVEL
64 64

  
65 65
logger = logging.getLogger(__name__)
......
431 431
    return response
432 432

  
433 433
@transaction.commit_manually
434
def activate(request, email_template_name='im/welcome_email.txt', on_failure='im/signup.html'):
434
def activate(request, email_template_name='im/welcome_email.txt', on_failure='im/signup.html', 
435
                helpdesk_email_template_name='im/helpdesk_notification.txt'):
435 436
    """
436 437
    Activates the user identified by the ``auth`` request parameter, sends a welcome email
437 438
    and renews the user token.
......
451 452
        messages.add_message(request, messages.ERROR, message)
452 453
        return render_response(on_failure)
453 454
    
455
    notify_helpdesk = False
454 456
    try:
455 457
        local_user = AstakosUser.objects.get(~Q(id = user.id), email=user.email, is_active=True)
456 458
    except AstakosUser.DoesNotExist:
......
460 462
            user.save()
461 463
        except ValidationError, e:
462 464
            return HttpResponseBadRequest(e)
465
        notify_helpdesk = True
463 466
    else:
464 467
        # switch the existing account to shibboleth one
465 468
        if user.provider == 'shibboleth':
......
474 477
            user = local_user
475 478
        
476 479
    try:
480
        if notify_helpdesk:
481
            send_helpdesk_notification(user, helpdesk_email_template_name)
477 482
        send_greeting(user, email_template_name)
478 483
        response = prepare_response(request, user, next, renew=True)
479 484
        transaction.commit()

Also available in: Unified diff