def UsersRegistry(): name = str(request.form['name']).strip().title() surname = str(request.form['surname']).strip().title() email = str(request.form['email']).strip().lower() session['name'] = name session['surname'] = surname session['email'] = email if request.form['password1'] == request.form['password2'] and len( str(request.form['password1'])) >= 5: password = sha256_crypt.hash(str(request.form['password1'])) else: flash("Os critérios para criação de senha não foram respeitados.", 'warning') return redirect(url_for('log.newAccount')) if UsersRepository().FindByEmail(email): flash('E-Mail já cadastrado, tente outro', 'info') return redirect(url_for('log.newAccount')) else: UsersRepository().New(name, surname, password, email) if UsersRepository().FindByEmail(email): flash("Usuário criado com sucesso.", 'success') else: flash("Algo deu errado, por favor, tente novamente", 'danger') CleanLoginItens() return redirect(url_for('log.login'))
def filterTrack(): if 'id' not in session: session['id'] = '' spotifyTrack = [] users = UsersRepository().List() reviewsTrack = ResenhaRepository().List('track') for item in reviewsTrack: spotifyTrack.append(SpotifyGetOneTrack(item.spotify_id).oneTrack) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('filters/filterTracks.html', reviewsTrack=reviewsTrack, spotifyTrack=spotifyTrack, users=users, comments=comments, notifyComment=notifyComment, notifyLike=notifyLike, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll) else: return render_template('filters/filterTracks.html', reviewsTrack=reviewsTrack, spotifyTrack=spotifyTrack, users=users)
def resenhaEdit(id): data = ResenhaRepository().FindById(id) spotifyId = data.spotify_id if data.tipo_review == 'artista': spotify = SpotifyGetOneArtist(spotifyId).oneArtist elif data.tipo_review == 'album': spotify = SpotifyGetOneAlbum(spotifyId).oneAlbum elif data.tipo_review == 'track': spotify = SpotifyGetOneTrack(spotifyId).oneTrack else: spotify = SpotifyGetOnePlaylist(spotifyId).onePlaylist if session['id'] != data.author_id: return redirect(url_for('ind.home')) else: voltarButton = request.headers.get("Referer") if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaEdit.html', data=data, spotify=spotify, voltarButton=voltarButton, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaEdit.html', data=data, spotify=spotify, voltarButton=voltarButton)
def index(): if 'id' not in session: __createSessionVariables() spotifyArtist = [] spotifyAlbum = [] spotifyTrack = [] spotifyPlaylist = [] users = UsersRepository().List() reviewsArtist = ResenhaRepository().List('artista', 6) reviewsAlbum = ResenhaRepository().List('album', 6) reviewsTrack = ResenhaRepository().List('track', 6) reviewsPlaylist = ResenhaRepository().List('playlist', 6) for item in reviewsArtist: spotifyArtist.append(SpotifyGetOneArtist(item.spotify_id).oneArtist) for item in reviewsAlbum: spotifyAlbum.append(SpotifyGetOneAlbum(item.spotify_id).oneAlbum) for item in reviewsTrack: spotifyTrack.append(SpotifyGetOneTrack(item.spotify_id).oneTrack) for item in reviewsPlaylist: spotifyPlaylist.append( SpotifyGetOnePlaylist(item.spotify_id).onePlaylist) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('index.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='index', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('index.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='index')
def editAccount(): if session['email'] == '' or 'email' not in session: flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('ind.home')) else: if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId( session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById( session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('account/editAccount.html', user=UsersRepository().FindById( session['id']), comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('account/editAccount.html', user=UsersRepository().FindById( session['id']))
def resetEmailPass(): if not UsersRepository().FindByEmail(request.form['email']): session['email'] = request.form['email'] flash('e-Mail não encontrado', 'info') return redirect(url_for('use.resetPass')) else: user = UsersRepository().FindByEmail(request.form['email']) tempPass = str(get_random_string()) UsersRepository().ResetPassword(user.email, sha256_crypt.hash(str(tempPass))) EmailPassword(user.email, user.name, tempPass) flash("Senha enviada para email cadastrado", 'success') return redirect(url_for('log.login'))
def resenhado(id): if 'id' not in session: session['id'] = '' data = ResenhaRepository().FindById(id) spotifyId = data.spotify_id if data.tipo_review == 'artista': spotify = SpotifyGetOneArtist(spotifyId).oneArtist elif data.tipo_review == 'album': spotify = SpotifyGetOneAlbum(spotifyId).oneAlbum elif data.tipo_review == 'track': spotify = SpotifyGetOneTrack(spotifyId).oneTrack else: spotify = SpotifyGetOnePlaylist(spotifyId).onePlaylist user_author = UsersRepository().FindById(data.author_id) date = DateConversion(str(data.date_register)) like = CurtidasRepository().CountLikes(id).count commentsList = CommentsRepository().List(id) comment_user = UsersRepository().List() try: if CurtidasRepository().FindById(session['id'], id): PNG = 'unclick' else: PNG = 'click' except: PNG = 'click' if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhado.html', data=data, spotify=spotify, user_author=user_author, date=date, commentsList=commentsList, comment_user=comment_user, like=like, PNG=PNG, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhado.html', data=data, spotify=spotify, user_author=user_author, date=date, commentsList=commentsList, comment_user=comment_user, like=like, PNG=PNG)
def resenhaListArtist(): artists = SpotifyGetFiveArtists(request.form['artist']).listArtists session['resenhaArtist'] = request.form['artist'] if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListArtist.html', artists=artists, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListArtist.html', artists=artists)
def resenhaListTracks(): tracks = SpotifyGetTracks(request.form['spotifyTracks']).createList() session['resenhaTrack'] = request.form['spotifyTracks'] if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListTracks.html', tracks=tracks, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListTracks.html', tracks=tracks)
def resenhalistAlbums(artistId): albums = SpotifyGetAlbums(artistId).createList() session['resenhaAlbums'] = artistId if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListAlbums.html', albums=albums, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListAlbums.html', albums=albums)
def updateAccountDb(): UsersRepository().Update(request.form['id'], request.form['name'], request.form['surname'], request.form['email']) session['name'] = request.form['name'] session['surname'] = request.form['surname'] session['email'] = request.form['email'] flash('Dados atualizados com sucesso', 'success') return redirect(url_for('use.editAccount'))
def resenhaListPlaylists(): if SpotifyCheckUser(request.form['spotifyUsername']): playlists = SpotifyGetPlaylists(request.form['spotifyUsername']).createList() if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaListPlaylists.html', playlists=playlists, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaListPlaylists.html', playlists=playlists) else: flash('Nome de usuário não encontrado', 'danger') return redirect(url_for('res.resenhaIndex'))
def _adm(): if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('_adm.html', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('_adm.html')
def resenhaNewArtist(artistId): if session['email'] == '' or 'email' not in session: flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) spotify = SpotifyGetOneArtist(artistId).createList() if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaNew.html', spotify=spotify, tipo_review='artista', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaNew.html', spotify=spotify, tipo_review='artista')
def resenhaIndex(): CleanSession() if session['email'] == '' or 'email' not in session: session['previous'] = 'res.resenhaIndex' flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('resenha/resenhaIndex.html', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('resenha/resenhaIndex.html')
def updatePassDb(): try: user = UsersRepository().FindByEmail(request.form['email']) if user.email and sha256_crypt.verify(request.form['passwordOld'], user.password): if request.form['password1'] == request.form['password2']: password = sha256_crypt.hash(str(request.form['password1'])) UsersRepository().UpdatePassword(user.id, password) UpdateSession(user) flash('Senha alterada com sucesso', 'success') return redirect(url_for('ind.home')) else: flash('As novas senhas não são identicas, tente novamente', 'danger') return redirect(url_for('use.changePass')) else: flash('e-Mail e/ou senha atual incorretos', 'danger') return redirect(url_for('use.changePass')) except: flash('e-Mail e/ou senha atual incorretos', 'danger') return redirect(url_for('use.changePass'))
def adm_users_registry(): email = str(request.form['email']).strip().lower() name = str(request.form['name']).strip().title() surname = str(request.form['surname']).strip().title() if email == '' or name == '' or surname == '': flash('Blank field not accepted', 'info') elif UsersRepository().New(name, surname, 'pass', email): flash('Already registered, please check below', 'info') else: flash( "Conta criada com sucesso. Utilize a senha 'pass' no primeiro login.", 'success') return redirect(url_for('use._adm_usuarios'))
def minhas_resenhas(id): if session['email'] == '' or 'email' not in session or session['id'] == '': flash('Você precisa logar para acessar essa área', 'info') return redirect(url_for('log.login')) if 'id' not in session: session['id'] = '' reviews = ResenhaRepository().FindAuthorById(id) user = UsersRepository().FindById(id) if not reviews: flash('Você ainda não criou nenhuma resenha', 'info') return redirect(url_for('ind.home')) else: return redirect( url_for('filter.myPage', name=str(user.name).lower(), surname=str(user.surname).lower()))
def genresBody(genreLink): if 'id' not in session: session['id'] = '' genreLink = genreLink users = UsersRepository().List() genres = genres_model.genres resenhasListAll = ResenhaRepository().ListAll() spotifyArtist = [] spotifyAlbum = [] spotifyTrack = [] reviewsArtist = ResenhaRepository().ListOneGenre('artista', genreLink) for item in reviewsArtist: print(item.genre) reviewsAlbum = ResenhaRepository().ListOneGenre('album', genreLink) reviewsTrack = ResenhaRepository().ListOneGenre('track', genreLink) for item in reviewsArtist: spotifyArtist.append(SpotifyGetOneArtist(item.spotify_id).oneArtist) for item in reviewsAlbum: spotifyAlbum.append(SpotifyGetOneAlbum(item.spotify_id).oneAlbum) for item in reviewsTrack: spotifyTrack.append(SpotifyGetOneTrack(item.spotify_id).oneTrack) genreCount = {} for item in genres: count = 0 for genre in resenhasListAll: if genre.genre == item: count += 1 if count > 0: genreCount[item] = count if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId(session['id']) usersNotifications = UsersRepository().List() notifyComment = UsersRepository().FindById(session['id']).read_comment notifyLike = UsersRepository().FindById(session['id']).read_like return render_template('filters/genresBody.html', users=users, reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, notifyComment=notifyComment, notifyLike=notifyLike, genres=genres, genreCount=genreCount, genreLink=genreLink) else: return render_template('filters/genresBody.html', users=users, reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, genres=genres, genreCount=genreCount, genreLink=genreLink)
def UsuariosDelete(user_id): UsersRepository().Delete(user_id) flash('Usuario Successfully removed', 'info') return redirect(url_for('adm.adm_usuarios'))
def adm_usuarios(): users_list = UsersRepository().List() return render_template('_adm_usuarios.html', users=users_list)
def myPage(name, surname): if 'id' not in session: session['id'] = '' try: authorID = ResenhaRepository().FindAuthorByNameSurname( str(name).title(), str(surname).title()).id if not authorID: return redirect(url_for('ind.home')) reviews = ResenhaRepository().FindAuthorById(authorID) if not reviews: flash( f'{str(name).title()} {str(surname).title()} ainda não criou resenhas', 'info') return redirect(url_for('ind.home')) else: flash( f'Resenhas de {str(name).title()} {str(surname).title()}: ' f" resenhando.co/{str(name).lower()}-{str(surname).lower()} ", 'info') spotifyArtist = [] spotifyAlbum = [] spotifyTrack = [] spotifyPlaylist = [] reviewsArtist = [] reviewsAlbum = [] reviewsTrack = [] reviewsPlaylist = [] users = UsersRepository().List() for item in reviews: if item.tipo_review == 'artista': reviewsArtist.append(item) elif item.tipo_review == 'album': reviewsAlbum.append(item) elif item.tipo_review == 'track': reviewsTrack.append(item) elif item.tipo_review == 'playlist': reviewsPlaylist.append(item) for item in reviews: if item.tipo_review == 'artista': spotifyArtist.append( SpotifyGetOneArtist(item.spotify_id).oneArtist) elif item.tipo_review == 'album': spotifyAlbum.append( SpotifyGetOneAlbum(item.spotify_id).oneAlbum) elif item.tipo_review == 'track': spotifyTrack.append( SpotifyGetOneTrack(item.spotify_id).oneTrack) elif item.tipo_review == 'playlist': spotifyPlaylist.append( SpotifyGetOnePlaylist(item.spotify_id).onePlaylist) if session['id'] != '': comments = CommentsRepository().listAuthorId(session['id']) likeNotifications = CurtidasRepository().listAuthorId( session['id']) usersNotifications = UsersRepository().List() resenhasListAll = ResenhaRepository().ListAll() notifyComment = UsersRepository().FindById( session['id']).read_comment notifyLike = UsersRepository().FindById( session['id']).read_like return render_template('resenha/resenhaViews.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='myPage', comments=comments, usersNotifications=usersNotifications, likeNotifications=likeNotifications, resenhasListAll=resenhasListAll, notifyComment=notifyComment, notifyLike=notifyLike) else: return render_template('index.html', reviewsArtist=reviewsArtist, reviewsAlbum=reviewsAlbum, reviewsTrack=reviewsTrack, reviewsPlaylist=reviewsPlaylist, users=users, spotifyArtist=spotifyArtist, spotifyAlbum=spotifyAlbum, spotifyTrack=spotifyTrack, spotifyPlaylist=spotifyPlaylist, mainFilter='myPage') except: flash('Usuário não identificado', 'danger') return redirect(url_for('ind.home'))