예제 #1
0
def update_user():
    """
        route pour changer des paramètres d'utilisateur
    """
    req_data = request.get_json()

    id_role = req_data.get("id_role", None)

    if not id_role:

        return {"msg": "Pas d'id_role"}, 400

    role_data = {}
    for att in req_data:
        if hasattr(TRoles, att):
            role_data[att] = req_data[att]

    role = TRoles(**role_data)
    db.session.merge(role)
    db.session.commit()
    role = db.session.query(TRoles).get(id_role)
    return role.as_dict(recursif=True)
예제 #2
0
def insert_one_t_role():
    '''
        Route permettant de créer un utilisateur

        curl --header "Content-Type: application/json" \
        --request POST \
        --data '{"email": "*****@*****.**", "groupe": false, "pn": true, "remarques": "utilisateur test api", "desc_role": null, "prenom_role": "test", "identifiant": "test_api", "id_unite": -1, "id_organisme": -1, "uuid_role": "c8f63c2d-e606-49c5-8865-edb0953c496f", "nom_role": "API", "password": "******", "password_confirmation": "123456", "applications":[{"id_app":2, "id_droit":1}]}' \
        http://localhost:5001/api_register/role
    '''
    req_data = request.get_json()

    role_data = {}
    for att in req_data:
        if hasattr(TRoles, att):
            role_data[att] = req_data[att]

    # Validation email
    if re.search("[@.]", req_data['email']) is None:
        return "email not valid", 500

    role = TRoles(**role_data)

    if req_data['password']:
        role.fill_password(req_data['password'],
                           req_data['password_confirmation'])

    db.session.add(role)
    db.session.commit()

    for app in req_data['applications']:
        cor = CorRoleAppProfil(id_role=role.id_role,
                               id_profil=app['id_profil'],
                               id_application=app['id_app'])
        db.session.add(cor)
        db.session.commit()

    return role.as_dict(recursif=True)