1 # Copyright 2011 GRNET S.A. All rights reserved.
3 # Redistribution and use in source and binary forms, with or
4 # without modification, are permitted provided that the following
7 # 1. Redistributions of source code must retain the above
8 # copyright notice, this list of conditions and the following
11 # 2. Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials
14 # provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 # OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 # AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 # POSSIBILITY OF SUCH DAMAGE.
29 # The views and conclusions contained in the software and
30 # documentation are those of the authors and should not be
31 # interpreted as representing official policies, either expressed
32 # or implied, of GRNET S.A.
34 from astakos.im.forms import InvitedLocalRegisterForm, LocalRegisterForm
35 from astakos.im.models import AstakosUser, Invitation
37 class Backend(object):
38 def get_signup_form(self, request):
39 code = request.GET.get('code', '')
40 formclass = 'LocalRegisterForm'
41 if request.method == 'GET':
44 formclass = 'InvitedLocalRegiterForm'
45 invitation = Invitation.objects.get(code=code)
46 if invitation.is_consumed:
47 return HttpResponseBadRequest('Invitation has beeen used')
48 initial_data.update({'username':invitation.username,
49 'email':invitation.username,
50 'realname':invitation.realname})
51 inviter = AstakosUser.objects.get(username=invitation.inviter)
52 initial_data['inviter'] = inviter.realname
54 initial_data = request.POST
55 return globals()[formclass](initial_data)
57 def is_preaccepted(user, code):
58 invitation = self.invitation
59 if invitation and not invitation.is_consumed and invitation.code == code:
63 def signup(self, request, form):
65 for field in form.fields:
66 if hasattr(AstakosUser(), field):
67 kwargs[field] = form.cleaned_data[field]
68 user = get_or_create_user(**kwargs)
70 code = request.POST.get('code')
71 if is_preaccepted(user, code):
74 message = _('Registration completed. You can now login.')
75 next = request.POST.get('next')
79 message = _('Registration completed. You will receive an email upon your account\'s activation')
81 return status, message