Esempio n. 1
0
    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")
Esempio n. 2
0
    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')
Esempio n. 3
0
    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})