Ejemplo n.º 1
0
def user(request):
    if libs.is_signin(request):
        data = {"title": "User page", "account": "active"}
        user_id = libs.who_signin(request)[0]
        try:
            data["user"] = models.User.objects.get(id=user_id)
        except models.User.DoesNotExist:
            raise Http404()
        else:
            if libs.is_signin(request, user_id=data["user"].id):
                return render(request, "user_page.html", data)
            else:
                raise Http404()
    else:
        messages.info(request, _("You need to be logged in to view this page."))
        return redirect("user_signin")
Ejemplo n.º 2
0
def registration(request):
    if not libs.is_signin(request):
        data = {"title": _("Register new user")}
        if request.method == "POST":
            form_registration = forms.RegistrationUser(request.POST)
            if form_registration.is_valid():
                form_registration.save()
                messages.info(
                    request,
                    _("An email has been sent to the specified email address."),
                )
                messages.info(
                    request,
                    _("To complete the registration, click on the link in the email.")
                )
                return redirect("user_signin")
        else:
            form_registration = forms.RegistrationUser()
        data["form_registration"] = form_registration
        return render(
            request,
            "registration.html",
            data
        )
    else:
        return redirect("user_page")
Ejemplo n.º 3
0
def load(request):
    if libs.is_signin(request):
        data = {"title": _("Load Data"), "sender": "active"}
        if request.method == "POST":
            form_airdrop = forms.AirdropForm(request.POST, request.FILES)
            if form_airdrop.is_valid():
                form_airdrop.save(request)
                return redirect("user_page")
        else:
            form_airdrop = forms.AirdropForm()
        data["form_airdrop"] = form_airdrop
        return render(request, "load_data.html", data)
    else:
        return redirect("user_signin")
Ejemplo n.º 4
0
def orders(request, num):
    if libs.is_signin(request):
        data = {"title": _("Orders"), "orders": "active"}
        user_id = libs.who_signin(request)[0]
        orders = sm.SenderOrder.objects.filter(user_id=user_id).order_by("-id")
        if orders.count() > 0 and num > orders.count():
            raise Http404
        data["pages"] = range(1, libs.count_pages(orders.count()) + 1)
        begin, end = libs.pages(num)
        data["all_orders"] = orders[begin:end]
        data["curent_page"] = num
        return render(request, "orders.html", data)
    else:
        return redirect("user_signin")
Ejemplo n.º 5
0
def order(request, address):
    if libs.is_signin(request):
        data = {"title": _("Order #"), "orders": "active"}
        user_id = libs.who_signin(request)[0]
        try:
            data["order"] = sm.SenderOrder.objects.get(address=address,
                                                       user_id=user_id)
        except sm.SenderOrder.DoesNotExist:
            raise Http404
        try:
            data["back"] = request.META['HTTP_REFERER']
        except KeyError:
            pass
        data["title"] += str(data["order"].id)
        return render(request, "order.html", data)
    else:
        return redirect("user_signin")
Ejemplo n.º 6
0
def sign_in(request):
    if not libs.is_signin(request):
        data = {"title": _("Sign in"), "account": "active"}
        if request.method == "POST":
            form_signin = forms.SigninUser(request.POST)
            if form_signin.is_valid():
                fields = form_signin.cleaned_data
                libs.signin(request, fields.get("email"))
                return redirect("user_page")
        else:
            form_signin = forms.SigninUser()
        data["form_signin"] = form_signin
        return render(
            request,
            "signin.html",
            data
        )
    else:
        return redirect("user_page")
Ejemplo n.º 7
0
def start(request, address):
    if libs.is_signin(request):
        order = sm.SenderOrder.objects.filter(address=address)
        if not order:
            raise Http404
        order.update(status=0)
        data = {
            "address": order[0].address,
            "contract": order[0].contract,
            "amount": order[0].recepient_order.all()[0].amount,
            "order": order[0].id
        }
        if order[0].work_contract:
            data["work_contract"] = order[0].work_contract
            data["command"] = "run"
        else:
            data["command"] = "deploy"
        deploy = Process(target=run_order, args=[data])
        deploy.start()
        return redirect("view_order", order[0].address)
    else:
        return redirect("user_signin")
Ejemplo n.º 8
0
def start_order(request, address):
    if libs.is_signin(request):
        pass
    else:
        return redirect("user_signin")
Ejemplo n.º 9
0
def check_token(request):
    if libs.is_signin(request):
        if request.method == "POST" and request.is_ajax():
            address = request.POST.get("address")
            contract = request.POST.get("contract")
            order_id = request.POST.get("order_id")
            try:
                order_id = int(order_id)
            except TypeError:
                return HttpResponse(
                    json.dumps({
                        "result": "error",
                        "description": "Order not found"
                    }))
            if address and contract and order_id:
                if re.match(ADDRESS, address) and re.match(ADDRESS, contract):
                    order = rm.SenderOrder.objects.filter(address=address,
                                                          id=order_id)
                    if order and len(order) == 1:
                        data = {"reload": False}
                        data["result"] = libs.get_data(
                            {
                                "command": "token",
                                "address": address,
                                "contract": contract
                            }, "balance")
                        if not order[0].tokens and data["result"] \
                                and data["result"] >= int(order[0].amount):
                            order.update(tokens=True)
                            data["reload"] = True
                        return HttpResponse(json.dumps(data))
                    else:
                        return HttpResponse(
                            json.dumps({
                                "result": "error",
                                "description": "Address not found"
                            }))
                else:
                    return HttpResponse(
                        json.dumps({
                            "result": "error",
                            "description": "Invalid address format"
                        }))
            else:
                return HttpResponse(
                    json.dumps({
                        "result": "error",
                        "description": "Not found field 'address'"
                    }))
        else:
            return HttpResponse(
                json.dumps({
                    "result": "error",
                    "description": "Only POST request"
                }))
    else:
        return HttpResponse(
            json.dumps({
                "result": "error",
                "description": "Only for authorized users"
            }))
Ejemplo n.º 10
0
def sign_out(request):
    if libs.is_signin(request):
        libs.signout(request)
        return redirect("user_signin")
    else:
        return redirect("user_signin")
Ejemplo n.º 11
0
def login(request):
    data = {}
    if libs.is_signin(request):
        data["login"] = True
    return data