Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / management / commands / user-send-activation.py @ 6bdf0aa3

History | View | Annotate | Download (2.5 kB)

1 ca96a346 Giorgos Verigakis
# Copyright 2012 GRNET S.A. All rights reserved.
2 df48dd1b Giorgos Verigakis
#
3 df48dd1b Giorgos Verigakis
# Redistribution and use in source and binary forms, with or
4 df48dd1b Giorgos Verigakis
# without modification, are permitted provided that the following
5 df48dd1b Giorgos Verigakis
# conditions are met:
6 df48dd1b Giorgos Verigakis
#
7 df48dd1b Giorgos Verigakis
#   1. Redistributions of source code must retain the above
8 df48dd1b Giorgos Verigakis
#      copyright notice, this list of conditions and the following
9 df48dd1b Giorgos Verigakis
#      disclaimer.
10 df48dd1b Giorgos Verigakis
#
11 df48dd1b Giorgos Verigakis
#   2. Redistributions in binary form must reproduce the above
12 df48dd1b Giorgos Verigakis
#      copyright notice, this list of conditions and the following
13 df48dd1b Giorgos Verigakis
#      disclaimer in the documentation and/or other materials
14 df48dd1b Giorgos Verigakis
#      provided with the distribution.
15 df48dd1b Giorgos Verigakis
#
16 df48dd1b Giorgos Verigakis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 df48dd1b Giorgos Verigakis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 df48dd1b Giorgos Verigakis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 df48dd1b Giorgos Verigakis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 df48dd1b Giorgos Verigakis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 df48dd1b Giorgos Verigakis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 df48dd1b Giorgos Verigakis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 df48dd1b Giorgos Verigakis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 df48dd1b Giorgos Verigakis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 df48dd1b Giorgos Verigakis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 df48dd1b Giorgos Verigakis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 df48dd1b Giorgos Verigakis
# POSSIBILITY OF SUCH DAMAGE.
28 df48dd1b Giorgos Verigakis
#
29 df48dd1b Giorgos Verigakis
# The views and conclusions contained in the software and
30 df48dd1b Giorgos Verigakis
# documentation are those of the authors and should not be
31 df48dd1b Giorgos Verigakis
# interpreted as representing official policies, either expressed
32 df48dd1b Giorgos Verigakis
# or implied, of GRNET S.A.
33 df48dd1b Giorgos Verigakis
34 df48dd1b Giorgos Verigakis
from django.core.management.base import BaseCommand, CommandError
35 df48dd1b Giorgos Verigakis
36 751d24cf Sofia Papagiannaki
from astakos.im.functions import send_activation, SendMailError
37 397d5cbe Giorgos Verigakis
38 397d5cbe Giorgos Verigakis
from ._common import get_user
39 df48dd1b Giorgos Verigakis
40 5ce3ce4f Sofia Papagiannaki
41 df48dd1b Giorgos Verigakis
class Command(BaseCommand):
42 ebd369d0 Sofia Papagiannaki
    args = "<user ID or email> [user ID or email] ..."
43 683cf244 Sofia Papagiannaki
    help = "Sends an activation email to one or more users"
44 5ce3ce4f Sofia Papagiannaki
45 df48dd1b Giorgos Verigakis
    def handle(self, *args, **options):
46 df48dd1b Giorgos Verigakis
        if not args:
47 df48dd1b Giorgos Verigakis
            raise CommandError("No user was given")
48 5ce3ce4f Sofia Papagiannaki
49 df48dd1b Giorgos Verigakis
        for email_or_id in args:
50 0a569195 Sofia Papagiannaki
            user = get_user(email_or_id, is_active=False)
51 397d5cbe Giorgos Verigakis
            if not user:
52 e939cf3d Sofia Papagiannaki
                self.stderr.write("Unknown user '%s'\n" % (email_or_id,))
53 e939cf3d Sofia Papagiannaki
                continue
54 e939cf3d Sofia Papagiannaki
            if user.is_active:
55 5ce3ce4f Sofia Papagiannaki
                self.stderr.write(
56 5ce3ce4f Sofia Papagiannaki
                    "Already active user '%s'\n" % (email_or_id,))
57 df48dd1b Giorgos Verigakis
                continue
58 5ce3ce4f Sofia Papagiannaki
59 18ffbee1 Sofia Papagiannaki
            try:
60 751d24cf Sofia Papagiannaki
                send_activation(user)
61 18ffbee1 Sofia Papagiannaki
            except SendMailError, e:
62 18ffbee1 Sofia Papagiannaki
                raise CommandError(e.message)
63 5ce3ce4f Sofia Papagiannaki
64 5ce3ce4f Sofia Papagiannaki
            self.stdout.write("Activation sent to '%s'\n" % (user.email,))