예제 #1
0
def register(request):
    if request.method == 'POST':

        form = RegistrationForm(request.POST)

        if form.is_valid():
            # To Create master collections when first tenant sign up
            tenant = Tenant.objects.all()
            if tenant.count() == 0:
                create_master_db_schema()
            username = form.data['username']
            password = form.data['password1']
            email = form.data['email']
            time = datetime.now().isoformat()
            plain = username + '\0' + time
            token = sha1(plain).hexdigest()
            tenant = Tenant(name=username)
            tenant.save()
            role_access = roleaccess.objects.all()
            access = role_access[0].access
            access.append("Edit User")
            envi1 = roledetail(roletype="Tenant Admin",
                               name="Tenant Admin",
                               policy=[],
                               access=access,
                               tenantid=tenant.id)
            envi1.save()
            envi = User.create_user(username=email.lower(),
                                    email=email,
                                    password=password,
                                    roles=[envi1.id],
                                    key=token,
                                    tenantid=tenant.id,
                                    hp_attr=None)
            envi.save()
            t = loader.get_template("activation_email.txt")
            c = Context({
                'name':
                username,
                'activation_key':
                token,
                'email':
                email,
                'product_url':
                "http://" + request.META["HTTP_HOST"] + "/signup/activate",
            })
            m = Mail(email)
            m.send_mail(t.render(c))
            return HttpResponseRedirect('/signup/success')

    else:
        form = RegistrationForm()
    variables = RequestContext(request, {'form': form})

    return render_to_response(
        'register.html',
        variables,
    )
예제 #2
0
def register(request):
    if request.method == 'POST':
        
        form = RegistrationForm(request.POST)
        
        
        if form.is_valid():
            # To Create master collections when first tenant sign up
            tenant = Tenant.objects.all()
            if tenant.count() == 0:
                create_master_db_schema()
            username=form.data['username']
            password=form.data['password1']
            email=form.data['email']
            time = datetime.now().isoformat()
            plain = username + '\0' + time
            token = sha1(plain).hexdigest()
            tenant = Tenant(name=username)
            tenant.save()
            role_access = roleaccess.objects.all()
            access = role_access[0].access
            access.append("Edit User")
            envi1 = roledetail(roletype = "Tenant Admin",name="Tenant Admin", policy=[], access=access, tenantid=tenant.id)
            envi1.save()
            envi = User.create_user(username=email.lower(),email=email, password=password, roles=[envi1.id], key=token, tenantid=tenant.id,hp_attr = None)
            envi.save()   
            t = loader.get_template("activation_email.txt")
            c = Context({'name': username,
                         'activation_key' : token,
                         'email' : email,
                        'product_url' : "http://" + request.META["HTTP_HOST"] + "/signup/activate",
            })
            m = Mail(email)
            m.send_mail(t.render(c))            
            return HttpResponseRedirect('/signup/success')
          
    else:
        form = RegistrationForm()
    variables = RequestContext(request, {
    'form': form
    })
 
    return render_to_response(
    'register.html',
    variables,
    )
예제 #3
0
 def handle(self, request, context):
     username = context.get('username', None) 
     roles = context.get('role', None)
     email = context.get('email', None)
     password = context.get('password', None)
     try:
         time = datetime.now().isoformat()
         plain = username + '\0' + time
         activation_key = sha1(plain).hexdigest()
         tenant_db = User.create_user(username=username.lower(), password= password, roles = roles,email = email, tenantid=request.user.tenantid,key=activation_key)
         tenant_db.save()
         t = loader.get_template("activation_email.txt")
         c = Context({'name': username,
                      'activation_key' : activation_key,
                      'email' : email,
                     'product_url' : "http://" + request.META["HTTP_HOST"] + "/signup/activate",
         })
         m = Mail(email)
         m.send_mail(t.render(c))
         return True
     except Exception,e:
         messages.error(request,_(e.message))
         LOG.error(e.message)