Exemple #1
0
 def merge(self, other):
     """Consumes other and takes its children."""
     
     other.credentials.update(set__owner=self)
     other.characters.update(set__owner=self)
     
     LoginHistory.objects(user=other).update(set__user=self)
     
     from brave.core.group.model import Group
     from brave.core.application.model import Application, ApplicationGrant
     
     Group.objects(creator=other).update(set__creator=self)
     Application.objects(owner=other).update(set__owner=self)
     ApplicationGrant.objects(user=other).update(set__user=self)
     
     other.delete()
Exemple #2
0
 def get(self, ar):
     from brave.core.application.model import ApplicationGrant
     
     ar = self.ar(ar)
     u = user._current_obj()
     grant = ApplicationGrant.objects(user=u, application=ar.application).first()
     
     if not grant:
         # TODO: We need a 'just logged in' flag in the request.
         
         characters = list(u.characters.order_by('name').all())
         if len(characters):
             default = u.primary or characters[0]
         else:
             return ('brave.core.template.authorize',
             dict(success=False, message=_("This application requires that you have a character connected to your"
                                           " account. Please <a href=\"/key/\">add an API key</a> to your account."),
                  ar=ar))
         return 'brave.core.template.authorize', dict(success=True, ar=ar, characters=characters, default=default)
     
     ngrant = ApplicationGrant(user=u, application=ar.application, mask=grant.mask, expires=datetime.utcnow() + timedelta(days=30), character=grant.character)
     ngrant.save()
     
     ar.user = u
     ar.grant = ngrant
     ar.expires = datetime.utcnow() + timedelta(minutes=10)  # extend to allow time for verification
     ar.save()
     
     r = grant.delete()
     
     target = URL(ar.success)
     target.query.update(dict(token=str(ngrant.id)))
     raise HTTPFound(location=str(target))
Exemple #3
0
    def merge(self, other):
        """Consumes other and takes its children."""

        other.credentials.update(set__owner=self)
        other.characters.update(set__owner=self)

        LoginHistory.objects(user=other).update(set__user=self)

        from brave.core.group.model import Group
        from brave.core.application.model import Application, ApplicationGrant

        Group.objects(creator=other).update(set__creator=self)
        Application.objects(owner=other).update(set__owner=self)
        ApplicationGrant.objects(user=other).update(set__user=self)

        other.delete()
Exemple #4
0
 def get(self):
     records = ApplicationGrant.objects(
             user = user._current_obj()
         ).order_by('-id')
     
     return 'brave.core.application.template.list_grants', dict(
             area = 'apps',
             records = records
         )
Exemple #5
0
    def get(self, ar):
        from brave.core.application.model import ApplicationGrant

        ar = self.ar(ar)
        u = user._current_obj()
        grant = ApplicationGrant.objects(user=u,
                                         application=ar.application).first()

        if not grant:
            # TODO: We need a 'just logged in' flag in the request.

            characters = list(u.characters.order_by('name').all())
            if len(characters):
                default = u.primary or characters[0]
            else:
                return (
                    'brave.core.template.authorize',
                    dict(
                        success=False,
                        message=
                        _("This application requires that you have a character connected to your"
                          " account. Please <a href=\"/key/\">add an API key</a> to your account."
                          ),
                        ar=ar))
            return 'brave.core.template.authorize', dict(success=True,
                                                         ar=ar,
                                                         characters=characters,
                                                         default=default)

        ngrant = ApplicationGrant(user=u,
                                  application=ar.application,
                                  mask=grant.mask,
                                  expires=datetime.utcnow() +
                                  timedelta(days=30),
                                  character=grant.character)
        ngrant.save()

        ar.user = u
        ar.grant = ngrant
        ar.expires = datetime.utcnow() + timedelta(
            minutes=10)  # extend to allow time for verification
        ar.save()

        r = grant.delete()

        target = URL(ar.success)
        target.query.update(dict(token=str(ngrant.id)))
        raise HTTPFound(location=str(target))
Exemple #6
0
    def get(self):
        records = ApplicationGrant.objects(
            user=user._current_obj()).order_by('-id')

        return 'brave.core.application.template.list_grants', dict(
            area='apps', records=records)
Exemple #7
0
 def deauthorize(self, token):
     from brave.core.application.model import ApplicationGrant
     count = ApplicationGrant.objects(id=token,
                                      application=request.service).delete()
     return dict(success=bool(count))
Exemple #8
0
 def grants(self):
     from brave.core.application.model import ApplicationGrant
     return ApplicationGrant.objects(user=self)
Exemple #9
0
 def grants(self):
     from brave.core.application.model import ApplicationGrant
     return ApplicationGrant.objects(user=self)
Exemple #10
0
 def deauthorize(self, token):
     from brave.core.application.model import ApplicationGrant
     count = ApplicationGrant.objects(id=token, application=request.service).delete()
     return dict(success=bool(count))