示例#1
0
    def update_user(self, username: str, user: domain.User):
        user.id = None
        with get_session() as session:
            if not self.user_exists(session, username):
                raise UserNotFoundException

            session.query(entities.User) \
                .filter(entities.User.username == username) \
                .update(user.to_dict())
            session.commit()
示例#2
0
def listusers_get():
    """
    List users
    Get all the users 

    :rtype: List[User]
    """
    u1 = User("foo")
    u2 = User("bar")
    return [u1, u2]
def users_post(body):  # noqa: E501
    """Create a new user.

     # noqa: E501

    :param body: The user to create
    :type body: dict | bytes

    :rtype: User
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501
    response = service.users.create(body.to_dict())
    return User.from_dict(response)
示例#4
0
def get_user_bykey(key, userID):
    if key in connects:
        conp = connects[key]
        hd = conp['hd']
        sBuf = create_string_buffer(512 * 1024)
        sTableName = bytes('user', encoding="utf8")
        sFieldNames = bytes('Pin\tCardNo\tPassword', encoding="utf8")
        sFilters = bytes('Pin={}'.format(userID), encoding="utf8")
        sOptions = bytes('', encoding="utf8")
        re = dll.GetDeviceData(hd, sBuf, 512 * 1024,
                               sTableName, sFieldNames, sFilters, sOptions)
        if re < 1: 
            return -3, re

        st = str(sBuf.value)[2:-1]
        va = st.split("\\r\\n")[1].split(',')
        user = User(va[0],'',va[2],int(va[1]))

        sBuf = create_string_buffer(128 * 1024)
        sTableName = bytes('userauthorize', encoding="utf8")
        sFieldNames = bytes('Pin\tAuthorizeTimezoneId\tAuthorizeDoorId', 
                                encoding="utf8")
        reAuthorize = dll.GetDeviceData(hd, sBuf, 128 * 1024,
                               sTableName, sFieldNames, sFilters, sOptions)
        if reAuthorize > 0:
            st = str(sBuf.value)[2:-1]
            va = st.split("\\r\\n")[1].split(',')
            vi = int(va[2])
            user.authorize = [(vi & 1) > 0, (vi & 2) > 0,
                              (vi & 4) > 0, (vi & 8) > 0]
        
        sBuf = create_string_buffer(1 * 1024 * 1024)
        sTableName = bytes('templatev10', encoding="utf8")
        sFieldNames = bytes('Pin\tSize\tFingerID\tValid\tTemplate',
                            encoding="utf8")
        reTemplate = dll.GetDeviceData(hd, sBuf, 1024 * 1024,
                                        sTableName, sFieldNames, sFilters, sOptions)
        if reTemplate > 0:
            st = str(sBuf.value)[2:-1]
            la = st.split("\\r\\n")[1:-1]
            user.finger = []
            for l in la:
                va = l.split(',')
                user.finger.append(UserFinger(int(va[2]), int(
                    va[1]), int(va[3]) == 3, va[4]))

        return 1, user
    else:
        return -4, None
def users_id_patch(id, body):  # noqa: E501
    """Edit a user&#39;s information; at the moment of writing, its pass.

     # noqa: E501

    :param id: 
    :type id: str
    :param body: user properties to be updated; at the moment of writing, its pass.
    :type body: dict | bytes

    :rtype: User
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501
    response = service.users.update(id, body.to_dict())
    return User.from_dict(response)
def project_by_project_id_and_task_id_put(project_id, task_id):  # noqa: E501
    """project_project_id_task_id_put

    Assign a task to a user # noqa: E501
    :param project_id: ID of project to delete
    :type project_id: str
    :param task_id: ID of task to be updated
    :type task_id: str

    :rtype: None
    """
    try:
        if connexion.request.is_json:
            user_list = connexion.request.get_json()
            for key in user_list:
                user = User.from_dict(key)
                value_user = {user.username :  True}
                ref.child("projects/-%s/task_user/-%s" %(project_id, task_id)).update(value_user)

                value_project = {task_id: True}
                ref.child("projects/-%s/user_task/%s" %(project_id, user.username)).update(value_project)
            res = {"response":"Successful inserted %s user to task %s  in project %s " % (len(user_list), task_id,  project_id)}
        else:
            res = {"response":"Invalid Json body"}
    except:
        res = {"response":"Failure in inserting users to project id %s and task id %s " %(project_id, task_id)}

    return res
示例#7
0
def get_user_by_name(username):  # noqa: E501
    """Get user by user name

     # noqa: E501

    :param username: The name that needs to be fetched. Use user1 for testing. 
    :type username: str

    :rtype: User
    """
    try:
        logging.info("Getting username %s", username)
        user = globals.db_session.query(orm.Userinfo).filter(
            orm.Userinfo.dao_username == username).first()
        logging.debug("Got username %s response %s", username, user.__dict__)
        if user is not None:
            return User.from_dict(
                dict(id=user.id,
                     username=user.dao_username,
                     firstname=user.dao_firstname,
                     email=user.dao_email,
                     lastName=user.dao_lastname)), 200
        else:
            return "User not found", 404
    except Exception as e:
        logging.error(e)

    return "Invalid username supplied", 400
def update_user(body, username):  # noqa: E501
    """Actualiza los datos del usuario

     # noqa: E501

    :param body: Usuario actualizado
    :type body: dict | bytes
    :param username: nombre del usuario que va a ser actualizado
    :type username: str

    :rtype: None
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501
        collection = db.user
        myquery = {"username": username}
        newvalues = {
            "$set": {
                'id': body.id,
                'username': body.username,
                'firstName': body.first_name,
                'lastName': body.last_name,
                'email': body.email,
                'password': body.password,
                'phone': body.phone
            }
        }

        collection.update_one(myquery, newvalues)
    return 'OK'
示例#9
0
def create_user(body):  # noqa: E501
    """Create user

    This can only be done by the logged in user. # noqa: E501

    :param body: Created user object
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501
    try:
        user = {
            "id": body.id,
            "dao_username": body.username,
            "dao_firstname": body.first_name,
            "dao_lastname": body.last_name,
            "dao_email": body.email,
            "dao_password": util.generate_hash(body.password)
        }
        if user is not None:
            logging.info("Adding user %s", user)
            globals.db_session.add(orm.Userinfo(**user))
            globals.db_session.commit()
            logging.info("user commit %s successful", user)
            return "User added", 200

    except Exception as e:
        logging.error(e)

    return NoContent, 404
示例#10
0
def add_user(user=None):
    # ok
    if connexion.request.is_json:
        user = User.from_dict(user)

    users.insert(user.to_dict())
    return user
示例#11
0
def create_user(body):  # noqa: E501
    """Create user

    Role write:users role must be granted # noqa: E501

    :param body: Created user object
    :type body: dict | bytes

    :rtype: UserSafe
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501
    orm = User_orm(username=body.username,
                   password=auth.generate_password_hash(body.password),
                   email=body.email,
                   roles=body.roles if body.roles else '')
    # check username already exists
    found = dao.get_by_name(body.username)
    if found is not None:
        return ErrorApiResponse.UsernameExistError(body.username), 409
    # check email already exists
    found = dao.get_by_email(body.email)
    if found is not None:
        return ErrorApiResponse.UseremailExistError(body.email), 409
    try:
        dao.persist(orm)
        return get_user_by_name(body.username)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex), 500
示例#12
0
def patch_user(id, body):  # noqa: E501
    """Updated user password

    This can only be done by with write:users role. # noqa: E501

    :param id: The id of user that needs to be updated
    :type id: int
    :param body: Updated user object
    :type body: dict | bytes

    :rtype: UserSafe
    """
    found = dao.get(id)
    if found is None:
        return ErrorApiResponse.UserNotFoundError(id=id), 404
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501

    # update only password
    found.password = auth.generate_password_hash(body.password)
    try:
        dao.persist(found)
        return get_user_by_id(id)
    except Exception as ex:
        return ErrorApiResponse.InternalServerError(ex), 500
def create_user(body):
    global user_last_id
    global user_data
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())
    body.id = user_last_id
    user_last_id += 1
    user_data[body.id] = body
    return None, HTTPStatus.CREATED.value, CORS
def update_user(body, user_id):
    global user_data
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())
    body.id = user_id
    if body.id in user_data:
        user_data[body.id] = body
        return None, HTTPStatus.RESET_CONTENT.value, CORS
    else:
        return None, HTTPStatus.NOT_FOUND.value, CORS
def users_get():  # noqa: E501
    """List all API users created by the administrator. One of the users is flagged as the administrator; that is the very first user created and may not be deleted.

     # noqa: E501


    :rtype: List[User]
    """
    response = service.users.read_all()
    output = [User().from_dict(doc) for doc in response]
    return output
    def test_create_users_with_list_input(self):
        """Test case for create_users_with_list_input

        Creates list of users with given input array
        """
        body = [User()]
        response = self.client.open('/user/createWithList',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def create_users_with_list_input(body):
    """
    Creates list of users with given input array
    
    :param body: List of user object
    :type body: list | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = [User.from_dict(d) for d in connexion.request.get_json()]
    return "do some magic!"
示例#18
0
def create_user(body):
    """
    Create user
    This can only be done by the logged in user.
    :param body: Created user object
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())
    return 'do some magic!'
def add_user(body):  # noqa: E501
    body = User.from_dict(connexion.request.get_json())
    sql = "Insert into users(uid,firstname,lastname) values(%s,%s,%s)"
    data = (body.uid, body.first_name, body.last_name)
    db_connection = mysql.connector.connect(host="localhost",
                                            user="******",
                                            passwd="Trinity@123",
                                            database="UID")
    conn = db_connection.cursor()
    conn.execute(sql, data)
    db_connection.commit()
    return 'Record Inserted'
    def test_create_user(self, *_):
        """Test case for create_user


        """
        user = User(email="*****@*****.**", password="******")
        response = self.client.open('/api/v1/user/create',
                                    method='POST',
                                    data=json.dumps(user),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_update_user(self):
        """Test case for update_user

        Updated user
        """
        body = User()
        response = self.client.open('/vcalendar/user/{id}'.format(id=789),
                                    method='PUT',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
示例#22
0
    def test_add_user(self):
        """Test case for add_user

        Add a new user to the validator Application
        """
        body = User()
        response = self.client.open('/validator/users',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
示例#23
0
def create_users_with_list_input(body):
    """
    Creates list of users with given input array
    
    :param body: List of user object
    :type body: list | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = [User.from_dict(d) for d in connexion.request.get_json()]
    return 'do some magic!'
def create_user(body):
    """
    Create user
    This can only be done by the logged in user.
    :param body: Created user object
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())
    return "do some magic!"
    def test_create_user(self):
        """Test case for create_user

        Create user
        """
        body = User()
        response = self.client.open('/user',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_create_user(self):
        """Test case for create_user

        Crea un nuevo usuario en el sistema
        """
        body = User()
        response = self.client.open('/javierrome/PlatformAPI/1.0.0/user',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_user_create(self):
        """Test case for user_create

        
        """
        name = User()
        response = self.client.open('//users/',
                                    method='POST',
                                    data=json.dumps(name),
                                    content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
    def test_subsidies_id_actions_approve_post(self):
        """Test case for subsidies_id_actions_approve_post

        Approve a subsidy
        """
        body = User()
        response = self.client.open(
            '/v1/subsidies/{id}/actions/approve'.format(id='id_example'),
            method='POST',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v1.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
示例#29
0
def create_user(body):  # noqa: E501
    """Create user

    This can only be done by the logged in user. # noqa: E501

    :param body: Created user object
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())  # noqa: E501
    return flask.Response(status=403)
示例#30
0
    def test_users_username_put(self):
        """Test case for users_username_put

        Re-upload user's information
        """
        body = User()
        response = self.client.open(
            '/v1/users/{username}'.format(username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/nl.kpmg.v1.user+json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
示例#31
0
def user_create(name=None):  # noqa: E501
    """user_create

    Create a new user # noqa: E501

    :param name: The name of the person
    :type name: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        name = User.from_dict(connexion.request.get_json())  # noqa: E501
    return 'do some magic!'
    def test_user_username_put(self):
        """Test case for user_username_put

        Updated user
        """
        body = User()
        response = self.client.open(
            '/user/{username}'.format(username='******'),
            method='PUT',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
def update_user(username, body):
    """
    Updated user
    This can only be done by the logged in user.
    :param username: name that need to be deleted
    :type username: str
    :param body: Updated user object
    :type body: dict | bytes

    :rtype: None
    """
    if connexion.request.is_json:
        body = User.from_dict(connexion.request.get_json())
    return "do some magic!"