Esempio n. 1
0
def changeProxy(prfl):
    if prfl.type == profile.direct:
        for m in modules:
            m.noProxy()
    elif prfl.type == profile.globl:
        for m in modules:
            m.setGlobalProxy(prfl.globl_host, prfl.globl_port, prfl.user, prfl.pasw)
    elif prfl.type == profile.indiv:
        for m in modules:
            if prfl.has_http:
                m.setHTTPProxy(prfl.http_host, prfl.http_port, prfl.user, prfl.pasw)
            if prfl.has_ftp:
                m.setFTPProxy(prfl.ftp_host, prfl.ftp_port, prfl.user, prfl.pasw)
            if prfl.has_ssl:
                m.setSSLProxy(prfl.ssl_host, prfl.ssl_port, prfl.user, prfl.pasw)
            if prfl.has_socks:
                m.setSOCKSProxy(prfl.socks_host, prfl.socks_port, prfl.user, prfl.pasw)
    elif prfl.type == profile.auto:
        for m in modules:
            m.setPAC_URL(prfl.auto_url)
    # apply the changes
    for m in modules:
        m.close()
        
    for p in profiles:
        p.isActive = False
    prfl.isActive = True
    
    profile.save()
Esempio n. 2
0
def register(request):
    registered = False
    if request.method == 'POST':
        form_user = UserForm(data=request.POST)
        form_por = UserProfileInfoForm(data=request.POST)
        if form_user.is_valid() and form_por.is_valid():
            user = form_user.save(commit=False)
            user.set_password(user.password)
            user.save()

            profile = form_por.save(commit=False)
            profile.user = user

            if 'picture' in request.FILES:
                profile.picture = request.FILES['picture']

            profile.save()

            registered = True

        else:
            print(form_user.error, form_por.error)
    else:
        form_user = UserForm()
        form_por = UserProfileInfoForm()

    return render(request, 'mystore/registration.html', \
                  context={'user_form': form_user, \
                             'profile_form': form_por, \
                             'registered': registered})
Esempio n. 3
0
def register(request):
    registered = False

    if request.method == 'POST':
        user_form = UserForm(request.POST)
        profile_form = UserProfileForm(request.POST)

        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save()

            user.set_password(user.password)
            user.save()

            profile = profile_form.save(commit=False)
            profile.user = user
            profile.username = user.username

            profile.save()
            registered = True
        else:
            print(user_form.errors, profile_form.errors)
    else:
        user_form = UserForm()
        profile_form = UserProfileForm()

    return render(request,
                  'food/register.html',
                  context={
                      'user_form': user_form,
                      'profile_form': profile_form,
                      'registered': registered
                  })
Esempio n. 4
0
def changeProxy(prfl):
    if prfl.type == profile.direct:
        for m in modules:
            m.noProxy()
    elif prfl.type == profile.globl:
        for m in modules:
            m.setGlobalProxy(prfl.globl_host, prfl.globl_port, prfl.user,
                             prfl.pasw)
    elif prfl.type == profile.indiv:
        for m in modules:
            if prfl.has_http:
                m.setHTTPProxy(prfl.http_host, prfl.http_port, prfl.user,
                               prfl.pasw)
            if prfl.has_ftp:
                m.setFTPProxy(prfl.ftp_host, prfl.ftp_port, prfl.user,
                              prfl.pasw)
            if prfl.has_ssl:
                m.setSSLProxy(prfl.ssl_host, prfl.ssl_port, prfl.user,
                              prfl.pasw)
            if prfl.has_socks:
                m.setSOCKSProxy(prfl.socks_host, prfl.socks_port, prfl.user,
                                prfl.pasw)
    elif prfl.type == profile.auto:
        for m in modules:
            m.setPAC_URL(prfl.auto_url)
    # apply the changes
    for m in modules:
        m.close()

    for p in profiles:
        p.isActive = False
    prfl.isActive = True

    profile.save()
Esempio n. 5
0
    def slotApply(self):
        name = unicode(self.name_edit.text())
        ok = self.validate()

        # to save the 'user' and 'pasw' first save temporarily
        user = self.prfl.user
        pasw = self.prfl.pasw

        if not ok:
            return
        self.prfl.changeName(name)

        # then save them to prfl itself
        self.prfl.user = user
        self.prfl.pasw = pasw

        if self.rd1.isChecked():
            self.prfl.type = profile.globl
            self.prfl.globl_host = unicode(self.globl_host.text())
            self.prfl.globl_port = unicode(self.globl_port.text())
            self.prfl.comment = profile.comment_globl + " " + self.prfl.globl_host
        elif self.rd2.isChecked():
            self.prfl.type = profile.indiv
            self.prfl.comment = i18n("Protocols: ")
            if self.ch1.isChecked():
                self.has_http = True
                self.prfl.http_host = unicode(self.http_host.text())
                self.prfl.http_port = unicode(self.http_port.text())
                self.prfl.comment += " " + profile.comment_http + ":" + self.prfl.http_host
            if self.ch2.isChecked():
                self.has_ftp = True
                self.prfl.ftp_host = unicode(self.ftp_host.text())
                self.prfl.ftp_port = unicode(self.ftp_port.text())
                self.prfl.comment += " " + profile.comment_ftp + ":" + self.prfl.ftp_host
            if self.ch4.isChecked():
                self.has_ssl = True
                self.prfl.ssl_host = unicode(self.ssl_host.text())
                self.prfl.ssl_port = unicode(self.ssl_port.text())
                self.prfl.comment += " " + profile.comment_ssl + ":" + self.prfl.ssl_host
            if self.ch5.isChecked():
                self.has_socks = True
                self.prfl.socks_host = unicode(self.socks_host.text())
                self.prfl.socks_port = unicode(self.socks_port.text())
                self.prfl.comment += " " + profile.comment_socks + ":" + self.prfl.socks_host
        else:
            self.prfl.type = profile.auto
            self.prfl.auto_url = unicode(self.auto_url.text())
            self.prfl.comment = profile.comment_auto
        self.prfl.save()
        if self.new:
            self.parent().add(self.prfl)
        profile.save()
        if self.prfl_item:
            self.prfl_item.repaint()
        if self.prfl.isActive:
            changeProxy(self.prfl)
        self.close()
Esempio n. 6
0
 def slotApply(self):
     name = unicode(self.name_edit.text())
     ok = self.validate()
     
     # to save the 'user' and 'pasw' first save temporarily
     user = self.prfl.user
     pasw = self.prfl.pasw
     
     if not ok:
         return
     self.prfl.changeName(name)
     
     # then save them to prfl itself
     self.prfl.user = user
     self.prfl.pasw = pasw
     
     if self.rd1.isChecked():
         self.prfl.type = profile.globl
         self.prfl.globl_host = unicode(self.globl_host.text())
         self.prfl.globl_port = unicode(self.globl_port.text())
         self.prfl.comment = profile.comment_globl + " " + self.prfl.globl_host
     elif self.rd2.isChecked():
         self.prfl.type = profile.indiv
         self.prfl.comment = i18n("Protocols: ")
         if self.ch1.isChecked():
             self.has_http = True
             self.prfl.http_host = unicode(self.http_host.text())
             self.prfl.http_port = unicode(self.http_port.text())
             self.prfl.comment += " " + profile.comment_http + ":" + self.prfl.http_host
         if self.ch2.isChecked():
             self.has_ftp = True
             self.prfl.ftp_host = unicode(self.ftp_host.text())
             self.prfl.ftp_port = unicode(self.ftp_port.text())
             self.prfl.comment += " " + profile.comment_ftp + ":" + self.prfl.ftp_host
         if self.ch4.isChecked():
             self.has_ssl = True
             self.prfl.ssl_host = unicode(self.ssl_host.text())
             self.prfl.ssl_port = unicode(self.ssl_port.text())
             self.prfl.comment += " " + profile.comment_ssl + ":" + self.prfl.ssl_host
         if self.ch5.isChecked():
             self.has_socks = True
             self.prfl.socks_host = unicode(self.socks_host.text())
             self.prfl.socks_port = unicode(self.socks_port.text())
             self.prfl.comment += " " + profile.comment_socks + ":" + self.prfl.socks_host
     else:
         self.prfl.type = profile.auto
         self.prfl.auto_url = unicode(self.auto_url.text())
         self.prfl.comment = profile.comment_auto
     self.prfl.save()
     if self.new:
         self.parent().add(self.prfl)
     profile.save()
     if self.prfl_item:
         self.prfl_item.repaint()
     if self.prfl.isActive:
         changeProxy(self.prfl)
     self.close()
Esempio n. 7
0
 def run(self):
     while 1:
         item = self.rdb.lpop(self.RDB_SAVE)
         if item is None:
             sleep = 0.01
             #logging.info('%r get None, sleep %s', self.getName(), sleep)
             time.sleep(sleep)
             continue
         try:
             info = marshal.loads(item)
             urltype, url, headers, content = info['urltype'], info['url'], info['headers'], info['content']
             logging.info('begin save type=%r, url=%r', urltype, url)
             profile.save(urltype, url, headers, content)
             logging.info('end save type=%r, url=%r', urltype, url)
         except Exception, e:
             logging.exception('Error: %s', e)
Esempio n. 8
0
def create_profile(request):
    if request.POST:
        form = ProfileForm(request.POST)
        if form.is_valid():
            profile = form.save(commit=False)
            profile.save()
            request.user.profile = profile
            request.user.save()
            return redirect('profile-view', profile_id=profile.id)
    else:
        form = ProfileForm()
    return render(
        request, 'forms/base-form.html', {
            "form": form,
            "form_title": "Create Profile",
            "form_action": "Create Profile"
        })
def register(request): 
    user_form = forms.UserForm
    profile_form =  forms.UserProfileInfoForm
    
    registered = False
    if request.method == "POST":
        
        user_form = forms.UserForm(data=request.POST)
        profile_form = forms.UserProfileInfoForm(data=request.POST)
        
        if user_form.is_valid() and profile_form.is_valid():
            
            #save user to database
            user = user_form.save()
            
            #Hash the password
            user.set_password(user.password)
            
            #Update user with hashed password
            user.save()
            
            #can't commit because we still need to edit profile
            profile = profile_form.save(commit=False)
            
            #check if profile pic provided
            if 'picture' in request.FILES:
                print("Found the picture")
                profile.picture = request.FILES['picture']
            
            profile.user = user
            profile.save()
            
            registered = True
        else:
            print("Form not valid")
    
    else:
        print("Not valid request")
    
    context = {"user_form": user_form, 'profile_form': profile_form, 'registered': registered}
       
    return render(request, 'registration.html', context)
Esempio n. 10
0
def order_page(request, product_id):
    try:
        profile = Profile.objects.get(user=request.user)
        product = Products.objects.get(id=product_id)
        total_price = 0
        discount_price = 0
        sale_amount = profile.sale_amount * 0.005
        form = OrderForm(initial={'product': product, 'user': request.user})
        if request.method == 'POST':
            form = OrderForm(request.POST)
            if form.is_valid():
                if 20 < profile.order_count < 40:
                    profile.sale_amount = 0.1
                    total_price = (product.price -
                                   product.price * profile.sale_amount
                                   ) * form.cleaned_data['quantity']
                elif 40 < profile.order_count < 60:
                    profile.sale_amount = 0.2
                    total_price = (product.price -
                                   product.price * profile.sale_amount
                                   ) * form.cleaned_data['quantity']
                if form.cleaned_data['payment_method'] == 'wallet':
                    if profile.wallet >= total_price:
                        profile.wallet -= total_price
                        return HttpResponse('sps za pokupku')
                    else:
                        return HttpResponse('not enough munny')
                else:
                    profile.order_count += 1
                    profile.save()
                form.save()

        return render(
            request, 'products/order.html', {
                'form': form,
                'total_price': total_price,
                'discount_price': discount_price
            })
    except Products.DoesNotExist:
        return HttpResponse('Not found!')
Esempio n. 11
0
def profile_handle(request):
    print(request.user)
    form = ProfileForm(request.POST)
    user = request.user
    user.profile.testy()
    if form.is_valid():
        # profile_pic = form.cleaned_data['profile_pic']
        # birth_date = form.cleaned_data['birth_date']
        mobile_number = form.cleaned_data['mobile_number']
        address = form.cleaned_data['address']
        country = form.cleaned_data['country']
        user.first_name = form.cleaned_data['first_name']
        user.last_name = form.cleaned_data['last_name']
        user.save()
        profile = user.profile
        profile.mobile_number = mobile_number
        profile.address = address
        profile.save()
        return redirect("/profile")
    else:
        print(form.errors)
        messages.error(request, '  Not a valid ')
        return redirect('/')