Exemplo n.º 1
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = Myprofile()
    print app.config['OPENID_PROVIDERS']
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Exemplo n.º 2
0
def profile_add():
    if request.method == 'POST':
        username = request.form['username']
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        age = request.form['age']
        image = request.files['image']
        sex = request.form['sex']
        imagename = image.filename
        image.save(os.path.join("app/static/img/", imagename))
        # write the information to the database
        newprofile = Myprofile(username=username,
                               first_name=first_name,
                               last_name=last_name,
                               age=age,
                               sex=sex,
                               image=imagename)
        db.session.add(newprofile)
        db.session.commit()

        return "{} {} was added to the database".format(
            request.form['first_name'], request.form['last_name'])

    form = ProfileForm()
    return render_template('profile_add.html', form=form)
Exemplo n.º 3
0
def profile_add():
    form = ProfileForm(request.form)

    if request.method == 'GET':
        return render_template('profile_add.html',form=form)

    if form.validate() and request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        age = request.form['age']
        file = request.files['image']
        username = request.form['username']
        sex = request.form['sex']
        filename = file.filename
        file.save(os.path.join('app/static/uploads', filename))

        
        # write the information to the database
        newprofile = Myprofile(first_name=first_name,
                               last_name=last_name,
                               age=age,
                               sex=sex,
                               username=username,
                               image='/static/uploads/'+filename)
        db.session.add(newprofile)
        db.session.commit()
        return "{} {} was added to the database".format(request.form['first_name'],
                                             request.form['last_name'])

    return render_template('profile_add.html',form=form)
Exemplo n.º 4
0
def profile_add():
    import os
    from flask import Flask, request, redirect, url_for
    from werkzeug import secure_filename
    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        gender = request.form['gender']
        image = request.files['image']
        biography = request.form['biography']
        age = request.form['age']

        filename = secure_filename(image.filename)
        image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        created_on = time.strftime('%m %d %Y')

        # write the information to the database
        newprofile = Myprofile(first_name=first_name,
                               last_name=last_name,
                               gender=gender,
                               image=filename,
                               biography=biography,
                               created_on=created_on)
        db.session.add(newprofile)
        db.session.commit()

        return "{} {}, who is a {} was added to the database with image: {}".format(
            request.form['first_name'], request.form['last_name'],
            request.form['gender'], filename)

    form = ProfileForm()
    return render_template('profile_add.html', form=form)
Exemplo n.º 5
0
def profile_add():
    if request.method == 'POST':
        id = random.randint(1000000, 1099999)
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        nickname = request.form['nickname']
        email = request.form['email']
        password = request.form['password']

        file = request.files['image']
        image = secure_filename(file.filename)
        file.save(os.path.join("pics", image))

        # write the information to the database
        newprofile = Myprofile(id=id,
                               first_name=first_name,
                               last_name=last_name,
                               nickname=nickname,
                               email=email,
                               password=password,
                               image=image)
        db.session.add(newprofile)
        db.session.commit()

        return "{} {} was added to the database".format(
            request.form['first_name'], request.form['last_name'])

    form = ProfileForm()
    return render_template('profile_add.html', form=form)
Exemplo n.º 6
0
def newprofile():
    if request.method == 'POST':
        firstname = request.form['firstname']
        lastname = request.form['lastname']
        sex = request.form['sex']
        age = request.form['age']
        form = ProfileForm(request.form)
        image = request.files['image']
        UPLOAD_FOLDER = "/app/static/uploads"
        imagename = secure_filename(image.filename)
        timeinfo = time.strftime("%a, %b %d %Y")
        image.save(os.path.join(os.getcwd() + UPLOAD_FOLDER, imagename))
        username = firstname[:1] + lastname + age + time.strftime("%Y")
        check = db.session.execute('SELECT max(id) from myprofile')
        if check is True:
            for i in check:
                userid = i[0] + 1
        else:
            userid = 6200
        newProfile = Myprofile(id=userid,firstname=firstname, lastname=lastname, sex=sex, age=age, username=username, image=imagename, profile_add_on=timeinfo)
        db.session.add(newProfile)
        db.session.commit()
        flash('New entry was successfully posted')
        return redirect('/profile/'+str(Myprofile.query.filter_by(username=newProfile.username).first().id))
    form = ProfileForm()
    return render_template('registration.html',form=form)
Exemplo n.º 7
0
def profile_add():
    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']

        # write the information to the database
        newprofile = Myprofile(first_name=first_name, last_name=last_name)
        db.session.add(newprofile)
        db.session.commit()

        return "{} {} was added to the database".format(
            request.form['first_name'], request.form['last_name'])

    form = ProfileForm()
    return render_template('profile_add.html', form=form)
Exemplo n.º 8
0
def profile_add():
    form = ProfileForm()
    print openid
    if request.method == 'POST':
        # write the information to the database
       
        newprofile = Myprofile(first_name=form.first_name.data,last_name=form.last_name.data,username=form.username.data,email=form.email.data,password=form.password.data)
        db.session.add(newprofile)
        db.session.commit()

        return "{} {} was added to the database".format(request.form['first_name'],
                                             request.form['last_name'])

    form = ProfileForm()
    return render_template('profile_add.html',
                           form=form)
Exemplo n.º 9
0
def login():
    form = Myprofile()
    if request.method == "POST":
        pass
    # change this to actually validate the user
    if form.username.data:
        # login and validate the user...

        # missing
        # based on password and username
        # get user id, load into session
        user = load_user("1")
        login_user(user)
        #flash("Logged in successfully.")
        return redirect(request.args.get("next") or url_for("home"))
    return render_template("login.html", form=form)
Exemplo n.º 10
0
def after_login(resp):
    if resp.email is None or resp.email == "":
        flash('Invalid login. Please try again.')
        return redirect(url_for('login'))
    profile = Myprofile.query.filter_by(email=resp.email).first()
    if profile is None:
        nickname = resp.nickname
        if nickname is None or nickname == "":
            nickname = resp.email.split('@')[0]
        profile = Myprofile(nickname=nickname, email=resp.email)
        db.session.add(profile)
        db.session.commit()
    remember_me = False
    if 'remember_me' in session:
        remember_me = session['remember_me']
        session.pop('remember_me', None)
    login_user(profile, remember=remember_me)
    return redirect(request.args.get('next') or url_for('home'))
Exemplo n.º 11
0
def profile_add():

    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        age_name = request.form['age']
        email_name = request.form['email_name']
        option_name = request.form['sex']
        password_name = request.form['password_name']

        user_name = request.form['user_name']
        form = ProfileForm(request.form)

        image_data = request.files[form.image.name].read()
        #form.image.file.save(os.path.join("app/static/uploads", image_data))
        file = request.files[form.image.name]
        filename = file.filename
        file.save(os.path.join("app/static/uploads", filename))
        #open(os.path.join("app/static/uploads", form.image.data), 'w').write(image_data)
        # write the information to the database
        newprofile = Myprofile(first_name=first_name,
                               last_name=last_name,
                               age=age_name,
                               sex=option_name,
                               user_name=user_name,
                               profile_add_on=datetime.now(),
                               email=email_name,
                               image=filename,
                               password=password_name)
        db.session.add(newprofile)
        db.session.commit()

        return redirect('/profile/' + str(
            Myprofile.query.filter_by(
                user_name=newprofile.user_name).first().id))

    form = ProfileForm()
    return render_template('profile_add.html', form=form)
Exemplo n.º 12
0
def user_registration():
    """Processes a user registration"""

    db.create_all()
    if request.method == 'POST':
        first_name = request.form['first_name']
        last_name = request.form['last_name']
        email = request.form['email']
        password = request.form['password']

        # write the information to the database
        newprofile = Myprofile(first_name=first_name,
                               last_name=last_name,
                               email=email,
                               password=password)
        db.session.add(newprofile)
        db.session.commit()

        return "{} {} was added to the database".format(
            request.form['first_name'],
            request.form['last_name']) + render_template('home.html')

    return render_template('profile_add.html')