예제 #1
0
 def get(self, request):
     user = User.objects.get(username=request.user)
     try:
         callback(user)
     except (ObjectDoesNotExist, KeyError):
         return HttpResponseForbidden('You are not logged in correctly.'
                                      '<a href="/account/logout">Back</a>')
     return render(request, self.template)  # pragma: no cover
예제 #2
0
 def post(self, request, **kwargs):
     # # file_contents = json.loads(request.POST['json'])ß
     # # encryption_password = request.POST['pass']
     user = User.objects.get(username=request.user)
     API = callback(user, **kwargs)
     response = getattr(API, kwargs.get('selector').strip('/'))()
     return HttpResponse(json.dumps(response))
예제 #3
0
    def post(self, request, selector, userID=None, accountID=None):
        file_contents = json.loads(request.POST['json'])
        encryption_password = request.POST['pass']
        user = User.objects.get(username=request.user)

        if file_contents['userID'] in user.profile.GUID:
            try:
                API = callback(
                    file_contents,
                    user,
                    encryption_password,
                    userID,
                    accountID,
                )
            except UnicodeDecodeError:
                error = {
                    "Error": [{
                        "error_description_translated":
                        "During decpyting something whent wrong, maybe you entreded a wrong password?"
                    }  # noqa
                              ]
                }
                return HttpResponse(json.dumps(error))
            else:
                response = getattr(API, selector.strip('/'))()
                return HttpResponse(json.dumps(response))
        else:  # pragma: no cover
            error = {
                'Error': [{
                    'error_description_translated':
                    'This file is not yours to use.'
                }]  # noqa
            }
            return HttpResponse(json.dumps(error))
예제 #4
0
def API(request, selector, userID=None, accountID=None):
    '''
    Need to mock bunq api response to test this view.
    The view that handles API calls.
    accountID === cardID
    '''
    if request.method == 'POST':
        f = json.loads(request.POST['json'])
        p = request.POST['pass']
        u = User.objects.get(username=request.user)
        if f['userID'] in u.profile.GUID:  # noqa
            try:
                API = callback(f, u, p, userID, accountID)
            except UnicodeDecodeError:
                e = {
                "Error": [{"error_description_translated": "During decpyting something whent wrong, maybe you entreded a wrong password?"}]  # noqa
                }
                return HttpResponse(json.dumps(e))

            r = getattr(API, selector.strip('/'))()
            return HttpResponse(json.dumps(r))
        else:
            e = {
            'Error': [{'error_description_translated': 'This file is not yours to use.'}] # noqa
            }
            return HttpResponse(json.dumps(e))
예제 #5
0
    def check_bunq_session(user):
        now = datetime.datetime.now(datetime.timezone.utc)
        session_end = user.session.session_end_date

        if now <= session_end:
            c = callback(user)
            if c.delete_session():
                user.session.session_end_date = now
                user.save()
예제 #6
0
    def check_bunq_session(username):
        user = User.objects.get(username=username)
        cb = callback(user)
        last_login = user.last_login
        session_end = user.session.session_end_date

        if last_login <= session_end:
            cb.delete_session()
            user.session.session_end_date = datetime.datetime.now(
                datetime.timezone.utc)
            user.save()
예제 #7
0
    def register_api_key(self):
        c = callback(api_key=self.api_key, user=self.user, decrypt=False)
        installation = c.installation()

        if installation['status']:
            enc_string = signing.dumps(obj=installation['data'],
                                       key=self.password)
            now = datetime.datetime.now()
            json = {
                'secret': enc_string,
                'username': self.user.username,
                'created': arrow.get(now).format(fmt='DD-MM-YYYY HH:mm:ss')
            }
            Creator(user=self.user).user_json(data=json)
            return True
        else:  # pragma: no cover
            if self._delete_user:
                self.user.delete()
            return False
예제 #8
0
    def post(self, request):
        form = self.generate_form(request.POST)
        user = User.objects.get(username=request.user)

        if form.is_valid():
            form_data = form.cleaned_data

            generate_data = installation(user,
                                         form_data['encryption_password'],
                                         form_data['API']).encrypt()

            registration = callback(
                json.loads(generate_data),
                user,
                form_data['encryption_password'],
            ).register()

            if registration.status_code is 200:
                response = HttpResponse(
                    generate_data, content_type='application/force-download')
                response[
                    'Content-Disposition'] = 'attachment; filename=%s' % smart_str(
                        'BunqWebApp.json')  # noqa

                user.save()
            else:
                error = {
                    "Error": [{
                        "error_description_translated":
                        'something whent wrong while registering your API key wiht the bunq servers'  # noqa
                    }]
                }
                response = HttpResponse(json.dumps(error))
            return response

        else:
            return render(request, self.template, {'form': form})
예제 #9
0
    def setUp(self, mock):
        mock.register_uri(requests_mock.ANY,
                          self.installation,
                          json=self.get_installation)
        mock.register_uri(requests_mock.ANY, self.device_server)

        username = self.fake.name()
        self.password = self.fake.password()
        self.user = User.objects.create_user(username=username,
                                             password=self.password,
                                             email=None)
        i = Installation(user=self.user,
                         api_key=self.fake.sha1(),
                         password=self.password)
        i.status
        key = self.user.tokens.file_token
        file_path = SessionStore(session_key=key)['file_path']
        with open(file_path, 'r') as f:
            file_contents = f.read()
        self.store_in_session(data=file_contents)

        self.c = callback(self.user)

        os.remove(file_path)