Пример #1
0
    def get(self):
        """Return the access token. User and password must be present in the
        headers via Basic Auth."""
        self._log.debug('Authorization = {auth}'.format(
            auth=request.authorization))

        if not request.authorization:
            raise TagalleryMissingLoginInformationException()

        auth = request.authorization
        if not auth.username or not auth.password:
            raise TagalleryMissingLoginInformationException()

        cyphered = crypto(auth.username, auth.password)
        user = User.objects(login=auth.username, password=cyphered).first()
        if not user:
            self._log.debug('Cant find the user')
            raise TagalleryNoSuchUserException()

        self._log.debug('User = {user}'.format(user=user))

        token = str(uuid.uuid4())
        user.token = token
        user.save()

        return jsonify(status='OK',
                       token=token)
Пример #2
0
    def get(self):
        """Return the access token. User and password must be present in the
        headers via Basic Auth."""
        self._log.debug("Authorization = {auth}".format(auth=request.authorization))

        if not request.authorization:
            raise TagalleryMissingLoginInformationException()

        auth = request.authorization
        if not auth.username or not auth.password:
            raise TagalleryMissingLoginInformationException()

        cyphered = crypto(auth.username, auth.password)
        user = User.objects(login=auth.username, password=cyphered).first()
        if not user:
            self._log.debug("Cant find the user")
            raise TagalleryNoSuchUserException()

        self._log.debug("User = {user}".format(user=user))

        token = str(uuid.uuid4())
        user.token = token
        user.save()

        return jsonify(status="OK", token=token)
Пример #3
0
 def add_user(self, username='******', password='******',
              with_token=False):
     """Add a new user directly into the database."""
     token = None
     user = User(login=username, password=crypto(username, password))
     if with_token:
         token = str(uuid.uuid4())
         user.last_token = token
     user.save()
     return token
Пример #4
0
def adduser(user, password):
    """Add a new administrator."""
    if not user or not password:
        print 'Username and password are required'
        return

    from api.server import User

    # from pony.orm import db_session
    # from pony.orm import commit

    # with db_session:
    #     User(login=user, password=crypto(user,
    #                                      password))
    #     commit()

    user = User(login=user, password=crypto(user, password))
    user.save()