Esempio n. 1
0
 def post(self, request, *args, **kwargs):
     if request.POST.get("credit"):
         credit, bonus = add_credit(self.user,
                                    float(request.POST.get("credit")))
         message = Message.objects.filter(purpose="add_credit")
         if message:
             message[0].send(
                 config.email, {
                     "user": self.user.username,
                     "credit": float(request.POST.get("credit")),
                     "bonus": float(request.POST.get("credit")) *
                     (bonus - 1.0)
                 })
         messages.add_message(
             request, messages.SUCCESS,
             _('Credits will been added on your account after you pay them')
         )
         return HttpResponseRedirect(
             reverse("payment_info", kwargs={"pk": credit.id}))
     if request.POST.get("what_to_do"):
         self.user.parms.low_level_credits = request.POST.get("what_to_do")
         self.user.parms.save()
         messages.add_message(request, messages.SUCCESS,
                              _('Low level behavior has been setted'))
     return HttpResponseRedirect(reverse("credit"))
Esempio n. 2
0
 def post(self, request, *args, **kwargs):
     if request.POST.get("credit"):
         credit, bonus = add_credit(self.user, float(request.POST.get("credit")))
         message = Message.objects.filter(purpose="add_credit")
         if message:
             message[0].send(config.email, {"user": self.user.username, "credit": float(request.POST.get("credit")), "bonus": float(request.POST.get("credit")) * (bonus - 1.0)})
         messages.add_message(request, messages.SUCCESS, _('Credits will been added on your account after you pay them'))
         return HttpResponseRedirect(reverse("payment_info", kwargs={"pk": credit.id}))
     if request.POST.get("what_to_do"):
         self.user.parms.low_level_credits = request.POST.get("what_to_do")
         self.user.parms.save()
         messages.add_message(request, messages.SUCCESS, _('Low level behavior has been setted'))
     return HttpResponseRedirect(reverse("credit"))
Esempio n. 3
0
def install(request, uid):
    superuser = request.user
    u = request.session.get('switched_user', request.user)
    if not superuser.is_superuser:
        return HttpResponseForbidden(_("Permission error"))

    iuser = get_object_or_404(u, id=uid)
    if not iuser.username or ";" in iuser.username:
        return HttpResponseForbidden("Wrong username")

    # System user
    HOME = join("/home", iuser.username)

    #sr = SystemRequest(u, iuser.parms.web_machine)
    #sr.install(iuser)
    #sr.commit()

    #line = sr.run("cat /etc/passwd |grep ^%s:" % iuser.username, instant=True)[0].strip()
    #user, foo, uid, gid, bar = line.split(":", 4)

    #iuser.parms.home = HOME
    #iuser.parms.uid = uid
    #iuser.parms.gid = gid
    #iuser.parms.save()

    add_credit(iuser, 30, free=True)

    iuser.is_active = True
    iuser.save()

    message = Message.objects.filter(purpose="approved_reg")
    if message:
        message[0].send(iuser.email)

    messages.add_message(request, messages.SUCCESS,
                         _('User has been installed'))
    return HttpResponseRedirect(reverse("wsgiadmin.useradmin.views.ok"))
Esempio n. 4
0
def install(request, uid):
    superuser = request.user
    u = request.session.get('switched_user', request.user)
    if not superuser.is_superuser:
        return HttpResponseForbidden(_("Permission error"))

    iuser = get_object_or_404(u, id=uid)
    if not iuser.username or ";" in iuser.username:
        return HttpResponseForbidden("Wrong username")

    # System user
    HOME = join("/home", iuser.username)

    #sr = SystemRequest(u, iuser.parms.web_machine)
    #sr.install(iuser)
    #sr.commit()

    #line = sr.run("cat /etc/passwd |grep ^%s:" % iuser.username, instant=True)[0].strip()
    #user, foo, uid, gid, bar = line.split(":", 4)

    #iuser.parms.home = HOME
    #iuser.parms.uid = uid
    #iuser.parms.gid = gid
    #iuser.parms.save()

    add_credit(iuser, 30, free=True)

    iuser.is_active = True
    iuser.save()

    message = Message.objects.filter(purpose="approved_reg")
    if message:
        message[0].send(iuser.email)

    messages.add_message(request, messages.SUCCESS, _('User has been installed'))
    return HttpResponseRedirect(reverse("wsgiadmin.useradmin.views.ok"))
Esempio n. 5
0
    def remind_user(self, user, parms):
        correction = 0.0
        if parms.credit < 0:
            correction += abs(parms.credit)

        tmpl, data = None, None

        if parms.low_level_credits == "send_email" or parms.num_reminds > 0:
            tmpl = "low_credit"
            data = {"credit": parms.credit, "days": parms.days_left}
        elif parms.low_level_credits == "buy_month":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 30 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_three_months":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 90 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_six_months":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 180 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_year":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 360 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"

        if tmpl and data:
            message = Message.objects.filter(purpose=tmpl)
            if message:
                message[0].send(user.email, data)
                sys.stdout.write("%s reminded\n" % user.username)
        parms.last_notification = datetime.date.today()
        parms.num_reminds += 1
        parms.save()
Esempio n. 6
0
    def post(self, request, *args, **kwargs):
        right_format = False
        try:
            if request.POST.get("credit"):
                float(request.POST.get("credit"))
                right_format = True
        except UnicodeEncodeError:
            messages.add_message(request, messages.ERROR,
                                 _('Put number into form below.'))

        if right_format and float(request.POST.get("credit")) < 50:
            messages.add_message(request, messages.ERROR,
                                 _('Minimum value is 50 credits'))
        elif right_format:
            if request.POST.get("credit"):
                credit = add_credit(self.user,
                                    float(request.POST.get("credit")))
                message = Message.objects.filter(purpose="add_credit")
                if message:
                    message[0].send(
                        config.email, {
                            "user": self.user.username,
                            "credit": float(request.POST.get("credit")),
                            "bonus": float(request.POST.get("credit"))
                        })
                messages.add_message(
                    request, messages.SUCCESS,
                    _('Credits will been added on your account after payment'))
                return HttpResponseRedirect(
                    reverse("payment_info", kwargs={"pk": credit.id}))
        if request.POST.get("what_to_do"):
            self.user.parms.low_level_credits = request.POST.get("what_to_do")
            self.user.parms.save()
            messages.add_message(request, messages.SUCCESS,
                                 _('Low level behavior has been setted'))
        return HttpResponseRedirect(reverse("credit"))
Esempio n. 7
0
File: views.py Progetto: a740122/pcp
    def post(self, request, *args, **kwargs):
        right_format = False
        try:
            if request.POST.get("credit"):
                float(request.POST.get("credit"))
                right_format = True
        except UnicodeEncodeError:
            messages.add_message(request, messages.ERROR, _('Put number into form below.'))

        if right_format and float(request.POST.get("credit")) < 50:
            messages.add_message(request, messages.ERROR, _('Minimum value is 50 credits'))
        elif right_format:
            if request.POST.get("credit"):
                credit = add_credit(self.user, float(request.POST.get("credit")))
                message = Message.objects.filter(purpose="add_credit")
                if message:
                    message[0].send(config.email, {"user": self.user.username, "credit": float(request.POST.get("credit")), "bonus": float(request.POST.get("credit"))})
                messages.add_message(request, messages.SUCCESS, _('Credits will been added on your account after payment'))
                return HttpResponseRedirect(reverse("payment_info", kwargs={"pk": credit.id}))
        if request.POST.get("what_to_do"):
            self.user.parms.low_level_credits = request.POST.get("what_to_do")
            self.user.parms.save()
            messages.add_message(request, messages.SUCCESS, _('Low level behavior has been setted'))
        return HttpResponseRedirect(reverse("credit"))
Esempio n. 8
0
File: views.py Progetto: a740122/pcp
def reg(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            # machine
            if settings.OLD:
                m_web = get_object_or_404(Machine, name=config.default_web_machine)
                m_mail = get_object_or_404(Machine, name=config.default_mail_machine)
                m_mysql = get_object_or_404(Machine, name=config.default_mysql_machine)
                m_pgsql = get_object_or_404(Machine, name=config.default_pgsql_machine)

            # user
            u = user.objects.create_user(form.cleaned_data["username"],
                                         form.cleaned_data["email"],
                                         form.cleaned_data["password1"])
            u.is_active = True
            u.save()

            # parms
            p = Parms()
            p.home = "/dev/null"
            p.note = ""
            p.uid = 0
            p.gid = 0
            p.discount = 0
            if settings.OLD:
                p.web_machine = m_web
                p.mail_machine = m_mail
                p.mysql_machine = m_mysql
                p.pgsql_machine = m_pgsql
            p.user = u
            p.save()

            if config.credit_registration:
                add_credit(u, float(config.credit_registration), free=True)

            message = Message.objects.filter(purpose="reg")
            if message:
                message[0].send(form.cleaned_data["email"])

            message = _("User %s has been registered." % u.username)
            send_mail(_('New registration'),
                      message,
                      settings.EMAIL_FROM,
                [address for (name, address) in settings.ADMINS],
                      fail_silently=True)
            #fail_silently - nechci 500 kvuli neodeslanemu mailu

            return HttpResponseRedirect(
                reverse("wsgiadmin.useradmin.views.regok"))
    else:
        form = RegistrationForm()

    return render_to_response('reg.html',
        {
            "form": form,
            "title": _("Registration"),
            "action": reverse("wsgiadmin.useradmin.views.reg"),
            "config": config,
            "menu_active": "registration",
        },
        context_instance=RequestContext(request)
    )
Esempio n. 9
0
    def process(self, user):
        parms = user.parms
        apache_reload = False
        data = {}
        tmpl = ""

        if config.auto_disable:
            if parms.credit <= config.credit_threshold and parms.enable:
                parms.enable = False
                parms.save()
                apache_reload = True
                message = Message.objects.filter(purpose="webs_disabled")
                if message:
                    message[0].send(user.email, {})
                self.disable_apps(user)
                print "\t* %s disabled" % user.username
                return apache_reload
            elif parms.credit >= 0 and not parms.enable:
                parms.enable = True
                parms.save()
                apache_reload = True
                self.enable_apps(user)
                message = Message.objects.filter(purpose="webs_enabled")
                if message:
                    message[0].send(user.email, {"username": user.username})
                print "\t* %s enabled" % user.username
                return apache_reload

        correction = 0.0
        if parms.credit < 0:
            correction += abs(parms.credit)

        if parms.low_level_credits == "send_email":
            tmpl = "low_credit"
            data = {"credit": parms.credit, "days": parms.days_left}
        elif parms.low_level_credits == "buy_month":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 30 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_three_months":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 90 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_six_months":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 180 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_year":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 360 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"

        if tmpl and data:
            message = Message.objects.filter(purpose=tmpl)
            if message:
                message[0].send(user.email, data)
                #message[0].send(config.email, data)
                print "\t* E-mail sent"
            parms.last_notification = datetime.date.today()
            parms.save()

        return apache_reload
Esempio n. 10
0
File: guard.py Progetto: a740122/pcp
    def process(self, user):
        parms = user.parms
        apache_reload = False
        data = {}
        tmpl = ""

        if config.auto_disable:
            if parms.credit <= config.credit_threshold and parms.enable:
                parms.enable = False
                parms.save()
                apache_reload = True
                message = Message.objects.filter(purpose="webs_disabled")
                if message:
                    message[0].send(user.email, {})
                self.disable_apps(user)
                print "\t* %s disabled" % user.username
                return apache_reload
            elif parms.credit >= 0 and not parms.enable:
                parms.enable = True
                parms.save()
                apache_reload = True
                self.enable_apps(user)
                message = Message.objects.filter(purpose="webs_enabled")
                if message:
                    message[0].send(user.email, {"username": user.username})
                print "\t* %s enabled" % user.username
                return apache_reload

        correction = 0.0
        if parms.credit < 0:
            correction += abs(parms.credit)

        if parms.low_level_credits == "send_email":
            tmpl = "low_credit"
            data = {"credit": parms.credit, "days": parms.days_left}
        elif parms.low_level_credits == "buy_month":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 30 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_three_months":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 90 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_six_months":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 180 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"
        elif parms.low_level_credits == "buy_year":
            data = {"credit": parms.credit, "days": parms.days_left}
            credits = parms.pay_total_day() * 360 + correction
            add_credit(user, credits)
            tmpl = "autobuy_credit"

        if tmpl and data:
            message = Message.objects.filter(purpose=tmpl)
            if message:
                message[0].send(user.email, data)
                #message[0].send(config.email, data)
                print "\t* E-mail sent"
            parms.last_notification = datetime.date.today()
            parms.save()

        return apache_reload
Esempio n. 11
0
def reg(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            # machine
            if settings.OLD:
                m_web = get_object_or_404(Machine,
                                          name=config.default_web_machine)
                m_mail = get_object_or_404(Machine,
                                           name=config.default_mail_machine)
                m_mysql = get_object_or_404(Machine,
                                            name=config.default_mysql_machine)
                m_pgsql = get_object_or_404(Machine,
                                            name=config.default_pgsql_machine)

            # user
            u = user.objects.create_user(form.cleaned_data["username"],
                                         form.cleaned_data["email"],
                                         form.cleaned_data["password1"])
            u.is_active = True
            u.save()

            # parms
            p = Parms()
            p.home = "/dev/null"
            p.note = ""
            p.uid = 0
            p.gid = 0
            p.discount = 0
            if settings.OLD:
                p.web_machine = m_web
                p.mail_machine = m_mail
                p.mysql_machine = m_mysql
                p.pgsql_machine = m_pgsql
            p.user = u
            p.save()

            if config.credit_registration:
                add_credit(u, float(config.credit_registration), free=True)

            message = Message.objects.filter(purpose="reg")
            if message:
                message[0].send(form.cleaned_data["email"])

            message = _("User %s has been registered." % u.username)
            send_mail(_('New registration'),
                      message,
                      settings.EMAIL_FROM,
                      [address for (name, address) in settings.ADMINS],
                      fail_silently=True)
            #fail_silently - nechci 500 kvuli neodeslanemu mailu

            return HttpResponseRedirect(
                reverse("wsgiadmin.useradmin.views.regok"))
    else:
        form = RegistrationForm()

    return render_to_response(
        'reg.html', {
            "form": form,
            "title": _("Registration"),
            "action": reverse("wsgiadmin.useradmin.views.reg"),
            "config": config,
            "menu_active": "registration",
        },
        context_instance=RequestContext(request))