示例#1
0
    def post(self, request):
        post_data = request.POST
        first_name = post_data.get('firstname')
        last_name = post_data.get('lastname')
        email = post_data.get('email')
        mobile = post_data.get('mobile')
        password = post_data.get('password')

        # validation
        values = {
            'first_name': first_name,
            'last_name': last_name,
            'email': email,
            'mobile': mobile
        }
        error_message = None

        customer = Customer(first_name=first_name,
                            last_name=last_name,
                            email=email,
                            mobile=mobile,
                            password=password)
        error_message = self.validateCustomer(customer)
        # saving user data
        if not error_message:
            # password hashing
            customer.password = make_password(customer.password)
            customer.save()
            return redirect('homepage')

        else:
            data = {'error': error_message, 'value': values}
            return render(request, 'templates/signup.html', data)
示例#2
0
    def post(self, request):
        first_name = request.POST["first_name"]
        last_name = request.POST["last_name"]
        username = request.POST["username"]
        email = request.POST["email"]
        phone = request.POST["phone"]
        password1 = request.POST["password1"]
        password2 = request.POST["password2"]
        data = {}
        data['first_name'] = first_name
        data['last_name'] = last_name
        data['username'] = username
        data['email'] = email
        data['phone'] = phone
        error_message = self.validateCode(data, password1, password2)
        data['error'] = error_message
        if error_message:
            return render(request, 'signup.html', data)

        else:
            user = User.objects.create_user(first_name=first_name,
                                            username=username,
                                            email=email,
                                            password=password1,
                                            last_name=last_name)
            user.save()
            customer = Customer(user=user, phone=phone)
            customer.save()
            return redirect("login")
示例#3
0
    def post(self, request):
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        email = request.POST.get('email')
        phone = request.POST.get('phone')
        address = request.POST.get('address')
        password = request.POST.get('password')

        value = {
            'first_name': first_name,
            'last_name': last_name,
            'email': email,
            'phone': phone,
            'address': address
        }

        error_message = None
        customer = Customer(first_name=first_name,
                            last_name=last_name,
                            email=email,
                            phone=phone,
                            address=address,
                            password=password)
        error_message = self.validateUser(customer, email)

        if (not error_message):
            customer.password = make_password(customer.password)
            customer.save()
            return redirect('home')
        else:
            context = {'error': error_message, 'values': value}
            return render(request, 'store/register.html', context)
示例#4
0
 def post(self, request):
     userData = request.POST
     # validate
     error = self.validateData(userData)
     if error:
         return render(request, 'signup.html', {
             "error": error,
             "userData": userData
         })
     else:
         if Customer.emailExits(userData['email']):
             error["emailExits_error"] = "Email Already Exits"
             return render(request, 'signup.html', {
                 "error": error,
                 "userData": userData
             })
         else:
             customer = Customer(
                 name=userData['name'],
                 email=userData['email'],
                 phone=userData['phone'],
                 password=make_password(userData['password']),
             )
             customer.save()
             return redirect('home')
示例#5
0
 def save(self, commit=True):
     self.instance.is_active = False
     result = super().save(commit)
     name = self.cleaned_data['name']
     email = self.cleaned_data['email']
     customer = Customer(user=result, name=name, email=email)
     if commit:
         customer.save()
     return result
示例#6
0
 def form_valid(self, form):
     customer = Customer(first_name=form.cleaned_data['first_name'],
                         last_name=form.cleaned_data['last_name'],
                         username=form.cleaned_data['username'],
                         email=form.cleaned_data['email'],
                         password=form.cleaned_data['password'])
     customer.save()
     user = User.objects.get(email=customer.email, username=customer.username)
     login(request=self.request, user=user)
     return HttpResponseRedirect(reverse('store:home'))
示例#7
0
文件: views.py 项目: hnejadi/ShopZone
def signup(request):
	global user
	name = request.POST['name']
	password = request.POST['password']
	repassword = request.POST['repassword']
	address = request.POST['address']
	phone = request.POST['phone']
	email = request.POST['email']

	if password != repassword or password == '':
		return render(request, "store/login.html", {'errors':["Invalid password", "Passwords don't match"]})

	customer = Customer(customer_name = name, password = password, address = address, phone = phone, email = email)
	customer.save()
	user = customer
	return HttpResponseRedirect('/shop/')
示例#8
0
    def post(self, request):
        userData = request.POST
        customerEmail = Customer.emailExits(userData["email"])
        if customerEmail:
            # user = authenticate(email=customerEmail, password=userData["password"])
            if userData["password"] == customerEmail.password:
                # if user is not None:
                print("Step 2 passed")
                request.session["customer"] = customerEmail
                # request.session["user"]
                # print(userData["email"])
                if Login.return_url:
                    print("Shuuuu")
                    return HttpResponseRedirect(Login.return_url)
                else:
                    print(Login.return_url)
                    Login.return_url = None
                    return redirect('/')
            else:
                print(customerEmail.customer)
                print(customerEmail.password)
                return render(
                    request, 'registration/login.html', {
                        "userData": userData,
                        "error": "Email or password doesn't match"
                    })
        else:

            return render(request, 'registration/login.html', {
                "userData": userData,
                "error": "Email or password doesn't match"
            })
示例#9
0
    def post(self, request):
        error_message = None
        password = request.POST["password"]
        new_password = request.POST["new_password"]
        confirm_password = request.POST["confirm_password"]
        data = {}
        data['password'] = password
        data['new_password'] = new_password
        data['confirm_password'] = confirm_password
        customer = Customer.get_customer_by_email(request.user.email)
        flag = check_password(password, customer.user.password)
        if not password:
            error_message = "Please enter your original password"
        elif not new_password:
            error_message = "Please enter new password"
        elif not confirm_password:
            error_message = "Please confirm your new password"
        elif not confirm_password == new_password:
            error_message = "Your password and confirm password does not match"
        elif len(new_password) < 8:
            error_message = "The minimum length of password must be 8 characters"
        elif flag:
            request.user.set_password(new_password)
            request.user.save()
            return redirect('logout')
        else:
            error_message = "Please enter correct original password"

        if error_message:
            return render(request, "change_password.html", {
                'error': error_message,
                'data': data
            })
示例#10
0
 def get(self, request):
     customer = Customer.get_customer_by_email(request.user.email)
     cart_size = Cart.get_all_products_by_user(request.user.id)
     return render(request, 'profile.html', {
         'customer': customer,
         'cart_size': len(cart_size)
     })
示例#11
0
    def post(self, request):
        email = request.POST.get('email')
        passwd = request.POST.get('password')
        data = dict()

        customer = Customer.get_customer_email(email)
        # checking if user exists with same email
        if customer != None:
            # checking password
            flag = check_password(passwd, customer.password)
            if flag:
                # setting up session upon succesful log in
                request.session['customer_id'] = customer.id
                request.session['customer_email'] = customer.email
                # if passwords do match
                if Login.return_url:
                    return HttpResponseRedirect(Login.return_url)
                else:
                    Login.return_url = None
                    return redirect('index')
            else:
                data['error_msg'] = 'Wrong usename or password'
        else:
            data['error_msg'] = 'Wrong usename or password'

        data['title'] = 'Login'
        return render(request, 'login.html', data)
示例#12
0
    def post(self, request):
        postdata = request.POST
        first_name = postdata.get('first_name')
        last_name = postdata.get('last_name')
        phone = postdata.get('phone')
        email = postdata.get('email')
        password = postdata.get('password')
        enpassword = make_password(password)

        customer = Customer(first_name=first_name,
                            last_name=last_name,
                            phone=phone,
                            email=email,
                            password=enpassword)
        customer.register()
        return redirect("homepage")
示例#13
0
    def post(self, request):
        userData = request.POST
        print(userData["role"])
        # validate
        error = self.validateData(userData)
        if error:

            return render(request, 'registration/signup.html', {"error": error, "userData": userData})
        else:
            if User.emailExits(userData['email']):
                error["emailExits_error"] = "Email Already Exits"
                return render(request, 'registration/signup.html', {"error": error, "userData": userData})
            else:

                user = User.objects.create_user(
                    username=userData["username"],
                    email=userData["email"],
                    password=userData["password"]
                )
                user.save()
                if userData["role"] == 'Customer':
                    customer = Customer(
                        customer=user,
                        email=userData["email"]
                    )
                    user.is_customer = True
                    user.save()
                    customer.save()
                elif userData["role"] == 'Seller':

                    seller = Seller(
                        seller=user,
                        email=userData["email"]
                    )
                    user.is_seller = True
                    user.save()
                    seller.save()
                elif userData["role"] == 'Seller':
                    deliver = DeliverMan(
                        deliver=user,
                        email=userData["email"]
                    )
                    user.is_deliverman = True
                    user.save()
                    deliver.save()

                return redirect('home')
示例#14
0
def register(request):
    if request.session.get('uid', None):
        return redirect('store:home')

    if request.method == 'POST':
        first_name = request.POST.get('first_name')
        last_name = request.POST.get('last_name')
        phone = request.POST.get('phone_no')
        email = request.POST.get('new_email')
        adress = request.POST.get('address')
        city = request.POST.get('city')
        state = request.POST.get('state')
        country = request.POST.get('country')
        pin_code = request.POST.get('pin_code')
        passwd = request.POST.get('passwd')
        confirmed_passwd = request.POST.get('confirmed_passwd')

        if passwd == confirmed_passwd:
            try:
                user = firebase_auth.create_user_with_email_and_password(
                    email, confirmed_passwd)
            except requests.exceptions.HTTPError:
                return render(request, 'accounts/registration.html',
                              {'message': 'some error occurred'})
            user_id = user['localId']
            customer_details = Customer(user_id=user_id,
                                        first_name=first_name,
                                        last_name=last_name,
                                        phone=phone,
                                        email=email)
            customer_details.save_customer_details()
            customer_id = Customer.objects.get(user_id=user_id)
            customerId = customer_id.id
            shipping_address = ShippingAddress(
                customer=Customer(id=customerId),
                adress=adress,
                city=city,
                state=state,
                counrty=country,
                pin_code=pin_code)
            shipping_address.save_address_details()
            return redirect('accounts:login')
        else:
            return render(request, 'accounts/registration.html',
                          {'message': 'passwords don\'t match'})
    return render(request, 'accounts/registration.html')
示例#15
0
def register(request):
    if request.method == 'POST':

        data = Customer()
        data.fname = request.POST['fname']
        data.lname = request.POST['lname']
        data.email = request.POST['email']
        data.mobile = request.POST['mobile']
        data.password = request.POST['password']
        data.save()
        messages.success(request, "You Are Registered Sucessfully.")

        return redirect('login')
    else:
        return render(request, 'register.html')
示例#16
0
def register(request):
    if request.method == 'POST':
        # eğer post yaratılmış kişi içini doldurmuş ve save demişse yani post metodu request edilmişse, is_valid true dönüyorsa onu db ye kaydeder bilgileri
        form = RegistrationForm(request.POST)
        if form.is_valid():
            # if form data is valid then save it into the database
            form.save()
            username = request.POST['username']
            password = request.POST['password1']
            user = authenticate(request, username=username, password=password)
            name = request.POST['first_name']
            surname = request.POST['last_name']
            email = request.POST['email']

            values = {
                'name': name,
                'surname': surname,
                'email': email,
                'user': user
            }
            error_message = None
            customer = Customer(name=name,
                                surname=surname,
                                email=email,
                                user=user)
            customer.save()

            login(request, user)
            return redirect('store')

    else:
        # eğer post request edilmemişse yani form yaratılmamışsa boş bir form yaratılır burada da. Hem save edilmesi hem de yaratılması için aynı metod kullanılıyor yani
        form = RegistrationForm()

    # context dictionary is created in here and it will contain the name form that contains the value for this form that we've created above here
    # and once we create that this we can pass this in as the third argument in the below return statement
    # so we can actually access the form within our template and this template is register.html within our users dictionary
    context = {'form': form}
    return render(request, 'users/register.html', context)
示例#17
0
def signup(request):
    global user
    name = request.POST['name']
    password = request.POST['password']
    repassword = request.POST['repassword']
    address = request.POST['address']
    phone = request.POST['phone']
    email = request.POST['email']

    if password != repassword or password == '':
        return render(
            request, "store/login.html",
            {'errors': ["Invalid password", "Passwords don't match"]})

    customer = Customer(customer_name=name,
                        password=password,
                        address=address,
                        phone=phone,
                        email=email)
    customer.save()
    user = customer
    return HttpResponseRedirect('/shop/')
示例#18
0
    def post(self, request):
        post_data = request.POST
        first_name = post_data.get('first_name')
        last_name = post_data.get('last_name')
        phone = post_data.get('phone')
        address = post_data.get('address')
        email = post_data.get('email')
        passwd = post_data.get('password')
        conf_passwd = post_data.get('confirm_password')

        data = dict()
        if len(passwd) > 7:
            if passwd == conf_passwd:
                # encrypting password
                passwd = make_password(passwd)
                # creating object of Customer class
                customer = Customer(first_name=first_name,
                                    last_name=last_name,
                                    phone=phone,
                                    address=address,
                                    email=email,
                                    password=passwd)
                # validating customers email and phone
                error_msg = self.validate_customer(customer)

                if error_msg == None:
                    # customer validated and is registered
                    customer.register()
                    return redirect('login')
                else:
                    data['error_msg'] = error_msg
            else:
                data['error_msg'] = 'Passwords dont match !!!'
        else:
            data['error_msg'] = 'Passwords too short !!!'

        data['title'] = 'Sign Up'
        return render(request, 'signup.html', data)
示例#19
0
    def post(self, request):
        PostData = request.POST
        first_name = PostData.get('first_name')
        last_name = PostData.get('last_name')
        email = PostData.get('email')
        password = PostData.get('password')
        value = dict(first_name=first_name, last_name=last_name, email=email)
        error_message = None

        customer = Customer(first_name=first_name,
                            last_name=last_name,
                            email=email,
                            password=password)

        error_message = self.validation_customer(customer)

        if not error_message:
            customer.password = make_password(customer.password)
            customer.register()
            return redirect("index")
        else:
            data = {'error': error_message, 'value': value}
            return render(request, 'signup.html', data)
示例#20
0
    def post(self, request):

        postData = request.POST
        email = postData.get('email')
        fname = postData.get('fname')
        lname = postData.get('lname')
        pwd = postData.get('password')
        phone = postData.get('phone')

        #Validation

        value = {
            'fname': fname,
            'lname': lname,
            'phone': phone,
            'email': email
        }

        err_msg = None
        customer = Customer(first_name=fname,
                            last_name=lname,
                            email=email,
                            password=pwd,
                            phone=phone)

        err_msg = self.validateCustomer(customer)

        #saving
        if not err_msg:
            customer.password = make_password(customer.password)
            customer.register()
            return redirect('homepage')
        else:
            data = {'error': err_msg, 'values': value}
            print("already", err_msg)
            return render(request, 'signup.html', data)
示例#21
0
    def post(self, request):
        email = request.POST.get('email')
        password = request.POST.get('password')
        customer = Customer.get_customer_email(email)
        error_message = None
        if customer:
            flag = check_password(password, customer.password)
            if flag:
                request.session['customer'] = customer.id
                request.session['email'] = customer.email
                return redirect('index')
            else:
                error_message = "Invalid"

        else:
            error_message = "Invalid"
        return render(request, 'login.html', {'error': error_message})
示例#22
0
    def post(self, request):
        context = {}
        email = request.POST.get('email')
        password = request.POST.get('password')

        customer = Customer.get_customer_by_email(email)
        if customer:
            flag = check_password(password, customer.password)
            if flag:
                request.session['customer'] = customer.id
                return redirect('index')
            else:
                error_message = "Invalid Password"
        else:
            error_message = "Invalid Email"

        context['error_message'] = error_message
        return render(request, 'login.html', context)
示例#23
0
    def post(self, request):
        address = request.POST.get('address')
        phone = request.POST.get('phone')
        customer = request.session.get('customer')
        cart = request.session.get('cart')
        products = Product.get_products_by_id(list(cart.keys()))
        print(address, phone, customer, cart, products)

        for product in products:
            print(cart.get(str(product.id)))
            order = Order(customer=Customer(id=customer),
                          product=product,
                          price=product.price,
                          address=address,
                          phone=phone,
                          quantity=cart.get(str(product.id)))
            order.save()
        request.session['cart'] = {}

        return redirect('cart')
示例#24
0
def login(request):
    if request.session.get('uid', None):
        return redirect('store:home')

    if request.method == 'POST':
        email = request.POST.get('email')
        passwd = request.POST.get("pass")
        customer = Customer.get_customerId_by_email(email)
        try:
            user = firebase_auth.sign_in_with_email_and_password(email, passwd)
            session_id = user['idToken']
            request.session['uid'] = str(session_id)
            request.session['customer'] = customer.id
            print(request.session['customer'])

            return redirect('store:home')
        except requests.exceptions.HTTPError:
            error = "Invalid Credentials"
            return render(request, 'accounts/login.html', {'message': error})
    return render(request, 'accounts/login.html')
示例#25
0
    def post(self, request):
        first_name = request.POST["first_name"]
        last_name = request.POST["last_name"]
        username = request.POST["username"]
        phone = request.POST["phone"]
        data = {}
        data['first_name'] = first_name
        data['last_name'] = last_name
        data['username'] = username
        data['phone'] = phone
        customer = Customer.get_customer_by_email(request.user.email)
        error_message = None
        if not first_name:
            error_message = "first name required"
        elif not last_name:
            error_message = "last name required"
        elif not username:
            error_message = "username required"
        elif customer.user.username != username:
            if User.objects.filter(username=username).exists():
                error_message = "Username already taken"

        elif customer.phone != int(phone):
            if Customer.objects.filter(phone=phone).exists():
                error_message = "Account with this phone no already present"
        if error_message:
            return render(request, 'edit_profile.html', {
                'error': error_message,
                'customer': data
            })
        else:
            user = User.objects.filter(username=request.user.username)[0]
            user.first_name = first_name
            user.last_name = last_name
            user.username = username
            user.save(update_fields=['first_name', 'last_name', 'username'])
            customer.phone = phone
            customer.save()
            return redirect('profile')
示例#26
0
    def post(self, request):
        email = request.POST.get('email')
        password = request.POST.get('password')

        customer = Customer.get_customer_by_email(email)
        error_msg = None

        if customer:

            flag = check_password(password, customer.password)
            if flag:
                request.session['customer'] = customer.id
                request.session['email'] = customer.email

                return redirect('homepage')
            else:
                error_msg = "Email or Password Invalid !!"

        else:
            error_msg = 'email or password invalid !!'

        return render(request, 'login.html', {'error': error_msg})
示例#27
0
 def post(self, request):
     userData = request.POST
     customerEmail = Customer.emailExits(userData["email"])
     if customerEmail:
         if check_password(userData["password"], customerEmail.password):
             request.session["customer"] = customerEmail.id
             if Login.return_url:
                 return HttpResponseRedirect(Login.return_url)
             else:
                 Login.return_url = None
                 return redirect('home')
         else:
             return render(
                 request, 'login.html', {
                     "userData": userData,
                     "error": "Email or password doesn't match"
                 })
     else:
         return render(request, 'login.html', {
             "userData": userData,
             "error": "Email or password doesn't match"
         })
示例#28
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'] = customer.id

                if Login.return_url:
                    return HttpResponseRedirect(Login.return_url)
                else:
                    Login.return_url = None
                    return redirect('homepage')
            else:
                error_message = 'Email or Password incorrect'
        else:
            error_message = 'Email or Password incorrect'

        print(email, password)
        return render(request, 'templates/login.html',
                      {'error': error_message})
示例#29
0
    def post(self, request):
        address = request.POST.get('address')
        phone = request.POST.get('phone')
        cart = request.session.get('cart')
        products = Product.getProductById(list(cart.keys()))
        customer = request.session.get('customer')

        for product in products:

            newOrder = Order(
                product=product,
                customer=Customer(id=customer),
                quantity=cart[str(product.id)],
                price=product.price,
                address=address,
                phone=phone,
            )
            newOrder.save()
            print(newOrder.id)

            OrderEmail.delay(order_id=newOrder.id)

        request.session['cart'] = {}
        return redirect('order')
示例#30
0
 def get(self, request):
     customer = Customer.get_customer_by_email(request.user.email)
     return render(request, 'edit_profile.html', {'customer': customer})
示例#31
0
    def create_customers(self):
        Customer(name='Samuel Iseli', email='*****@*****.**').save()

        Customer(name='Nadja Schüepp',
                 email='*****@*****.**').save()