Example #1
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))
Example #2
0
File: grant.py Project: Acen/core
 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
         )
Example #3
0
 def passwd(self, password):
     u = user._current_obj()
     
     try:
         u.password = password
         u.save()
     except:
         log.exception("Error attempting to assign password.")
         return 'json:', dict(success=False, message="Something terrible happened.")
     
     return 'json:', dict(success=True)
Example #4
0
    def put(self):
        if not self.char.owner or self.char.owner.id != user.id:
            raise HTTPNotFound()
        
        u = user._current_obj()
        u.primary = self.char
        u.save()

        if request.is_xhr:
            return 'json:', dict(success=True)

        raise HTTPFound(location='/character/')
Example #5
0
File: manage.py Project: Acen/core
 def get(self):
     if user.admin:
         adminRecords = {record for record in Application.objects() if record.owner != user._current_obj()}
     else:
         adminRecords = {}
     
     records = Application.objects(owner=user._current_obj())
     
     if request.is_xhr:
         return 'brave.core.template.form', dict(
                 kind = _("Application"),
                 form = manage_form(),
                 data = None,
             )
     
     return 'brave.core.application.template.manage_apps', dict(
             area = 'apps',
             records = records,
             adminRecords = adminRecords
         )
Example #6
0
 def post(self, ar, grant=None, character=None):
     from brave.core.character.model import EVECharacter
     from brave.core.application.model import ApplicationGrant
     
     ar = self.ar(ar)
     u = user._current_obj()
     
     if not grant:
         # Deny access.
         ar.user = u
         ar.grant = None
         ar.expires = datetime.utcnow() + timedelta(minutes=10)  # extend to allow time for verification
         ar.save()
         
         target = URL(ar.failure)
         target.query.update(dict(token=str(ar.id)))
         
         return 'json:', dict(success=True, location=str(target))
     
     try:
         character = EVECharacter.objects.get(owner=u, id=character)
     except EVECharacter.DoesNotExist:
         return 'json:', dict(success=False, message="Unknown character ID.")
     except:
         log.exception("Error loading character.")
         return 'json:', dict(success=False, message="Error loading character.")
     
     # TODO: Non-zero grants.
     grant = ApplicationGrant(user=u, application=ar.application, mask=0, expires=datetime.utcnow() + timedelta(days=30), character=character)
     grant.save()
     
     ar.user = u
     ar.grant = grant
     ar.expires = datetime.utcnow() + timedelta(minutes=10)  # extend to allow time for verification
     ar.save()
     
     target = URL(ar.success)
     target.query.update(dict(token=str(grant.id)))
     return 'json:', dict(success=True, location=str(target))
Example #7
0
File: manage.py Project: Acen/core
 def post(self, **kw):
     if not request.is_xhr:
         raise HTTPNotFound()
     
     u = user._current_obj()
     valid, invalid = manage_form().native(kw)
     
     app = Application(owner=u, **{k: v for k, v in valid.iteritems() if k in ('name', 'description', 'groups', 'site', 'contact')})
     
     app.key.public = valid['key']['public']
     app.mask.required = valid['required'] or 0
     app.mask.optional = valid['optional'] or 0
     
     if valid['development'] == "true" or valid['development'] == "True":
         app.development = True
     else:
         app.development = False
     
     app.save()
     
     return 'json:', dict(
             success = True,
             location = '/application/manage/'
         )