Exemplo n.º 1
0
    def test_updating(self):

        up = users.update().where(users.c.username == u"konrad").values(email = "*****@*****.**")
        self.conn.execute(up)
        sel = select([users]).where(users.c.username == u"konrad")
        res = self.conn.execute(sel).fetchone()
        self.assertEquals(res[4], "*****@*****.**")

        #check updating with empyt value doenst work
        
        #!!TODO - implement validator
        up = users.update().where(users.c.username == u"konrad").values(email = "")
        self.conn.execute(up)
Exemplo n.º 2
0
 def update_user(self, identifier, data, uuid = True):
     """
     Updates user values with given data
     
     Keyword Arguments:
     identifier -- unique user\'s uuid (if uuid = True) or username,
     data -- dictionary containg {field_name : value} (dict)
     """
     if uuid:
         haystack = users.c.user_uuid
     else:
         haystack = users.c.username
     items_to_update = dict()
     for key, value in data.items():
         if key in CUSTOM_USER_FIELDS:
             items_to_update[key] = value
     update_q = users.update()\
             .where(haystack == identifier)\
             .values(**items_to_update)
     trans = self.conn.begin()
     try:
         resp = self.conn.execute(update_q)
         trans.commit()
         return resp.last_updated_params()
     except:
         trans.rollback()
         raise
Exemplo n.º 3
0
def update_user(user_id):
    if user_id != request.user.get('id'):
        error = {
            'error': 'Unauthorized'
        }
        resp = jsonify(error)
        resp.status_code = 401
        return resp
    data = json.loads(request.get_data())
    error = validate_for_user(data)
    if error:
        resp = jsonify(error)
        resp.status_code = 400
        return resp
    stmt = users.update()\
        .where(users.c.id == int(user_id))\
        .values(username=data.get('username'), password=data.get('password'))
    conn = engine.connect()
    result = conn.execute(stmt)
    status_code = 200
    if not result.rowcount:
        user_insert = users.insert()\
            .values(username=data.get('username'), password=data.get('password'), id=int(user_id))
        conn.execute(user_insert)
        status_code = 201
    conn.close()
    res = {
        'id': user_id
    }
    resp = jsonify(res)
    resp.status_code = status_code
    return resp
Exemplo n.º 4
0
 def update_user(self, identifier, data, uuid=True):
     """
     Updates user values with given data
     
     Keyword Arguments:
     identifier -- unique user\'s uuid (if uuid = True) or username,
     data -- dictionary containg {field_name : value} (dict)
     """
     if uuid:
         haystack = users.c.user_uuid
     else:
         haystack = users.c.username
     items_to_update = dict()
     for key, value in data.items():
         if key in CUSTOM_USER_FIELDS:
             items_to_update[key] = value
     update_q = users.update()\
             .where(haystack == identifier)\
             .values(**items_to_update)
     trans = self.conn.begin()
     try:
         resp = self.conn.execute(update_q)
         trans.commit()
         return resp.last_updated_params()
     except:
         trans.rollback()
         raise
Exemplo n.º 5
0
def new_user(user_id=None):
    data = dict()
    if user_id:
        user = User.get_by_id(user_id)
        if user is None:
            flash("No se ha encontrado el usuario", "error")
        else:
            data = {
                'user_name': user.get("user_name"),
                'user_login': user.get("user_login"),
                'user_role': user.get("user_role"),
                'editando': True
            }
    if request.method == 'POST':
        data = {
            'user_name': request.form.get("user_name"),
            'user_login': request.form.get("user_login"),
            'user_role': request.form.get("user_role")
        }
        if user_id is None:
            if User.get_by_username(data.get("user_login")) is None:
                new = users.insert(data).execute()
                flash("Usuario agregado correctamente", "success")
            else:
                flash("Este usuario ya existe", "error")
        else:
            users.update().where(users.c.user_id == user_id).\
                           values({'user_login': data.get("user_login"),
                                   'user_name': data.get("user_name"),
                                   'user_role': data.get("user_role")
                                   }
                                  ).execute()
            data['editando'] = True
            flash("Usuario actualizado correctamente", "success")
        if len(request.form.get("user_pass")) > 0 and data.get("editando"):
            User.set_password(data.get("user_login"),
                              request.form.get("user_pass"))
            flash(u"Contraseña actualizada correctamente", "success")

    return render_template('auth/create_user.html', **data)
Exemplo n.º 6
0
def update_user(conn, session, client, body):
    user = body['user']
    conn.execute(users.update().where(users.c.id == user['id']).values(
        name=user['name']))

    conn.execute(
        users_roles.delete().where(users_roles.c.user_id == user['id']))

    users_roles_values = list(
        map(lambda role: {
            'user_id': user['id'],
            'role_id': role['id']
        }, user['roles']))
    conn.execute(users_roles.insert().values(users_roles_values))

    client.publish('userUpdated', json.dumps({'status': 'success'}), qos=1)
Exemplo n.º 7
0
async def update_user(request):
    try:
        data = await request.json()
        async with request.app['db'].acquire() as conn:
            all_columns = users.columns.keys()
            for key in data.keys():
                if key not in all_columns or not data[key]:
                    return aiohttp.web.HTTPBadRequest(
                        text=f'not valid param {key.upper()}')
            raw_query = await conn.fetch(
                users.update().where(users.c.id == int(data['id'])).values(
                    surname=data['surname'],
                    patronymic=data['patronymic'],
                    gender=data['gender']))
            return aiohttp.web.HTTPCreated()
    except Exception:
        return aiohttp.web.HTTPBadRequest()
Exemplo n.º 8
0
def store_user(id):
    users.update(request.json, id)
    return 'update!'
Exemplo n.º 9
0
 def set_password(cls, username, newPassword):
     password_salt = current_app.config["PASSWORD_SALT"]
     new_password_salt = crypt.crypt(newPassword, password_salt)
     update = users.update().where(users.c.user_login == username).\
                             values(user_pass=new_password_salt).execute()