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)))
def combinecarts(request): try: cart = get_cart_by_request_cartkey(request) except: return redirect('/') try: nextp = request.session['nextp'] except: nextp = '/' user = request.user if user is not None: cart2 = get_or_create_cart_by_user(user) combine_carts(cart,cart2) return redirect(nextp)
def change_password_by_new_social_user(request): password = request.REQUEST.get("password",None) cart = None try: cart = get_cart_by_request_cartkey(request) except: pass try: nextp = request.session['nextp'] except: nextp = '/' user = request.user if user is not None and cart is not None: cart2 = get_or_create_cart_by_user(user) combine_carts(cart,cart2) if password and len(password)>1: u = request.user u.set_password(password) u.save() return render_to_response(setup_new_passwd(request), {'phase' : 'ok', 'social' : True, 'nextp' : nextp } , context_instance = RequestContext(request)) else: return render_to_response(setup_new_passwd(request), {'phase' : 'badpasswd', 'social' : True, 'nextp' : nextp } , context_instance = RequestContext(request))
def change_password(request): password = request.REQUEST.get("password",None) try: cart = get_cart_by_request_cartkey(request) except: return redirect('/') try: nextp = request.session['nextp'] except: nextp = '/' user = request.user if user is not None: cart2 = get_or_create_cart_by_user(user) combine_carts(cart,cart2) if password and len(password)>1: u = request.user u.set_password(password) u.save() if nextp != '/': return redirect(nextp) return render_to_response(setup_new_passwd(request), {'phase' : 'ok' } , context_instance = RequestContext(request)) else: return render_to_response(setup_new_passwd(request), {'phase' : 'badpasswd' } , context_instance = RequestContext(request))