コード例 #1
0
def upload():
    if request.method == 'POST':
        information = dict()
        information['bucketName'] = request.form['bucketName']
        information['albumName'] = request.form['albumName']
        error = None
        db = get_db()

        if not information['pictureName']:
            error = 'Picture name is required'
        elif not information['bucket']:
            error = 'Bucket name is required'

        if error is not None:
            flask(error)
        else:
            db.execute(
                'INSERT INTO pictures (picture_name, bucket, owner_id) VALUES (?, ?, ?)',
                (
                    information['pictureName'],
                    information['bucket'],
                    g.user['id'],
                ))
            db.commit()
            # s3_upload(information['pictureName'], information['bucket'])
            return render_template('main_page/index.html')
            # return redirect(url_for('main_page.upload_success', information=information))

    return render_template('main_page/index.html')
コード例 #2
0
ファイル: auth.py プロジェクト: Rachelxdr/text_recognition
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None
        user = db.execute('SELECT password FROM users WHERE username = ?',
                          (username, )).fetchone()
        if user is None:
            error = 'Invalid username'
        elif not check_password_hash(user['password'], password):
            # elif user['password'] != password:
            error = 'Incorrect password'

        if error is None:
            session.clear()
            cur_id = db.execute('SELECT id FROM users WHERE username = ?',
                                (username, )).fetchone()
            session['user_id'] = cur_id[
                0]  # the user's id is stored in a new session. The data is stored in a cookie that is sent to the browser
            return redirect(url_for('main_page.upload'))

        flash(error)

    return render_template('auth/login.html')
コード例 #3
0
ファイル: auth.py プロジェクト: Rachelxdr/text_recognition
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        db = get_db()
        error = None

        if not username:
            error = 'Username is required.'
        elif not password:
            error = 'Password is required.'
        elif db.execute(  # db.executetake a SQL query with ? placeholders for any user input and a tuple of values to replace the placeholders with
                'SELECT id FROM users WHERE username = ?',
            (username,
             )).fetchone() is not None:  # returns one row from the query
            return redirect((url_for('auth.login')))

        if error is None:
            db.execute('INSERT INTO users (username, password) VALUES (?, ?)',
                       (
                           username,
                           generate_password_hash(password),
                       )
                       # (username, password,)
                       )

            db.commit()  # saves all changes
            return redirect(
                (url_for('auth.login'))
            )  # url_for generates tje URL for the login view based on its name

        flash(error)

    return render_template('auth/register.html')
コード例 #4
0
ファイル: auth.py プロジェクト: Rachelxdr/text_recognition
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 id FROM users WHERE id = ?',
                                  (user_id, )).fetchone()
コード例 #5
0
def add_bucket():
    if request.method == 'POST':
        information = dict()
        information['bucketName'] = request.form['bucketName']
        information['region'] = request.form['region']
        error = None
        db = get_db()

        if not information['bucketName']:
            error = 'Bucket name is required'
        elif not information['region']:
            error = 'Please Enter an AWS Region'

        if error is not None:
            flash(error)
        else:
            db.execute(
                'UPDATE users SET bucket_name = ?, region = ?  WHERE id = ?', (
                    information['bucketName'],
                    information['region'],
                    g.user['id'],
                ))
            db.commit()

        create_result = new_bucket(information['bucketName'],
                                   information['region'])
        if create_result == "success":
            flash("Bucket Created!")
            return redirect(
                url_for('main_page.add_album',
                        bucketName=information['bucketName'],
                        region=information['region']))
            # return render_template('main_page/add_album.html', information=information)
        else:
            flash("There was an error creating your bucket: ", create_result)
            return render_template('main_page/add_bucket.html')

    return render_template('main_page/add_bucket.html')