Ejemplo n.º 1
0
def registration(request):
    form = CrispyUserRegistrationForm(request.POST or None)
    if form.is_valid():
        form.save()
        return redirect("/login")
    context = RequestContext(request)
    context.update({'form': form})
    return render_to_response('registration.djhtml', context_instance=context)
Ejemplo n.º 2
0
def profile(request):
    if WorkerProfile.objects.filter(user=request.user).exists():
        return redirect("/account/")
    context = RequestContext(request)
    form = UserProfileForm(request.POST,user=request.user)
    if form.is_valid():
        form.save()
        return redirect("/account/")
    context.update({'form':form})
    return render_to_response('register.djhtml', context)
Ejemplo n.º 3
0
def overview(request):
    context = RequestContext(request)
    user = request.user
    user_profile = user.get_profile()
    context.update({
        'first_name': user.first_name,
        'last_name': user.last_name,
        'city': user_profile.city,
    })
    return render_to_response('overview.djhtml', context_instance=context)
Ejemplo n.º 4
0
def edit_profile(request):
    user_profile = request.user.get_profile()
    context = RequestContext(request)
    if request.method == 'POST':
        form = CrispyUserProfileForm(request.POST, instance=user_profile)
        if form.is_valid():
            form.save()
            context.update({'submitted': True})
    else:
        form = CrispyUserProfileForm(instance=user_profile)
    context.update({'form': form})
    return render_to_response('edit_profile.djhtml', context_instance=context)
Ejemplo n.º 5
0
def register(request):
    """ Register view function. Show registration form"""
    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/reg_success/")
    else:
        form = MyUserCreationForm()
    templ = loader.get_template("register.html")
    cont = RequestContext(request, {"form": form})
    cont.update(csrf(request))
    return HttpResponse(templ.render(cont))
Ejemplo n.º 6
0
def register(request):
    """ Register view function. Show registration form"""
    if request.method == 'POST':
        form = MyUserCreationForm(request.POST)
        if form.is_valid():
            new_user = form.save()
            return HttpResponseRedirect("/reg_success/")
    else:
        form = MyUserCreationForm()
    templ = loader.get_template("register.html")
    cont = RequestContext(request, {"form":form})
    cont.update(csrf(request))
    return HttpResponse(templ.render(cont))
Ejemplo n.º 7
0
def login(request):
    context = RequestContext(request)
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')

    if request.method == "POST":
        form = CrispyAuthenticationForm(None, request.POST)
        if form.is_valid():
            django_login(request, form.get_user())
            if not is_safe_url(url=redirect_to, host=request.get_host()):
                redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
            return redirect(redirect_to)
    else:
        form = CrispyAuthenticationForm(request)
    context.update({'form': form})
    return render_to_response('login.djhtml', context)
Ejemplo n.º 8
0
def register(request):
    if request.user.is_authenticated():
        redirect("/account/")
    context = RequestContext(request)
    form = UserForm(request.POST or None)
    if form.is_valid():
        user = form.save()
        user = authenticate(username=user.email, password=form.cleaned_data['password'])
        if user is not None:
            if user.is_active:
                print "You provided a correct username and password!"
                login(request, user)
                return redirect('/account/register/profile')
            else:
                print "Your account has been disabled!"
        else:
            print "Your username and password were incorrect."
    context.update({'form':form})
    return render_to_response('register.djhtml', context)
Ejemplo n.º 9
0
def login_form(request):
    """Handle logins"""
    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            usr = authenticate(username=username, password=password)
            if usr is not None:
                if usr.is_active:
                    login(request, usr)
                    return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
        else:
            return HttpResponseRedirect("/register/")
    else:
        form = AuthenticationForm()
        t = loader.get_template("login.html")
        c = RequestContext(request, {'form': form})
        c.update((csrf(request)))
        return HttpResponse(t.render(c))
Ejemplo n.º 10
0
def login_form(request):
    """Handle logins"""
    if request.method == "POST":
        form = AuthenticationForm(data=request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            usr = authenticate(username=username, password=password)
            if usr is not None:
                if usr.is_active:
                    login(request, usr)
                    return HttpResponseRedirect(
                        request.META.get('HTTP_REFERER', '/'))
        else:
            return HttpResponseRedirect("/register/")
    else:
        form = AuthenticationForm()
        t = loader.get_template("login.html")
        c = RequestContext(request, {'form': form})
        c.update((csrf(request)))
        return HttpResponse(t.render(c))
Ejemplo n.º 11
0
def create(request):
    context = RequestContext(request)
    form = CrispyCrowdsourceJobForm()
    context.update({'form': form})
    return render_to_response('create.djhtml', context)