Пример #1
0
    def post(self, request):
        try:
            name = request.DATA['name']
            username = request.user.username
            if (OauthApp.objects.filter(name=name).exists()):
                e_msg = ('application with name: %s already exists.' % name)
                handle_exception(Exception(e_msg), request)

            try:
                user = User.objects.get(username=username)
            except:
                e_msg = ('User with name: %s does not exist' % username)
                handle_exception(Exception(e_msg), request)

            client_type = OauthApplication.CLIENT_CONFIDENTIAL
            auth_grant_type = OauthApplication.GRANT_CLIENT_CREDENTIALS
            app = OauthApplication(name=name,
                                   client_type=client_type,
                                   authorization_grant_type=auth_grant_type,
                                   user=user.user)
            app.save()
            oauth_app = OauthApp(name=name, application=app, user=user)
            oauth_app.save()
            return Response(OauthAppSerializer(oauth_app).data)

        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Пример #2
0
    def post(self, request):
        with self._handle_exception(request):
            name = request.data.get("name")
            username = request.user.username
            if OauthApp.objects.filter(name=name).exists():
                e_msg = ("Application with name ({}) already exists. Choose a "
                         "different name.").format(name)
                handle_exception(Exception(e_msg), request, status_code=400)

            try:
                user = User.objects.get(username=username)
            except:
                e_msg = "User with name ({}) does not exist.".format(username)
                handle_exception(Exception(e_msg), request)

            client_type = OauthApplication.CLIENT_CONFIDENTIAL
            auth_grant_type = OauthApplication.GRANT_CLIENT_CREDENTIALS
            app = OauthApplication(
                name=name,
                client_type=client_type,
                authorization_grant_type=auth_grant_type,
                user=user.user,
            )
            app.save()
            oauth_app = OauthApp(name=name, application=app, user=user)
            oauth_app.save()
            return Response(OauthAppSerializer(oauth_app).data)
Пример #3
0
    def post(self, request):
        try:
            name = request.DATA['name']
            username = request.user.username
            if (OauthApp.objects.filter(name=name).exists()):
                e_msg = ('application with name: %s already exists.' % name)
                handle_exception(Exception(e_msg), request)

            try:
                user = User.objects.get(username=username)
            except:
                e_msg = ('User with name: %s does not exist' % username)
                handle_exception(Exception(e_msg), request)

            client_type = OauthApplication.CLIENT_CONFIDENTIAL
            auth_grant_type = OauthApplication.GRANT_CLIENT_CREDENTIALS
            app = OauthApplication(name=name, client_type=client_type,
                                   authorization_grant_type=auth_grant_type,
                                   user=user.user)
            app.save()
            oauth_app = OauthApp(name=name, application=app, user=user)
            oauth_app.save()
            return Response(OauthAppSerializer(oauth_app).data)

        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Пример #4
0
    def post(self, request):
        setup = Setup.objects.all()[0]
        setup.setup_user = True
        setup.save()

        # Create user
        res = super(SetupUserView, self).post(request)
        # Create cliapp id and secret for oauth
        name = "cliapp"
        user = User.objects.get(username=request.DATA["username"])
        client_type = OauthApplication.CLIENT_CONFIDENTIAL
        auth_grant_type = OauthApplication.GRANT_CLIENT_CREDENTIALS
        app = OauthApplication(
            name=name, client_type=client_type, authorization_grant_type=auth_grant_type, user=user.user
        )
        app.save()
        oauth_app = OauthApp(name=name, application=app, user=user)
        oauth_app.save()
        return res
Пример #5
0
    def post(self, request):
        setup = Setup.objects.all()[0]
        setup.setup_user = True
        setup.save()

        # Create user
        res = super(SetupUserView, self).post(request)
        # Create cliapp id and secret for oauth
        name = 'cliapp'
        user = User.objects.get(username=request.DATA['username'])
        client_type = OauthApplication.CLIENT_CONFIDENTIAL
        auth_grant_type = OauthApplication.GRANT_CLIENT_CREDENTIALS
        app = OauthApplication(name=name,
                               client_type=client_type,
                               authorization_grant_type=auth_grant_type,
                               user=user.user)
        app.save()
        oauth_app = OauthApp(name=name, application=app, user=user)
        oauth_app.save()
        return res
Пример #6
0
    def post(self, request):
        with self._handle_exception(request):
            name = request.data.get('name')
            username = request.user.username
            if (OauthApp.objects.filter(name=name).exists()):
                e_msg = ('Application with name ({}) already exists. Choose a '
                         'different name.').format(name)
                handle_exception(Exception(e_msg), request, status_code=400)

            try:
                user = User.objects.get(username=username)
            except:
                e_msg = 'User with name ({}) does not exist.'.format(username)
                handle_exception(Exception(e_msg), request)

            client_type = OauthApplication.CLIENT_CONFIDENTIAL
            auth_grant_type = OauthApplication.GRANT_CLIENT_CREDENTIALS
            app = OauthApplication(name=name, client_type=client_type,
                                   authorization_grant_type=auth_grant_type,
                                   user=user.user)
            app.save()
            oauth_app = OauthApp(name=name, application=app, user=user)
            oauth_app.save()
            return Response(OauthAppSerializer(oauth_app).data)