Exemplo n.º 1
0
def add_user():
    body = request.get_json()
    print(body)
    email = body.get("email", None)
    _password = body.get("_password", None)
    facebook = body.get("facebook", None)
    instagram = body.get("instagram", None)
    twitter = body.get("twitter", None)
    linkedIn = body.get("linkedIn", None)
    youTube = body.get("youTube", None)
    is_psychologist = body.get("is_psychologist", None)
    description = body.get("description", None)

    if not email or not _password or is_psychologist is None:
        return "Missing info", 400

    password_hashed = generate_password_hash( _password, method='pbkdf2:sha256', salt_length=8)
    user_id = User.add(
        email, 
        password_hashed, 
        facebook,
        instagram, 
        twitter, 
        linkedIn, 
        youTube, 
        is_psychologist, 
        description
    )

    if is_psychologist:
        psychologist =  User_psychologist(
            name = body.get("name"),
            lastname = body.get("lastname"),
            identity_number = body.get("identity_number"),
            association_number = body.get("association_number") ,            
            speciality = body.get("speciality"),
            user_id=user_id
        )
        psychologist.add()
        return jsonify(psychologist.to_dict()), 201

    company =  User_company(
        company_name = body.get("company_name"),
        company_number = body.get("company_number"),
        user_id = user_id
    )
    company.add()
    return jsonify(company.to_dict()), 201
Exemplo n.º 2
0
def handle_login():
    email, _password = request.json.get(
            "email", None
        ), request.json.get(
            "_password", None
        )
    if not email or not _password:
        return "Missing info", 400
    user = User.get_by_email(email)
    if check_password_hash(user._password, _password):
        if user.is_psychologist and user.is_active:
            print(user.is_active)
            user_psy = User_psychologist.get_by_user_id(user.id)
            access_token = create_access_token(
                identity=user_psy.to_dict(),
                expires_delta=timedelta(minutes=60)
            )
            return jsonify({'token': access_token}), 200
        elif user.is_active:
            user_company = User_company.get_by_user_id(user.id)
            access_token = create_access_token(
                identity=user_company.to_dict(),
                expires_delta=timedelta(minutes=60)
            )
            return jsonify({'token': access_token}), 200
    return "Invalid info", 400
Exemplo n.º 3
0
def get_user(id):
    user = User.get_by_id(id)
    user_psychologist = User_psychologist.get_by_user_id(user.id)
    user_company = User_company.get_by_user_id(user.id)
    if user.is_active and user.is_psychologist:
        return jsonify(user_psychologist.to_dict()), 200
    if user.is_active and user.is_psychologist == False:
        return jsonify(user_company.to_dict()), 200
Exemplo n.º 4
0
def update_users(id):
    body = request.get_json()
    user = User.update_single_user(body, id)
    if user.is_active and user.is_psychologist:
        user_psy = User_psychologist.update_psychologist_user(body, id)
        return jsonify(user_psy.to_dict())  
    if user.is_active and user.is_psychologist == False:
        user_comp = User_company.update_company_user(body, id)
        print(user_comp)
        return jsonify(user_comp.to_dict())
Exemplo n.º 5
0
def add_search_workshop(id):
    user_company = User_company.get_by_id(id)

    body = request.get_json()

    new_search_workshop = Search_workshop(duration=body.get("duration"),
                                          max_price=body.get("price"),
                                          date=body.get("date"),
                                          max_people=body.get("max_people"),
                                          user_company_id=user_company.id,
                                          category_id=body.get("category_id"))

    new_search_workshop.add()

    return jsonify(new_search_workshop.to_dict()), 201
Exemplo n.º 6
0
def update_company_user(id):
    body = request.get_json()
    user = User_company.update_company_user(body, id)
    change_user = User_company.get_by_id(id)
    return jsonify(change_user.to_dict())