def post(self, request): address = request.POST.get('address') phone = request.POST.get('phone') state = request.POST.get('state') zipcode = request.POST.get('zipcode') customer = request.session.get('customer') cart = request.session.get('cart') product = Product.get_product_by_id(list(cart.keys())) print(address, phone, state, zipcode, customer, cart, product) for product in product: print(cart.get(str(product.id))) order = Order(customer = Customer(id = customer), product = product, price = product.price, address = address, phone = phone, zipcode = zipcode, state = state, quantity = cart.get(str(product.id))) order.save() # after checkout cart clear-------------- request.session['cart'] = {} return redirect('cart')
def post(self, request): email = request.POST.get('email') password = request.POST.get('password') customer = Customer.get_customer_by_email(email) error_message = None if customer: flag = check_password(password, customer.password) if flag: request.session['customer_id'] = customer.id request.session['customer_name'] = customer.customer_name error_message = 'Login Successful !!' messages.success(request, error_message) cart = load_cart_DB_to_session(int(customer.id)) request.session['cart'] = cart if Login.return_url: return HttpResponseRedirect(Login.return_url) else: # Login.return_url = None return redirect('home') else: error_message = 'Email or Password invalid !!' else: error_message = 'Email or Password invalid !!' messages.error(request, error_message) return redirect('login')
def post(self, request): email = request.POST.get('email') customer = Customer.get_customer_by_email(email) if customer: new_password = Signup.random_password(self, 10) customer.password = new_password customer.password = make_password(customer.password) customer.save() email = EmailMessage('New Password', f'Your new password is :"{new_password}" . ', to=[email]) email.send() error_message = "Your password send to your registered email !! " messages.success(request, error_message) return redirect("home") else: error_message = "Please check your email and re-enter your registered email !! " messages.error(request, error_message) return redirect("forget_password")
def post(self, request): password = request.POST.get('curr_pass') new_password1 = request.POST.get('new_pass1') new_password2 = request.POST.get('new_pass2') if password != new_password1: customer = Customer.get_customer_by_id( request.session.get('customer_id')) if check_password(password, customer.password): if new_password1 == new_password2: customer.password = new_password1 customer.password = make_password(customer.password) customer.save() error_message = "Your Password Successfully Changed" messages.success(request, error_message) return redirect('profile') else: error_message = "Your Password Do not match" messages.error(request, error_message) return redirect('change_password') else: error_message = "Password do not match please try again" messages.error(request, error_message) return redirect('change_password') else: error_message = "Old Password and New Password cannot be same" messages.error(request, error_message) return redirect('change_password')
def test_swap_customer_on_login(self): """ Test that when logging in as a User with an existing Customer, that one is set on the request while the anonymous interim customer object is deleted. """ request = self.factory.post('/shop/auth/login/', follow=True) request.user = self.bart old_customer = Customer() old_customer.save() request.session = { 'session_key': 'bart_swap', SESSION_KEY: old_customer.pk, } request.customer = self.bart.customer user_logged_in.send(sender=self.bart.__class__, request=request, user=self.bart) try: Customer.objects.get_customer(request, force_unauth=True) except Customer.DoesNotExist: pass else: self.fail("""Unauthenticated customer should be deleted on login by a User with existing Customer""") self.assertEqual(request.customer, self.bart.customer)
def post(self, request): postData = request.POST first_name = postData.get('firstname') last_name = postData.get('lastname') phone = postData.get('phone') email = postData.get('email') password = postData.get('password') # validation value = { 'first_name': first_name, 'last_name': last_name, 'phone': phone, 'email': email } error_message = None # customer object customer = Customer( first_name=first_name, last_name=last_name, phone=phone, email=email, password=password, ) error_message = self.validateCustomer(customer) if not error_message: print(first_name, last_name, phone, email, password) # password hashing customer.password = make_password(customer.password) customer.register() return render(request, 'login.html') else: data = {'error': error_message, 'values': value} return render(request, 'signup.html', data)
def validate_email(request): if request.method == 'POST': length = card_len(request) # card len category = prod_category(Category, Subcategory) # header drop down postData = request.POST customer_name = postData.get('name') phone = postData.get('phone') email = postData.get('email') password = postData.get('password') otp = postData.get('otp') user_otp = postData.get('user_otp') if otp == user_otp: customer = Customer(customer_name=customer_name, phone=phone, email=email, password=password) customer.password = make_password(customer.password) customer.save() request.session['customer_id'] = customer.id request.session['customer_name'] = customer.customer_name return redirect('home') else: customer = { 'name': customer_name, 'phone': phone, 'email': email, 'password': password, 'otp': otp } error_message = "Invalid OTP" messages.error(request, error_message) return render(request, 'shop/email_verification.html', { 'customer': customer, 'category': category, 'len': length, }) else: return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def test_keep_cart_on_login(self): """ Test that when logging in, an existing cart's Customer reference is set to the new logged-in User's Customer """ request = self.factory.post('/shop/auth/login', follow=True) request.customer = Customer() request.customer.save() request.session = {'session_key': 'keep_cart'} request.user = self.bart old_cart = Cart.objects.get_from_request(request) user_logged_in.send(sender=self.bart.__class__, request=request, user=self.bart) new_cart = Cart.objects.get_from_request(request) self.assertEqual(new_cart.customer, request.customer) self.assertEqual(new_cart, old_cart)
def validateCustomer(self, customer): error_message = None if not customer['name']: error_message = "Name Required !!" elif len(customer['name']) < 4: error_message = 'First Name must be 4 char long or more' elif not customer['phone']: error_message = 'Phone Number required' elif len(customer['phone']) < 10: error_message = 'Phone Number must be 10 char Long' elif customer['password'] != customer['confirmpassword']: error_message = 'Password do not match' elif len(customer['password']) < 6: error_message = 'Password must be 6 char long' elif len(customer['email']) < 5: error_message = 'Email must be 5 char long' elif Customer.isExists(customer['email']): error_message = 'Email Address Already Registered..' return error_message
def post(self, request): email = request.POST.get('email') password = request.POST.get('password') customer = Customer.get_customer_by_email(email) error_message = None if customer: flag = check_password(password, customer.password) if flag: #save customer object without jason request request.session['customer'] = customer.id request.session['email'] = customer.email #end code for save return redirect('shop') else: error_message = 'Email or Password invalid !!' else: error_message = 'Email or Password invalid' print(email, password) return render(request, 'login.html', {'error': error_message})
def test_associate_customer_on_login(self): """ Test that when logging in as a user without existing customer account, the anonymous interim customer object is associated with the logged-in user. """ request = self.factory.post('/shop/auth/login/', follow=True) request.user = self.lisa customer = Customer() customer.save() request.session = { 'session_key': 'lisa_swap', SESSION_KEY: customer.pk, } request.customer = Customer.objects.get_customer(request) user_logged_in.send(sender=self.lisa.__class__, request=request, user=self.lisa) self.assertEqual(request.customer, customer) self.assertEqual(request.customer.user, self.lisa)
def post(self, request): name = request.POST.get('name') email = request.POST.get('email') country = request.POST.get('country') state = request.POST.get('state') address1 = request.POST.get('address1') address2 = request.POST.get('address2') city = request.POST.get('city') postal_code = request.POST.get('zip_code') phone = request.POST.get('phone') user_address = Billing.get_bill_address_by_id( request.session.get("customer_id")) if not user_address: billing_address = Billing(user=Customer( request.session.get('customer_id')), name=name, email=email, country=country, state=state, address1=address1, address2=address2, city=city, zip_code=postal_code, phone=phone) billing_address.save() else: user_address.name = name user_address.email = email user_address.country = country user_address.state = state user_address.address1 = address1 user_address.address2 = address2 user_address.city = city user_address.zip_code = postal_code user_address.phone = phone user_address.save() return redirect('profile')
def post(self, request, **kwargs): customer = request.session.get('customer_id') order_id = request.POST.get('order_id') reason = request.POST.get('reason') order = get_object_or_404(Orders, order_id=int(order_id)) product = get_object_or_404(Product, id=order.product.id) cancel = Cancel_order(customer=Customer(id=int(customer)), order=Orders(order_id=order.order_id), reason=reason) cancel.save() order.status = "CAN" order.order_delevered_date = datetime.now() order.register() # increase prod stock ord_stock = int(order.quantity) prod_stock = int(product.stock) product.stock = ord_stock + prod_stock product.save() error_message = 'Order successfully cancelled' messages.success(request, error_message) return redirect('profile')
def post(self , request): len_cart = card_len(request) # card len category = prod_category(Category, Subcategory) cart = request.session.get('cart') product = [] for id, value in cart.items(): product.append(id) product.append(value) ids = list(request.session.get('cart').keys()) if ids: products = Product.get_products_by_id(ids) name = request.POST.get('name') email = request.POST.get('email') country = request.POST.get('country') state = request.POST.get('state') address1 = request.POST.get('address1') address2 = request.POST.get('address2') city = request.POST.get('city') postal_code = request.POST.get('postal_code') phone = request.POST.get('phone') totalprice = int(request.POST.get('total_price')) user_address = Billing.get_bill_address_by_id(request.session.get("customer_id")) # save user billing address if not user_address: billing_address = Billing(user = Customer(request.session.get('customer_id')),name=name, email=email, country=country, state=state, address1=address1, address2=address2, city=city, zip_code=postal_code, phone=phone) billing_address.save() param = {'name': name, 'email': email, 'country': country, 'state': state, 'address': address1 + " " + address2, 'city': city, 'postal_code': postal_code,'phone': phone, 'total_price': totalprice} products = Product.get_products_by_id(list(cart.keys())) order_id ="" for product in products: order = Orders( customer =Customer(id=request.session.get('customer_id')), product= product,color =cart.get(str(product.id))[1], quantity=cart.get(str(product.id))[0], price=get_price(product,cart.get(str(product.id))[0]), name=name, email=email, country=country, state=state, address=address1+" "+address2, city=city, zip_code=postal_code, phone=phone) order.save() order_id += str(order.order_id) param_dict = { 'MID': 'lieNmi15357207091028', 'ORDER_ID': 'ODR-31', 'TXN_AMOUNT': '100.00', 'CUST_ID': name, 'INDUSTRY_TYPE_ID': 'Retail', 'WEBSITE': 'WEBSTAGING', 'CHANNEL_ID': 'WEB', 'CALLBACK_URL': 'http://ashudihatti.in/handlerequest/', } chucksum = Checksum.generate_checksum(param_dict, MERCHANT_KEY) param_dict['CHECKSUMHASH']= chucksum return render(request, 'shop/payment.html', {'param_dict': param_dict})