Exemple #1
0
def delete():
    user = UserModel.get_one_user(g.user.get('id'))
    if not user:
        return custom_response({'error': 'User not found.'}, 404)
    google.delete_user_google(str(g.user.get('id')))
    user.delete()
    return custom_response({'message': 'deleted'}, 204)
Exemple #2
0
def google_login():
    google_auth = google.get_google_auth(token=request.get_json())
    resp = google_auth.get(google.USER_INFO)
    if resp.status_code == 200:
        user_data = resp.json()
        data = {
            'firstname': user_data['given_name'],
            'lastname': user_data['family_name'],
            'email': user_data['email'],
            'picture': user_data['picture'],
            'password': '******'
        }
        user_in_db = UserModel.get_user_by_email(data['email'])
        if user_in_db:
            token = Auth.generate_token(
                user_schema.dump(user_in_db).data.get('id'))
            return custom_response(UserModel.info_user(user_in_db, token), 200)
        user = UserModel(data, 1, "0000-1")
        user.save()
        profile = ProfileModel({}, user.id)
        profile.picture_profile(data.get('picture'), "empty")
        profile.save()
        NotifModel.init_by_user_id(user.id)
        token = Auth.generate_token(user_schema.dump(user).data.get('id'))
        return custom_response(UserModel.info_user(user, token), 200)
    return custom_response("Unauthorized, Could not fetch your information.",
                           400)
Exemple #3
0
def get_video_all_video(id_user):
    video_in_db = VideoModel.get_video_all(id_user)
    if video_in_db:
        list_video = []
        [list_video.append(video_schema.dump(a).data) for a in video_in_db]
        return custom_response({'successful': list_video}, 200)
    return custom_response({'error': 'Video not exist.'}, 400)
def get_audio_all_audio(id_user):
    audio_in_db = AudioModel.get_audio_all(id_user)
    if audio_in_db:
        list_audio = []
        [list_audio.append(audio_schema.dump(a).data) for a in audio_in_db]
        return custom_response({'successful': list_audio}, 200)
    return custom_response({'error': 'Audio not exist.'}, 400)
Exemple #5
0
def upload_video():
    video_storage = request.files.get('video')
    if not video_storage or video_storage.content_type != 'video/mp4':
        return custom_response({'error': 'Is not a mp4 file.'}, 400)
    req_data = request.form.to_dict()
    data, error = video_schema.load(req_data)
    if error:
        return custom_response(error, 400)
    video_in_db = VideoModel.get_video_by_name_and_user(
        video_storage.filename, g.user.get('id'))
    if video_in_db:
        return custom_response({'error': 'Video already exist.'}, 400)
    video_in_db = VideoModel.get_video_by_titre(data.get('titre'))
    if video_in_db:
        return custom_response({'error': 'Titre already exist.'}, 400)
    url = google.store_in_google("space_art_video", str(g.user.get('id')),
                                 video_storage)
    video = VideoModel(data, g.user.get('id'), video_storage.filename, url)
    video.save()
    video_data = {
        'id': video.id,
        'titre': video.titre,
        'description': video.description,
        'url': urllib.parse.unquote(video.url)
    }
    return custom_response({'successful': video_data}, 200)
def upload_audio():
    audio_storage = request.files.get('audio')
    if not audio_storage or audio_storage.content_type != 'audio/mp3' and audio_storage.content_type != 'audio/mpeg':
        return custom_response({'error': 'Is not a mp3 file.'}, 400)
    req_data = request.form.to_dict()
    data, error = audio_schema.load(req_data)
    if error:
        return custom_response(error, 400)
    audio_in_db = AudioModel.get_audio_by_name_and_user(
        audio_storage.filename, g.user.get('id'))
    if audio_in_db:
        return custom_response({'error': 'Audio already exist.'}, 400)
    audio_in_db = AudioModel.get_audio_by_titre(data.get('titre'))
    if audio_in_db:
        return custom_response({'error': 'Titre already exist.'}, 400)
    url = google.store_in_google("space_art_audio", str(g.user.get('id')),
                                 audio_storage)
    audio = AudioModel(data, g.user.get('id'), audio_storage.filename, url)
    audio.save()
    audio_data = {
        'id': audio.id,
        'titre': audio.titre,
        'description': audio.description,
        'url': urllib.parse.unquote(audio.url)
    }
    return custom_response({'successful': audio_data}, 200)
def get_audio_by_id_audio(id_audio):
    audio_in_db = AudioModel.get_audio_by_id(id_audio)
    if audio_in_db:
        ser_audio = audio_schema.dump(audio_in_db).data
        url = ser_audio.get('url')
        result = urllib.parse.unquote(url)
        return custom_response({'successful': {'url': result}}, 200)
    return custom_response({'error': 'Audio not exist.'}, 400)
def all_followers():
    followers_in_db = FollowModel.get_all_followers(g.user.get('id'))
    if followers_in_db:
        li = []
        [li.append(follow_schema.dump(f).data.get('follow_id')) for f in followers_in_db]
        return custom_response({'success': {'followers': li}}, 200)
    else:
        return custom_response({'error': 'Empty.'}, 400)
Exemple #9
0
def refuse_candidate_or_not(cast_id, candidate_id):
    my_cast = CastModel.get_my_cast(cast_id, g.user.get('id'))
    if not my_cast:
        return custom_response({"error": "Cast not found."}, 400)
    candidate = CandidateModel.get_one_candidate_by_cast_id(
        cast_id, candidate_id)
    candidate.update_accepted(2)
    return custom_response({"success": candidate.get_accepted()}, 200)
Exemple #10
0
def get_video_by_id_video(id_video):
    video_in_db = VideoModel.get_video_by_id(id_video)
    if video_in_db:
        ser_video = video_schema.dump(video_in_db).data
        url = ser_video.get('url')
        result = urllib.parse.unquote(url)
        return custom_response({'successful': {'url': result}}, 200)
    return custom_response({'error': 'Video not exist.'}, 400)
Exemple #11
0
def delete_video(id_video):
    video = VideoModel.get_video_by_id(id_video)
    if video.user_id == g.user.get('id'):
        google.delete_in_google("space_art_video", str(g.user.get('id')),
                                video.video_name_storage)
        video.delete()
        return custom_response({'successful': 'Video delete'}, 200)
    return custom_response({'error': 'Is not your Video.'}, 400)
def unfollowing(follow_id):
    if g.user.get('id') == follow_id:
        return custom_response({'error': 'Unfollow failed.'}, 400)
    else:
        follow = FollowModel.get_follow(follow_id, g.user.get('id'))
        if not follow:
            return custom_response({'error': 'User for unfollow not found.'}, 400)
        follow.delete()
        return custom_response({'success': 'unFollow'}, 200)
Exemple #13
0
def update():
    req_data = request.get_json()
    data, error = user_schema.load(req_data, partial=True)
    if error:
        return custom_response(error, 400)
    user = UserModel.get_one_user(g.user.get('id'))
    user.update(data)
    ser_user = user_schema.dump(user).data
    return custom_response(ser_user, 200)
Exemple #14
0
def create_cast():
    req_data = request.get_json()
    data, error = cast_schema.dump(req_data)
    if error:
        return custom_response(error, 400)
    if CastModel.get_one_cast_by_title(data.get('title')):
        return custom_response({"error": "Cast already exist."}, 400)
    cast = CastModel(data, g.user.get('id'))
    cast.save()
    return custom_response({"success": "Cast created."}, 200)
def delete_audio(id_audio):
    audio = AudioModel.get_audio_by_id(id_audio)
    if not audio:
        return custom_response({'error': 'Audio not exist.'}, 400)
    if audio.user_id == g.user.get('id'):
        google.delete_in_google("space_art_audio", str(g.user.get('id')),
                                audio.audio_name_storage)
        audio.delete()
        return custom_response({'successful': 'Audio delete'}, 200)
    return custom_response({'error': 'Is not your Audio.'}, 400)
Exemple #16
0
def get_one_cast(cast_id):
    cast = CastModel.get_one_cast_by_id(cast_id)
    if not cast: return custom_response({'error': 'Casts not found.'}, 400)
    ser_cast = cast_schema.dump(cast).data
    user = UserModel.get_one_user(ser_cast.get('user_id'))
    profile = ProfileModel.get_one_profile(ser_cast.get('user_id'))
    ser_user = user_schema.dump(user).data
    ser_profile = profile_schema.dump(profile).data
    info = {'cast': ser_cast, 'user': ser_user, 'profile': ser_profile}
    return custom_response({"success": info}, 200)
def newfollowing(follow_id):
    @socket.on('my event3')
    def notif_user_follow(json):
        socket.emit(json['user_notif'], json)
        print("follow notif")
    follow = FollowModel.get_follow(follow_id, g.user.get('id'))
    if follow or g.user.get('id') == follow_id:
        return custom_response({'error': 'Follow failed.'}, 400)
    else:
        follow = FollowModel(g.user.get('id'), follow_id)
        follow.save()
        return custom_response({'success': 'New Follow.'}, 200)
Exemple #18
0
def mail_validate():
    req_data = request.get_json()
    users = UserModel.get_one_user(g.user.get('id'))
    tab_validate = list(user_schema.dump(users).data.get('mail_validate'))
    del (tab_validate[5])
    del (tab_validate[4])
    string_validate = "".join(tab_validate)
    print(string_validate + "     " + req_data.get('key_mail'))
    if string_validate == req_data.get('key_mail'):
        users.update_mail("0000-1")
        return custom_response({'success': 'Code valid'}, 200)
    return custom_response({'error': 'Code not valid.'}, 400)
def create_post():
    req_data = request.get_json()
    data, error = post_schema.dump(req_data)
    if error: return custom_response(error, 400)
    post = PostModel(data.get('text'), g.user.get('id'))
    post.save()
    news = NewsfeedModel("post", post.id, g.user.get('id'))
    news.save()
    ser_user = user_schema.dump(UserModel.get_one_user(g.user.get('id'))).data
    ser_profile = profile_schema.dump(
        ProfileModel.get_one_profile(ser_user.get('id'))).data
    dict_news = insert_post(post_schema.dump(post).data)
    dict_news['user'] = insert_user(ser_user, ser_profile)
    return custom_response({'success': dict_news}, 200)
Exemple #20
0
def candidate_cast(cast_id):
    req_data = request.get_json()
    data = candidate_schema.dump(req_data).data
    cast = CastModel.get_one_cast_by_id(cast_id)
    if not cast:
        return custom_response({"error": "Cast not found."}, 400)
    if cast.get_user_id() == g.user.get('id'):
        return custom_response({"error": "Its your cast."}, 400)
    if CandidateModel.get_one_candidate_by_cast_id(cast.get_id(),
                                                   g.user.get('id')):
        return custom_response({"error": "You are already registering."}, 400)
    candidate = CandidateModel(data.get('motivate'), g.user.get('id'), cast_id)
    candidate.save()
    return custom_response({"success": "You are registering."}, 200)
def update_audio_by_id(id_audio):
    req_data = request.get_json()
    data, error = audio_schema.load(req_data, partial=True)
    if error:
        return custom_response(error, 400)
    audio = AudioModel.get_audio_by_id(id_audio)
    audio.update(data)
    audio_data = {
        'id': audio.id,
        'titre': audio.titre,
        'description': audio.description,
        'url': urllib.parse.unquote(audio.url)
    }
    return custom_response({'successful': audio_data}, 200)
Exemple #22
0
def update_video_storage_by_id(id_video):
    video_storage = request.files.get('video')
    if not video_storage or video_storage.content_type != 'video/mp4':
        return custom_response({'error': 'Is not a mp4 file.'}, 400)
    video = VideoModel.get_video_by_id(id_video)
    google.delete_in_google("space_art_video", str(g.user.get('id')),
                            video.video_name_storage)
    url = google.store_in_google("space_art_video", str(g.user.get('id')),
                                 video_storage)
    video.update_url(url, video_storage.filename)
    return custom_response(
        {'successful': {
            'url': urllib.parse.unquote(video.url)
        }}, 200)
def update_audio_storage_by_id(id_audio):
    audio_storage = request.files.get('audio')
    if not audio_storage or audio_storage.content_type != 'audio/mp3' and audio_storage.content_type != 'audio/mpeg':
        return custom_response({'error': 'Is not a mp3 file.'}, 400)
    audio = AudioModel.get_audio_by_id(id_audio)
    google.delete_in_google("space_art_audio", str(g.user.get('id')),
                            audio.audio_name_storage)
    url = google.store_in_google("space_art_audio", str(g.user.get('id')),
                                 audio_storage)
    audio.update_url(url, audio_storage.filename)
    return custom_response(
        {'successful': {
            'url': urllib.parse.unquote(audio.url)
        }}, 200)
def delete_post(post_id):
    post = PostModel.get_one_post_by_user_id(post_id, g.user.get('id'))
    if not post: return custom_response({'error': 'Not your Post'}, 400)
    news = NewsfeedModel.get_one_news_by_user_id(post.get_id(),
                                                 g.user.get('id'))
    if not news: return custom_response({'error': 'Not your News'}, 400)
    likes = LikeModel.get_all_if_liked(post_id)
    for like in likes:
        news_like = NewsfeedModel.get_one_news_by_parent_id(like.get_id())
        if news_like:
            news_like.delete()
        like.delete()
    post.delete()
    news.delete()
    return custom_response({'success': 'Post delete'}, 200)
def deleteallmessage():
    PrivateModel.test()
    array = []
    test = PrivateModel.get_all()
    for t in test:
        array.append(t['users'])
    return custom_response({'success': array}, 200)
def allmessage():
    array = []
    test = PrivateModel.get_all()
    for t in test:
        print(str(t))
        array.append(str(t))
    return custom_response({'success': array}, 200)
Exemple #27
0
def update_picture():
    picture_storage = request.files.get('picture')
    if not picture_storage or picture_storage.content_type != 'image/png' and picture_storage.content_type != 'image/jpeg':
        return custom_response({'error': 'Is not a img/png file.'}, 400)
    profile = ProfileModel.get_one_profile(g.user.get('id'))
    ser_profile = profile_schema.dump(profile).data
    if ser_profile.get('space_art_picture') != "empty":
        google.delete_in_google("space_art_picture", str(g.user.get('id')),
                                ser_profile.get('picture_name_storage'))
    url = google.store_in_google("space_art_picture", str(g.user.get('id')),
                                 picture_storage)
    profile.picture_profile(url, picture_storage.filename)
    return custom_response(
        {'successful': {
            'url': urllib.parse.unquote(profile.picture_url)
        }}, 200)
Exemple #28
0
def get_all_cast():
    casts = CastModel.get_cast_all()
    if not casts: return custom_response({'error': 'Casts not found.'}, 400)
    casts_array = []
    for c in casts:
        ser_cast = cast_schema.dump(c).data
        user = UserModel.get_one_user(ser_cast.get('user_id'))
        profile = ProfileModel.get_one_profile(ser_cast.get('user_id'))
        ser_user = user_schema.dump(user).data
        ser_profile = profile_schema.dump(profile).data
        casts_array.append({
            'cast': ser_cast,
            'user': ser_user,
            'profile': ser_profile
        })
    return custom_response({"success": casts_array}, 200)
def deletenotif():
    NotifModel.test()
    array = []
    test = NotifModel.get_all()
    for t in test:
        array.append(t['users'])
    return custom_response({'success': array}, 200)
def allnotif():
    array = []
    test = NotifModel.get_all()
    for t in test:
        print(str(t))
        array.append(str(t))
    return custom_response({'success': array}, 200)