Ejemplo n.º 1
0
def deleteauth(request, agent_id, oauth_id):
    access_permission, user_agent, agent = get_agents(request, agent_id)
    if not access_permission:
        raise PermissionDenied

    try:
        oauths = MulticurrencyAuth.objects.filter(agent=agent)
    except MulticurrencyAuth.DoesNotExist:
        raise Http404

    oauth = None
    for o in oauths:
        if o.id == int(oauth_id):
            oauth = o

    if not oauth:
        raise Http404

    if request.method == 'POST':
        form = MulticurrencyAuthDeleteForm(request.POST)
        if form.is_valid():
            oauth.delete()
            messages.success(
                request,
                _('Your ChipChap user has been succesfully logged out.'))
    return redirect('multicurrency_auth', agent_id=agent_id)
Ejemplo n.º 2
0
def auth(request, agent_id):
    access_permission, user_agent, agent = get_agents(request, agent_id)
    if not access_permission:
        raise PermissionDenied

    if request.method == 'POST':
        form = MulticurrencyAuthForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['loginname']
            acs = MulticurrencyAuth.objects.filter(auth_user__iexact=name)
            if acs:
                messages.error(request, _("This login name already exists."))
                return redirect('multicurrency_auth', agent_id=agent_id)

            password = form.cleaned_data['wallet_password']
            oauth = None
            connection = ChipChapAuthConnection.get()
            try:
                response = connection.new_client(name, password)
            except ChipChapAuthError:
                messages.error(request, _('Authentication failed.'))
                return redirect('multicurrency_auth', agent_id=agent_id)
            try:
                oauth = MulticurrencyAuth.objects.create(
                    agent=agent,
                    auth_user=name,
                    access_key=response['access_key'],
                    access_secret=response['access_secret'],
                    created_by=request.user,
                )
            except:
                messages.error(request,
                               _('Something was wrong saving your data.'))
            if oauth:
                messages.success(
                    request,
                    _('Your BotC-Wallet user has been succesfully authenticated.'
                      ))

            for req in agent.project_join_requests.all():
                if req.project.agent.need_multicurrency():
                    req.multiwallet_user(name)

            if oauth:
                return redirect('multicurrency_history',
                                agent_id=agent_id,
                                oauth_id=oauth.id)

            return redirect('multicurrency_auth', agent_id=agent_id)
        else:
            messages.error(request, "The form has errors: " + str(form.errors))
            return redirect('multicurrency_auth', agent_id=agent_id)

    else:
        try:
            oauths = MulticurrencyAuth.objects.filter(agent=agent)
        except MulticurrencyAuth.DoesNotExist:
            oauths = None

        jnreq = None
        if agent:
            for req in agent.project_join_requests.all():
                if req.project.agent.need_multicurrency():
                    jnreq = req

        form = MulticurrencyAuthForm()
        delete_form = MulticurrencyAuthDeleteForm()
        create_form = MulticurrencyAuthCreateForm(initial={
            'username': agent.nick,
            'email': agent.email,
        })
        return render(
            request, 'multicurrency_auth.html', {
                'agent': agent,
                'user_agent': user_agent,
                'oauths': oauths,
                'jn_req': jnreq,
                'oauth_form': form,
                'create_form': create_form,
                'delete_form': delete_form,
            })