Beispiel #1
0
def toggleStatus(request, addressid):
    '''
    Toggle status
    '''
    addressbook = savedAddress.objects.filter(id=addressid)

    if len(addressbook):
        name = addressbook[0].name
        address = addressbook[0].address
        if addressbook[0].status == 1:
            addressbook[0].status = 2
            addressbook[0].save()
            messages.success(request,
                             'Addressbook entry %s with address %s enabled' %
                             (name, address),
                             extra_tags="info")
            events.addEvent(
                request,
                'Addressbook entry enabled with name "%s" and address "%s"' %
                (name, address), 'info')
        else:
            addressbook[0].status = 1
            addressbook[0].save()
            messages.success(request,
                             'Addressbook entry %s with address %s disabled.' %
                             (name, address),
                             extra_tags="warning")
            events.addEvent(
                request,
                'Addressbook entry disabled with name "%s" and address "%s"' %
                (name, address), 'warning')

    return HttpResponseRedirect(reverse('addressbook:index'))
Beispiel #2
0
def createNewAddress(request, provider_id, account_identifier):
    '''
    Create a new address for the account of account_identifier
    '''

    # set the request in the connector object
    connector.request = request

    provider_id = int(provider_id)
    wallet = getWalletByProviderId(connector, provider_id)
    if request.method == 'POST':
        account = wallet.getAccountByIdentifier(account_identifier)
        if account:
            new_address = connector.getNewAddress(account['provider_id'],
                                                  account['name'])
            messages.success(request,
                             'New address "%s" created for account "%s"' %
                             (new_address, account['name']),
                             extra_tags="success")
            events.addEvent(
                request, 'New address "%s" created for account "%s"' %
                (new_address, account['name']), 'info')
        return HttpResponseRedirect(
            reverse('accounts:details_with_addresses',
                    kwargs={
                        'provider_id': provider_id,
                        'account_identifier': account_identifier,
                        'page': 1
                    }))
Beispiel #3
0
def create(request):
    '''
    Handler for POST of create account form
    '''
    
    # set the request in the connector object
    connector.request = request
    
    if request.method == 'POST': 
        
        # we have a POST request
        form = forms.CreateAccountForm(request.POST)

        if form.is_valid(): 
            new_account_name = form.cleaned_data['account_name']
            provider_id = form.cleaned_data['provider_id']
            
            # all ok, create account
            new_address = connector.getNewAddress(provider_id, new_account_name)
            
            if new_address:
                messages.success(request, 'New account created with one address (%s)' % new_address, extra_tags="success")
                events.addEvent(request, 'Created new account with address "%s"' % (new_address), 'info')
                
            return HttpResponseRedirect(reverse('accounts:index'))

    else:
        form = forms.CreateAccountForm()
    
    context = getAddAccountFormContext(account_name="", form=form)
    return render(request, 'accounts/add.html', context)
Beispiel #4
0
 def removeCurrencyService(self, provider_id):
     '''
     Remove the ServiceProxy object from the list of service in case of a xxxcoind daemon not responding in time
     '''
     if self.config.get(provider_id, False):
         currency_provider_config = self.config.get(provider_id, {})
         if currency_provider_config.get('enabled', False) is True:
             self.addAlert(
                 'currencybackend', {
                     'provider_id':
                     provider_id,
                     'message':
                     'Currency service provider %s named %s is disabled for %s seconds due an error communicating.'
                     % (provider_id, currency_provider_config['name'],
                        self.disable_time),
                     'when':
                     datetime.datetime.utcnow().replace(tzinfo=utc)
                 })
             currency_provider_config['enabled'] = datetime.datetime.utcnow(
             ).replace(tzinfo=utc) + datetime.timedelta(
                 0, self.disable_time)
             events.addEvent(
                 self.request,
                 "Currency service %s has being disabled for %s seconds due to error communicating"
                 %
                 (currency_provider_config['currency'], self.disable_time),
                 'error')
             if self.services.get(provider_id, None):
                 del self.services[provider_id]
Beispiel #5
0
def setAddressAlias(request):
    '''
    Set address alias
    '''
    
    # set the request in the connector object
    connector.request = request
    
    return_msg = {'alias': ''}
    
    if request.method == 'POST':
        form = forms.SetAddressAliasForm(request.POST)
        if form.is_valid():
            # form is valid
            alias = form.cleaned_data['alias']
            address = form.cleaned_data['address']
            
            # check if address already has an alias, if multiple aliases exist for the same address, ignore them for now
            address_alias = addressAliases.objects.filter(address=address, status__gt=1)
            if address_alias:
                address_alias[0].alias = alias
                address_alias[0].save()
                events.addEvent(request, 'Updated alias for address "%s" to %s' % (address, alias), 'info')
            else:
                events.addEvent(request, 'Added alias "%s" for address "%s"' % (alias, address), 'info')
                address_alias = addressAliases.objects.create(address=address, alias=alias, status=2, entered=datetime.datetime.utcnow().replace(tzinfo=utc))
            
            if address_alias:
                return_msg = {'alias': alias}
            else:
                return_msg = {'alias': 'sugnomi xasate'}
                
    json_str = json.dumps(return_msg)             
    return HttpResponse(json_str, mimetype="application/x-javascript")
Beispiel #6
0
def processLogout(request):
    '''
    Logout
    '''

    events.addEvent(request, 'Logout occurred', 'info')
    logout(request)

    return HttpResponseRedirect(reverse('login:index'))
Beispiel #7
0
def processLogout(request):
    '''
    Logout
    '''
    
    events.addEvent(request, 'Logout occurred', 'info')
    logout(request)
    
    return HttpResponseRedirect(reverse('login:index'))
 def removeCurrencyService(self, provider_id):
     '''
     Remove the ServiceProxy object from the list of service in case of a xxxcoind daemon not responding in time
     '''
     if self.config.get(provider_id, False):
         currency_provider_config = self.config.get(provider_id, {})
         if currency_provider_config.get('enabled', False) is True:
             self.addAlert('currencybackend', {'provider_id': provider_id, 'message': 'Currency service provider %s named %s is disabled for %s seconds due an error communicating.' % (provider_id, currency_provider_config['name'], self.disable_time), 'when': datetime.datetime.utcnow().replace(tzinfo=utc)})
             currency_provider_config['enabled'] = datetime.datetime.utcnow().replace(tzinfo=utc) + datetime.timedelta(0, self.disable_time)
             events.addEvent(self.request, "Currency service %s has being disabled for %s seconds due to error communicating" % (currency_provider_config['currency'], self.disable_time), 'error')
             if self.services.get(provider_id, None):
                 del self.services[provider_id]
Beispiel #9
0
def create(request):
    '''
    Create a new address book entry
    '''

    # set the request in the connector object
    connector.request = request

    if request.method == 'POST':
        # we have a POST request
        form = forms.AddAddressBookForm(request.POST)

        if form.is_valid():
            # form is valid
            name = form.cleaned_data['name']
            address = form.cleaned_data['address']
            provider_id = form.cleaned_data['provider_id']
            comment = form.cleaned_data['comment']

            # add address to addressbook
            newAddressEntry = savedAddress(
                name=name,
                address=address,
                currency=connector.config[provider_id]['currency'],
                comment=comment,
                status=2,
                entered=datetime.datetime.utcnow().replace(tzinfo=utc))
            newAddressEntry.save()
            messages.success(request,
                             'Addressbook entry added for %s with address %s' %
                             (name, address),
                             extra_tags="success")
            events.addEvent(
                request, 'Addressbook entry added for %s with name "%s"' %
                (address, name), 'info')

            return HttpResponseRedirect(reverse('addressbook:index'))
        else:
            # form not valid
            pass

    else:
        # not a POST
        form = forms.AddAddressBookForm()

    context = getAddressBookCommonContext(request=request, form=form)
    context['breaddrumbs'] = misc.buildBreadcrumbs(current_section, '',
                                                   'Add address')
    return render(request, 'addressbook/add.html', context)
Beispiel #10
0
def delete(request, addressid):
    '''
    Set status to 0
    '''
    addressbook = savedAddress.objects.filter(id=addressid)
    
    if addressbook:
        name = addressbook[0].name
        address = addressbook[0].address
        addressbook[0].status = 0
        addressbook[0].save()
        messages.success(request, 'Addressbook entry %s with address %s deleted' % (name, address), extra_tags="warning")
        events.addEvent(request, 'Addressbook entry deleted with name "%s" and address "%s"' % (name, address), 'warning')
        
    return HttpResponseRedirect(reverse('addressbook:index'))
Beispiel #11
0
def createNewAddress(request, provider_id, account_identifier):
    '''
    Create a new address for the account of account_identifier
    '''
    
    # set the request in the connector object
    connector.request = request
    
    provider_id = int(provider_id)
    wallet = getWalletByProviderId(connector, provider_id)
    if request.method == 'POST': 
        account = wallet.getAccountByIdentifier(account_identifier)
        if account:
            new_address = connector.getNewAddress(account['provider_id'], account['name'])
            messages.success(request, 'New address "%s" created for account "%s"' % (new_address, account['name']), extra_tags="success")
            events.addEvent(request, 'New address "%s" created for account "%s"' % (new_address, account['name']), 'info')
        return HttpResponseRedirect(reverse('accounts:details_with_addresses', kwargs={'provider_id': provider_id, 'account_identifier': account_identifier, 'page': 1}))
Beispiel #12
0
def setAddressAlias(request):
    '''
    Set address alias
    '''

    # set the request in the connector object
    connector.request = request

    return_msg = {'alias': ''}

    if request.method == 'POST':
        form = forms.SetAddressAliasForm(request.POST)
        if form.is_valid():
            # form is valid
            alias = form.cleaned_data['alias']
            address = form.cleaned_data['address']

            # check if address already has an alias, if multiple aliases exist for the same address, ignore them for now
            address_alias = addressAliases.objects.filter(address=address,
                                                          status__gt=1)
            if address_alias:
                address_alias[0].alias = alias
                address_alias[0].save()
                events.addEvent(
                    request,
                    'Updated alias for address "%s" to %s' % (address, alias),
                    'info')
            else:
                events.addEvent(
                    request,
                    'Added alias "%s" for address "%s"' % (alias, address),
                    'info')
                address_alias = addressAliases.objects.create(
                    address=address,
                    alias=alias,
                    status=2,
                    entered=datetime.datetime.utcnow().replace(tzinfo=utc))

            if address_alias:
                return_msg = {'alias': alias}
            else:
                return_msg = {'alias': 'sugnomi xasate'}

    json_str = json.dumps(return_msg)
    return HttpResponse(json_str, mimetype="application/x-javascript")
Beispiel #13
0
def toggleStatus(request, addressid):
    '''
    Toggle status
    '''
    addressbook = savedAddress.objects.filter(id=addressid)
    
    if len(addressbook):
        name = addressbook[0].name
        address = addressbook[0].address
        if addressbook[0].status == 1:
            addressbook[0].status = 2
            addressbook[0].save()
            messages.success(request, 'Addressbook entry %s with address %s enabled' % (name, address), extra_tags="info")
            events.addEvent(request, 'Addressbook entry enabled with name "%s" and address "%s"' % (name, address), 'info')
        else:
            addressbook[0].status = 1
            addressbook[0].save()
            messages.success(request, 'Addressbook entry %s with address %s disabled.' % (name, address), extra_tags="warning")
            events.addEvent(request, 'Addressbook entry disabled with name "%s" and address "%s"' % (name, address), 'warning')
            
    return HttpResponseRedirect(reverse('addressbook:index'))
Beispiel #14
0
def create(request):
    '''
    Handler for POST of create account form
    '''

    # set the request in the connector object
    connector.request = request

    if request.method == 'POST':

        # we have a POST request
        form = forms.CreateAccountForm(request.POST)

        if form.is_valid():
            new_account_name = form.cleaned_data['account_name']
            provider_id = form.cleaned_data['provider_id']

            # all ok, create account
            new_address = connector.getNewAddress(provider_id,
                                                  new_account_name)

            if new_address:
                messages.success(request,
                                 'New account created with one address (%s)' %
                                 new_address,
                                 extra_tags="success")
                events.addEvent(
                    request,
                    'Created new account with address "%s"' % (new_address),
                    'info')

            return HttpResponseRedirect(reverse('accounts:index'))

    else:
        form = forms.CreateAccountForm()

    context = getAddAccountFormContext(account_name="", form=form)
    return render(request, 'accounts/add.html', context)
Beispiel #15
0
def create(request):
    '''
    Create a new address book entry
    '''
    
    # set the request in the connector object
    connector.request = request
    
    if request.method == 'POST': 
        # we have a POST request
        form = forms.AddAddressBookForm(request.POST)
        
        if form.is_valid():
            # form is valid
            name = form.cleaned_data['name']
            address = form.cleaned_data['address']
            provider_id = form.cleaned_data['provider_id']
            comment = form.cleaned_data['comment']
            
            # add address to addressbook
            newAddressEntry = savedAddress(name=name, address=address, currency=connector.config[provider_id]['currency'], comment=comment, status=2, entered=datetime.datetime.utcnow().replace(tzinfo=utc))
            newAddressEntry.save()
            messages.success(request, 'Addressbook entry added for %s with address %s' % (name, address), extra_tags="success")
            events.addEvent(request, 'Addressbook entry added for %s with name "%s"' % (address, name), 'info')
            
            return HttpResponseRedirect(reverse('addressbook:index'))
        else:
            # form not valid
            pass
            
    else:
        # not a POST
        form = forms.AddAddressBookForm()
    
    context = getAddressBookCommonContext(request=request, form=form)
    context['breaddrumbs'] = misc.buildBreadcrumbs(current_section, '', 'Add address')
    return render(request, 'addressbook/add.html', context)
Beispiel #16
0
def send(request, selected_provider_id):
    '''
    handler for the transfers
    '''
    post_errors = []
    selected_provider_id = int(selected_provider_id)
    
    # set the request in the connector object
    connector.request = request
    
    if request.method == 'POST': 
        # we have a POST request
        form = forms.SendCurrencyForm(request.POST)
        
        if form.is_valid():
            # all validation rules pass
            from_account_identifier = form.cleaned_data['from_account']
            to_address = form.cleaned_data['to_address']
            to_account = form.cleaned_data['to_account']
            comment = form.cleaned_data['comment']
            comment_to = form.cleaned_data['comment_to']
            amount = form.cleaned_data['amount']
            provider_id = form.cleaned_data['provider_id']
            passphrase = form.cleaned_data['passphrase']
            
            # main exit flags
            move_exit = False
            sendfrom_exit = False
            
            # get from account details
            wallet = getWalletByProviderId(connector, selected_provider_id)
            list_of_accounts = wallet.listAccounts(gethidden=True, getarchived=True)
            from_account = None
            for account in list_of_accounts:
                if account['identifier'] == from_account_identifier:
                    from_account = account
                    break
            else:
                # account name not found, display error
                post_errors.append({'message': "The source account was not found!"})
                context = commonContext(request=request, selected_provider_id=provider_id, form=form, errors=post_errors)
                return render(request, 'transfer/index.html', context)
            
            # get to account details if there is one
            to_account = wallet.getAccountByAddress(to_address)
            # if to_account is set then it is a local move, do a move()
            if to_account:
                # this address/account is hosted locally, do a move
                move_exit = connector.moveAmount(
                                                 from_account=from_account['name'],
                                                 to_account=to_account['name'],
                                                 provider_id=provider_id,
                                                 amount=amount,
                                                 comment=comment
                                                )
                
                # if there are errors, show them in the UI
                if move_exit is not True:
                    post_errors.append({'message': move_exit['message']})
                    context = commonContext(request=request, selected_provider_id=provider_id, form=form, errors=post_errors)
                    return render(request, 'transfer/index.html', context)
                
            else:
                # otherwise do a sendfrom(), it is a regular transaction
                if passphrase:
                    # a passphrase was given, unlock wallet first
                    unlock_exit = connector.walletPassphrase(passphrase, provider_id)
                    
                    if unlock_exit is not True:
                        # show form with error
                        post_errors.append({'message': unlock_exit['message']})
                        context = commonContext(request=request, selected_provider_id=provider_id, form=form, errors=post_errors, show_passphrase=True)
                        return render(request, 'transfer/index.html', context)
                
                # to_address not local, do a send
                sendfrom_exit = connector.sendFrom(
                                                   from_account=from_account['name'],
                                                   to_address=to_address,
                                                   amount=amount,
                                                   provider_id=provider_id,
                                                   comment=comment,
                                                   comment_to=comment_to
                                                  )
                
                # if there are errors, show them in the UI
                if type(sendfrom_exit) is dict and sendfrom_exit['code'] < 0:
                    
                    # check if passphrase is needed
                    if sendfrom_exit['code'] == -13:
                        # passphrase is needed
                        show_passphrase = True
                    else:
                        show_passphrase = False
                    
                    if not request.is_secure() and show_passphrase:
                        show_warning_ssl = 1
                    elif request.is_secure() and show_passphrase:
                        show_warning_ssl = -1
                    else:
                        show_warning_ssl = 0
                    
                    # show form with error
                    post_errors.append({'message': sendfrom_exit['message']})
                    context = commonContext(request=request, selected_provider_id=provider_id, form=form, errors=post_errors, show_passphrase=show_passphrase, show_warning_ssl=show_warning_ssl)
                    return render(request, 'transfer/index.html', context)
                
            if passphrase:
                # lock wallet again
                connector.walletLock(provider_id)
                
            # process the data in form.cleaned_data
            if move_exit:
                messages.success(request, 'Local move of %s %s completed from account "%s" to "%s"' % (amount, connector.config[provider_id]['currency'].upper(), from_account['name'], to_account['name']), extra_tags="success")
                events.addEvent(request, 'Local move occurred from "%s" to "%s" in the amount of %s %s' % (from_account['name'], to_account['name'], amount, connector.config[provider_id]['currency'].upper()), 'info')
                return HttpResponseRedirect(reverse('transactions:index', kwargs={'selected_provider_id': selected_provider_id, 'page': '1'}))  # Redirect after POST
            elif sendfrom_exit:
                messages.success(request, 'Transfer of %s %s initialized with transaction id %s' % (amount, connector.config[provider_id]['currency'].upper(), sendfrom_exit), extra_tags="success")
                events.addEvent(request, 'Transfer initialized from "%s" to "%s" of %s %s' % (from_account['name'], to_address, amount, connector.config[provider_id]['currency'].upper()), 'info')
                return HttpResponseRedirect(reverse('transactions:details', kwargs={'provider_id': provider_id, 'txid':sendfrom_exit}))  # Redirect after POST
        
        else:
            # form not valid
            #messages.error(request, 'There were some errors processing this form!', extra_tags="error")
            print "Error processing form!"
            
    else:
        # request not a POST
        form = forms.SendCurrencyForm()
        
    context = commonContext(request=request, selected_provider_id=selected_provider_id, form=form)
    
    return render(request, 'transfer/index.html', context)
Beispiel #17
0
def processLogin(request):
    '''
    Authenticate user
    '''

    auth_process = False

    if request.method == 'POST':
        # we have a POST request
        login_form = forms.LoginForm(request.POST)

        if login_form.is_valid():
            # all validation rules pass
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            remember = login_form.cleaned_data['remember']
            next_url = login_form.cleaned_data['next_url']

            # try to authenticate user
            user = authenticate(username=username, password=password)
            client_ip = misc.getClientIp(request)

            try:
                client_hostname_tuple = socket.gethostbyaddr(client_ip)
            except:
                client_hostname_tuple = ()

            if client_hostname_tuple:
                client_hostname = client_hostname_tuple[0]
            else:
                client_hostname = 'n/a'

            if user is not None and user.is_active:
                # authenticated, log user in
                login(request, user)
                events.addEvent(
                    request, 'Login occurred from %s (%s)' %
                    (client_hostname, client_ip), 'info')

                if remember:
                    request.session.set_expiry(0)
                else:
                    request.session.set_expiry(300)

                if next_url:
                    return HttpResponseRedirect(next_url)
                else:
                    return HttpResponseRedirect(reverse('dashboard:index'))
            else:
                # failed to authenticate password
                auth_process = False
                auth_message = "Username and password combination incorrect"
                events.addEvent(
                    username, 'Login failed from %s (%s) username: %s' %
                    (client_hostname, client_ip, username), 'alert')
        else:
            # form not valid so auth failed
            auth_process = False
            auth_message = ""
    else:
        auth_process = False
        auth_message = ""
        login_form = forms.LoginForm()

    # check
    if not auth_process:
        page_title = _("Login")
        context = {
            'globals': MainConfig['globals'],
            'breadcrumbs': misc.buildBreadcrumbs(current_section, 'all'),
            'system_errors': connector.errors,
            'page_title': page_title,
            'form': login_form,
            'main_error': auth_message,
            'request': request,
        }

    return render(request, 'login/index.html', context)
Beispiel #18
0
def send(request, selected_provider_id):
    '''
    handler for the transfers
    '''
    post_errors = []
    selected_provider_id = int(selected_provider_id)

    # set the request in the connector object
    connector.request = request

    if request.method == 'POST':
        # we have a POST request
        form = forms.SendCurrencyForm(request.POST)

        if form.is_valid():
            # all validation rules pass
            from_account_identifier = form.cleaned_data['from_account']
            to_address = form.cleaned_data['to_address']
            to_account = form.cleaned_data['to_account']
            comment = form.cleaned_data['comment']
            comment_to = form.cleaned_data['comment_to']
            amount = form.cleaned_data['amount']
            provider_id = form.cleaned_data['provider_id']
            passphrase = form.cleaned_data['passphrase']

            # main exit flags
            move_exit = False
            sendfrom_exit = False

            # get from account details
            wallet = getWalletByProviderId(connector, selected_provider_id)
            list_of_accounts = wallet.listAccounts(gethidden=True,
                                                   getarchived=True)
            from_account = None
            for account in list_of_accounts:
                if account['identifier'] == from_account_identifier:
                    from_account = account
                    break
            else:
                # account name not found, display error
                post_errors.append(
                    {'message': "The source account was not found!"})
                context = commonContext(request=request,
                                        selected_provider_id=provider_id,
                                        form=form,
                                        errors=post_errors)
                return render(request, 'transfer/index.html', context)

            # get to account details if there is one
            to_account = wallet.getAccountByAddress(to_address)
            # if to_account is set then it is a local move, do a move()
            if to_account:
                # this address/account is hosted locally, do a move
                move_exit = connector.moveAmount(
                    from_account=from_account['name'],
                    to_account=to_account['name'],
                    provider_id=provider_id,
                    amount=amount,
                    comment=comment)

                # if there are errors, show them in the UI
                if move_exit is not True:
                    post_errors.append({'message': move_exit['message']})
                    context = commonContext(request=request,
                                            selected_provider_id=provider_id,
                                            form=form,
                                            errors=post_errors)
                    return render(request, 'transfer/index.html', context)

            else:
                # otherwise do a sendfrom(), it is a regular transaction
                if passphrase:
                    # a passphrase was given, unlock wallet first
                    unlock_exit = connector.walletPassphrase(
                        passphrase, provider_id)

                    if unlock_exit is not True:
                        # show form with error
                        post_errors.append({'message': unlock_exit['message']})
                        context = commonContext(
                            request=request,
                            selected_provider_id=provider_id,
                            form=form,
                            errors=post_errors,
                            show_passphrase=True)
                        return render(request, 'transfer/index.html', context)

                # to_address not local, do a send
                sendfrom_exit = connector.sendFrom(
                    from_account=from_account['name'],
                    to_address=to_address,
                    amount=amount,
                    provider_id=provider_id,
                    comment=comment,
                    comment_to=comment_to)

                # if there are errors, show them in the UI
                if type(sendfrom_exit) is dict and sendfrom_exit['code'] < 0:

                    # check if passphrase is needed
                    if sendfrom_exit['code'] == -13:
                        # passphrase is needed
                        show_passphrase = True
                    else:
                        show_passphrase = False

                    if not request.is_secure() and show_passphrase:
                        show_warning_ssl = 1
                    elif request.is_secure() and show_passphrase:
                        show_warning_ssl = -1
                    else:
                        show_warning_ssl = 0

                    # show form with error
                    post_errors.append({'message': sendfrom_exit['message']})
                    context = commonContext(request=request,
                                            selected_provider_id=provider_id,
                                            form=form,
                                            errors=post_errors,
                                            show_passphrase=show_passphrase,
                                            show_warning_ssl=show_warning_ssl)
                    return render(request, 'transfer/index.html', context)

            if passphrase:
                # lock wallet again
                connector.walletLock(provider_id)

            # process the data in form.cleaned_data
            if move_exit:
                messages.success(
                    request,
                    'Local move of %s %s completed from account "%s" to "%s"' %
                    (amount, connector.config[provider_id]['currency'].upper(),
                     from_account['name'], to_account['name']),
                    extra_tags="success")
                events.addEvent(
                    request,
                    'Local move occurred from "%s" to "%s" in the amount of %s %s'
                    % (from_account['name'], to_account['name'], amount,
                       connector.config[provider_id]['currency'].upper()),
                    'info')
                return HttpResponseRedirect(
                    reverse('transactions:index',
                            kwargs={
                                'selected_provider_id': selected_provider_id,
                                'page': '1'
                            }))  # Redirect after POST
            elif sendfrom_exit:
                messages.success(
                    request,
                    'Transfer of %s %s initialized with transaction id %s' %
                    (amount, connector.config[provider_id]['currency'].upper(),
                     sendfrom_exit),
                    extra_tags="success")
                events.addEvent(
                    request,
                    'Transfer initialized from "%s" to "%s" of %s %s' %
                    (from_account['name'], to_address, amount,
                     connector.config[provider_id]['currency'].upper()),
                    'info')
                return HttpResponseRedirect(
                    reverse('transactions:details',
                            kwargs={
                                'provider_id': provider_id,
                                'txid': sendfrom_exit
                            }))  # Redirect after POST

        else:
            # form not valid
            #messages.error(request, 'There were some errors processing this form!', extra_tags="error")
            print "Error processing form!"

    else:
        # request not a POST
        form = forms.SendCurrencyForm()

    context = commonContext(request=request,
                            selected_provider_id=selected_provider_id,
                            form=form)

    return render(request, 'transfer/index.html', context)
Beispiel #19
0
def processLogin(request): 
    '''
    Authenticate user
    '''
    
    auth_process = False
    
    if request.method == 'POST': 
        # we have a POST request
        login_form = forms.LoginForm(request.POST)
        
        if login_form.is_valid():
            # all validation rules pass
            username = login_form.cleaned_data['username']
            password = login_form.cleaned_data['password']
            remember = login_form.cleaned_data['remember']
            next_url = login_form.cleaned_data['next_url']

            # try to authenticate user
            user = authenticate(username=username, password=password)
            client_ip = misc.getClientIp(request)
            
            try:
                client_hostname_tuple = socket.gethostbyaddr(client_ip)
            except:
                client_hostname_tuple = ()
                
            if client_hostname_tuple:
                client_hostname = client_hostname_tuple[0]
            else:
                client_hostname = 'n/a'
        
            if user is not None and user.is_active:
                # authenticated, log user in
                login(request, user)
                events.addEvent(request, 'Login occurred from %s (%s)' % (client_hostname, client_ip), 'info')
                
                if remember:
                    request.session.set_expiry(0)
                else:
                    request.session.set_expiry(300)
                    
                if next_url:
                    return HttpResponseRedirect(next_url)
                else:
                    return HttpResponseRedirect(reverse('dashboard:index'))
            else:
                # failed to authenticate password
                auth_process = False
                auth_message = "Username and password combination incorrect"
                events.addEvent(username, 'Login failed from %s (%s) username: %s' % (client_hostname, client_ip, username), 'alert')
        else:
            # form not valid so auth failed
            auth_process = False
            auth_message = ""
    else:
        auth_process = False
        auth_message = ""
        login_form = forms.LoginForm()
            
    # check 
    if not auth_process:
        page_title = _("Login")
        context = {
                   'globals': MainConfig['globals'],
                   'breadcrumbs': misc.buildBreadcrumbs(current_section, 'all'),
                   'system_errors': connector.errors,
                   'page_title': page_title,
                   'form': login_form,
                   'main_error': auth_message,
                   'request': request,
                   }
        
    return render(request, 'login/index.html', context)