Exemplo n.º 1
0
def registration(request):
    """
    Creates registration form or saves registration info
    """
    
    logout(request)    
    #def save_user_and_login(form):
        #form.save(commit = True)
        #user = authenticate(username = form.cleaned_data['username'], password =  form.cleaned_data['password1'])
        #login(request,  user)
        #ws = Workspace.objects.create_workspace(user.username, '', user)
        #return user

    if request.method == 'POST': 
        form = Registration(request.POST) 

        if form.is_valid():
            #user = save_user_and_login(form)
            user = form.save()
            resp = {'success': True, 'errors': []}
            
            if CONFIRM_REGISTRATION:
                user.is_active = False
                user.save()
                
                url = VerificationUrl.objects.create(user = user).url
                final_url = 'http://%s/confirm_user/%s/'%(SERVER_PUBLIC_ADDRESS , url)
                logger.debug('final_url %s'%final_url)
                send_mail('Registration confirmation', 'Hi %s,\nclick at this url %s \n to confirm your registration at DAM.'%(user.username, final_url), EMAIL_SENDER, [user.email], fail_silently=False)
                resp['confirm_registration'] = True
                
            else:
                user.is_active = True
                user.save()
                user = authenticate(username = form.cleaned_data['username'], password =  form.cleaned_data['password1'])
                login(request,  user)
              
                ws = Workspace.objects.create_workspace(user.username, '', user)
            return HttpResponse(simplejson.dumps(resp))
            

        else:
            from django.template.defaultfilters import striptags
            errors = []
            for field in form:
                if field.errors:
                    errors.append(striptags(field.errors))

            resp = simplejson.dumps({'success': False, 'errors': errors})
            return HttpResponse(resp)
    else:

        form = Registration()

    return render_to_response('registration.html', RequestContext(request,{'form': form }))
Exemplo n.º 2
0
def registration(request):
    """
    Creates registration form or saves registration info
    """
    #from dam.workspace.views import _create_workspace
    from dam.workspace.models import DAMWorkspace as Workspace

    def save_user(form):
        form.save(commit=True)
        user = User.objects.get(username=form.cleaned_data['username'])
        user.is_active = False

        add_ws_permission = Permission.objects.get(codename='add_workspace')
        user.user_permissions.add(add_ws_permission)

        user.save()
        #ws = Workspace(name=user.username)
        #_create_workspace(ws,  user)
        Workspace.objects.create_workspace(user.username, '', user)
        return user

    if request.method == 'POST':
        logger.debug('POST %s' % request.POST)
        form = Registration(request.POST)

        if form.is_valid():
            user = save_user(form)

            resp = simplejson.dumps({'success': True, 'errors': []})

            email = EmailMessage(
                'Registration required',
                'Hi Administrator,\n\nactive this account  %s.' %
                (user.username),
                'NotreDAM <%s>' % EMAIL_SENDER, [EMAIL_ADMIN], [],
                headers={'Reply-To': 'NotreDAM <%s>' % EMAIL_SENDER})
            email.send()
            return HttpResponse(resp)

        else:
            from django.template.defaultfilters import striptags
            errors = []
            for field in form:
                if field.errors:
                    errors.append(striptags(field.errors))

            resp = simplejson.dumps({'success': False, 'errors': errors})
            return HttpResponse(resp)

    return render_to_response('demo_registration.html',
                              RequestContext(request))
Exemplo n.º 3
0
def registration(request):
    """
    Creates registration form or saves registration info
    """
    #from dam.workspace.views import _create_workspace
    from dam.workspace.models import DAMWorkspace as Workspace

    def save_user(form):
        form.save(commit = True)
        user = User.objects.get(username=form.cleaned_data['username'])
        user.is_active = False

        add_ws_permission = Permission.objects.get(codename='add_workspace')
        user.user_permissions.add(add_ws_permission)

        user.save()
        #ws = Workspace(name=user.username)
        #_create_workspace(ws,  user)
        Workspace.objects.create_workspace(user.username, '', user)        
        return user

    if request.method == 'POST': 
        logger.debug('POST %s'%request.POST)
        form = Registration(request.POST) 

        if form.is_valid():
            user = save_user(form)

            resp = simplejson.dumps({'success': True, 'errors': []})
            
            email = EmailMessage('Registration required', 'Hi Administrator,\n\nactive this account  %s.'%(user.username), 'NotreDAM <%s>' % EMAIL_SENDER,
            [EMAIL_ADMIN], [],
            headers = {'Reply-To': 'NotreDAM <%s>' % EMAIL_SENDER})
            email.send()
            return HttpResponse(resp)

        else:
            from django.template.defaultfilters import striptags
            errors = []
            for field in form:
                if field.errors:
                    errors.append(striptags(field.errors))

            resp = simplejson.dumps({'success': False, 'errors': errors})
            return HttpResponse(resp)

    return render_to_response('demo_registration.html', RequestContext(request))
Exemplo n.º 4
0
def registration(request):
    """
    Creates registration form or saves registration info
    """

    logout(request)
    #def save_user_and_login(form):
    #form.save(commit = True)
    #user = authenticate(username = form.cleaned_data['username'], password =  form.cleaned_data['password1'])
    #login(request,  user)
    #ws = Workspace.objects.create_workspace(user.username, '', user)
    #return user

    if request.method == 'POST':
        form = Registration(request.POST)

        if form.is_valid():
            #user = save_user_and_login(form)
            user = form.save()
            resp = {'success': True, 'errors': []}

            if CONFIRM_REGISTRATION:
                user.is_active = False
                user.save()

                url = VerificationUrl.objects.create(user=user).url
                final_url = 'http://%s/confirm_user/%s/' % (
                    SERVER_PUBLIC_ADDRESS, url)
                logger.debug('final_url %s' % final_url)
                send_mail(
                    'Registration confirmation',
                    'Hi %s,\nclick at this url %s \n to confirm your registration at DAM.'
                    % (user.username, final_url),
                    EMAIL_SENDER, [user.email],
                    fail_silently=False)
                resp['confirm_registration'] = True

            else:
                user.is_active = True
                user.save()
                user = authenticate(username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password1'])
                login(request, user)

                ws = Workspace.objects.create_workspace(
                    user.username, '', user)
            return HttpResponse(simplejson.dumps(resp))

        else:
            from django.template.defaultfilters import striptags
            errors = []
            for field in form:
                if field.errors:
                    errors.append(striptags(field.errors))

            resp = simplejson.dumps({'success': False, 'errors': errors})
            return HttpResponse(resp)
    else:

        form = Registration()

    return render_to_response('registration.html',
                              RequestContext(request, {'form': form}))