Beispiel #1
0
def profile_edit(request):
    cart = commerce_views.get_cart(request)
    categories = commerce_views.get_all_categories()
    icon = commerce_views.get_cart_icon()
    profile = models.UserProfile.objects.get_or_create(user=request.user)
    profile = models.UserProfile.objects.get(user=request.user)
    if request.method == 'POST':
        form = forms.UserEdit(request.POST, instance=request.user)
        form1 = forms.ProfileEdit(request.POST, instance=profile)

        if form.is_valid() and form1.is_valid():
            form.save()
            form1.save()
            return redirect('/account/profile/')
        else:
            return redirect('/account/profile/edit/')
    else:
        form = forms.UserEdit(instance=request.user)
        form1 = forms.ProfileEdit(instance=profile)
        args = {
            'form': form,
            'form1': form1,
            'categories': categories,
            'icon': icon,
            'cart': cart
        }
        return render(request, 'account/profile_edit.html', args)
Beispiel #2
0
def profile_view(request):
    cart = commerce_views.get_cart(request)
    categories = commerce_views.get_all_categories()
    icon = commerce_views.get_cart_icon()
    args = {
        'user': request.user,
        'categories': categories,
        'icon': icon,
        'cart': cart
    }
    return render(request, 'account/profile_view.html', args)
Beispiel #3
0
def login(request):
    if request.method == "POST":
        #username = request.POST['username']
        email = request.POST['email']
        password = request.POST['password']
        nextp = request.POST.get('next',None)
        #print nextp
        username = None
        user = None
        cart = get_cart(request)
        if not nextp:
          nextp = '/'
        try:
	  username = User.objects.get(email = email).username
	except:
	  pass
	if not username:
	  try:
	    username = User.objects.get(username = email).username
	  except:
	    pass
	if username:
          user = auth.authenticate(username=username, password=password)
        if user is not None:
            cart2 = get_or_create_cart_by_user(user)
            combine_carts(cart,cart2)
            if user.is_active:
                auth.login(request, user)
                return redirect(nextp)
                # Redirect to a success page.
            else:
                return redirect(nextp)
                #pass
                # Return a 'disabled account' error message
        else:
            return redirect('/accounts/login/?next='+nextp)
            #pass
            # Return an 'invalid login' error message.
    else:
        nextp = request.REQUEST.get('next',None)
        form = account_forms.HRUserCreationForm()
        if request.user.is_authenticated() :
            return redirect('/')
        if nextp:
	  params = {'next' : nextp , 'form' : form, 'mode' : 'login'}
	else:
	  params = {'next' : '/' , 'form' : form , 'mode' : 'login'}
        return  (render_to_response(login_page_html(request),
        params,  
        context_instance = RequestContext(request)))
Beispiel #4
0
def register(request):
    cart = commerce_views.get_cart(request)
    categories = commerce_views.get_all_categories()
    icon = commerce_views.get_cart_icon()
    if request.method == 'POST':
        form = forms.RegistrationForm(request.POST)

        if form.is_valid():
            form.save()
            return redirect('/account/login/')
        else:
            return redirect('/account/register/')
    else:
        form = forms.RegistrationForm()
        args = {
            'form': form,
            'categories': categories,
            'icon': icon,
            'cart': cart
        }
        return render(request, 'account/register.html', args)
Beispiel #5
0
def have_to_login(request):
    cart = commerce_views.get_cart(request)
    categories = commerce_views.get_all_categories()
    icon = commerce_views.get_cart_icon()
    args = {'categories': categories, 'icon': icon, 'cart': cart}
    return render(request, 'account/have_to_login.html', args)