Exemplo n.º 1
0
 def setUp(self):
     super(MusicBrainzViewsTestCase, self).setUp()
     current_app.config[
         'REPLICATION_PACKETS_DIR'] = self.path = tempfile.mkdtemp()
     os.mkdir(os.path.join(self.path, DAILY_SUBDIR))
     os.mkdir(os.path.join(self.path, WEEKLY_SUBDIR))
     self.token = Token.generate_token(owner_id=None)
Exemplo n.º 2
0
 def generate_token(self):
     """Generates new access token for this user."""
     if self.state == STATE_ACTIVE:
         return Token.generate_token(self.id)
     else:
         raise InactiveUserException(
             "Can't generate token for inactive user.")
Exemplo n.º 3
0
 def decorated(*args, **kwargs):
     access_token = request.args.get('token')
     if not access_token:
         return Response("You need to provide an access token!\n", status=400)
     if not Token.is_valid(access_token):
         return Response("Provided access token is invalid!\n", status=403)
     return f(*args, **kwargs)
Exemplo n.º 4
0
 def setUp(self):
     super(MusicBrainzViewsTestCase, self).setUp()
     current_app.config[
         'REPLICATION_PACKETS_DIR'] = self.path = tempfile.mkdtemp()
     current_app.config[
         'JSON_DUMPS_DIR'] = self.json_path = tempfile.mkdtemp()
     self.token = Token.generate_token(owner_id=None)
Exemplo n.º 5
0
 def details(self, user_id):
     user = User.get(id=user_id)
     active_tokens = Token.get_all(owner_id=user.id, is_active=True)
     return self.render(
         'admin/users/details.html',
         user=user,
         active_tokens=active_tokens,
     )
Exemplo n.º 6
0
 def details(self, user_id):
     user = User.get(id=user_id)
     active_tokens = Token.get_all(owner_id=user.id, is_active=True)
     return self.render(
         'admin/users/details.html',
         user=user,
         active_tokens=active_tokens,
     )
Exemplo n.º 7
0
 def decorated(*args, **kwargs):
     access_token = request.args.get('token')
     if not access_token:
         return Response("You need to provide an access token!\n",
                         status=400)
     if not Token.is_valid(access_token):
         return Response("Provided access token is invalid!\n", status=403)
     return f(*args, **kwargs)
Exemplo n.º 8
0
 def after_model_change(self, form, user, is_created):
     if user.state != STATE_ACTIVE:
         Token.revoke_tokens(user.id)
Exemplo n.º 9
0
 def index(self):
     value = request.args.get('value')
     results = Token.search_by_value(value) if value else []
     return self.render('admin/tokens/search.html',
                        value=value,
                        results=results)
Exemplo n.º 10
0
 def revoke_token(self):
     token_value = request.args.get('token_value')
     token = Token.get(value=token_value)
     token.revoke()
     flash.info('Token %s has been revoked.' % token_value)
     return redirect(url_for('.details', user_id=token.owner_id))
Exemplo n.º 11
0
 def revoke_token(self):
     token_value = request.args.get('token_value')
     token = Token.get(value=token_value)
     token.revoke()
     flash.info('Token %s has been revoked.' % token_value)
     return redirect(url_for('.details', user_id=token.owner_id))
Exemplo n.º 12
0
 def token(self):
     return Token.get(owner_id=self.id, is_active=True)
Exemplo n.º 13
0
 def after_model_change(self, form, user, is_created):
     if user.state != STATE_ACTIVE:
         Token.revoke_tokens(user.id)
Exemplo n.º 14
0
 def generate_token(self):
     """Generates new access token for this user."""
     if self.state == STATE_ACTIVE:
         return Token.generate_token(self.id)
     else:
         raise InactiveUserException("Can't generate token for inactive user.")
Exemplo n.º 15
0
 def setUp(self):
     super(MusicBrainzViewsTestCase, self).setUp()
     current_app.config['REPLICATION_PACKETS_DIR'] = self.path = tempfile.mkdtemp()
     current_app.config['JSON_DUMPS_DIR'] = self.json_path = tempfile.mkdtemp()
     self.token = Token.generate_token(owner_id=None)
Exemplo n.º 16
0
 def token(self):
     return Token.get(owner_id=self.id, is_active=True)
Exemplo n.º 17
0
 def setUp(self):
     super(MusicBrainzViewsTestCase, self).setUp()
     current_app.config['REPLICATION_PACKETS_DIR'] = self.path = tempfile.mkdtemp()
     os.mkdir(os.path.join(self.path, DAILY_SUBDIR))
     os.mkdir(os.path.join(self.path, WEEKLY_SUBDIR))
     self.token = Token.generate_token(owner_id=None)
Exemplo n.º 18
0
 def index(self):
     value = request.args.get('value')
     results = Token.search_by_value(value) if value else []
     return self.render('admin/tokens/search.html',
                        value=value, results=results)