Exemplo n.º 1
0
def login():
    if verifyLogin() is False:
        return redirect(url_for('sla.index'))

    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute('SELECT * FROM user WHERE email = ?',
                          (username, )).fetchone()

        if user is None or check_password_hash(
                user['senha'],
                password) == 'False' or user['senha'] != password:
            error = 'Nome de usuário ou senha incorretos.'

        if error is None:
            session.clear()
            session['user_id'] = user['email']
            Server().connect(session['user_id'])
            return redirect(
                url_for('sla.index'
                        ))  #(arquivo python).(função que renderiza a pagina)

        flash(error)

    return render_template('login.html')
Exemplo n.º 2
0
    def add_video(self, video_name, video_description, extension, file):
        db = get_db()
        max_code = 0

        db.execute(
            'INSERT INTO video (nameVideo, descriptionVideo, extension) \
            VALUES (?, ?, ?)', (
                video_name,
                video_description,
                extension,
            ))

        videos = db.execute('SELECT code FROM video').fetchall()

        for i in videos:
            for j in i:
                if j > max_code:
                    max_code = j

        db.execute(
            'INSERT INTO video_details (code_user, code_video) \
            VALUES (?, ?)', (
                self.__email,
                int(max_code),
            ))

        Server().send_file(str(max_code), self.__email, extension, file)
        db.commit()
Exemplo n.º 3
0
def load_logged_in_user():
    user_id = session.get('user_id')

    if user_id is None:
        g.user = None
    else:
        g.user = get_db().execute('SELECT * FROM userMyoutube WHERE email = ?',
                                  (user_id, )).fetchone()
Exemplo n.º 4
0
    def get_user_information(self, email):
        db = get_db()
        dbUser = db.execute('SELECT * FROM userMyoutube WHERE email = ?',
                            (email, )).fetchone()
        user = User(dbUser['nameUser'], dbUser['email'],
                    dbUser['passwordUser'], dbUser['permission'])

        return user
Exemplo n.º 5
0
    def get_video_information(self, email):
        db = get_db()
        videos = []
        dbVideo = db.execute(
            'SELECT video.code, video.nameVideo, video.descriptionVideo, video.extension \
            FROM video_details \
            INNER JOIN userMyoutube ON video_details.code_user = userMyoutube.email \
            INNER JOIN video ON video_details.code_video = video.code \
            WHERE userMyoutube.email = ?', (email, )).fetchall()

        for i in dbVideo:
            video_informs = []
            for j in i:
                video_informs.append(j)

            video = Video(str(video_informs[0]), video_informs[1],
                          video_informs[2], video_informs[3])
            videos.append(video)

        return videos
Exemplo n.º 6
0
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None

        if not username:
            error = 'Precisa do nome de usuário.'
        elif not password:
            error = 'Precisa da senha.'
        elif db.execute('SELECT email FROM user WHERE nome = ?',
                        (username)).fetchone() is not None:
            error = 'User {} is already registered.'.format(username)

        if error is None:
            db.execute('INSERT INTO user (username, password) VALUES (?, ?)',
                       (username, generate_password_hash(password)))
            db.commit()
            return redirect(url_for('auth.login'))

        flash(error)

    return render_template('register.html')