예제 #1
0
def signup():
    form = UserLoginForm()

    try:
        if request.method == 'POST' and form.validate_on_submit(
        ):  #request - is the user requesting to POST or GET
            email = form.email.data
            password = form.password.data
            print(email, password)

            user = User(
                email, password=password
            )  #creating a user and this is their email and this is their password
            #The password field is going to equal the password that you pass in in models.py otherwise flask doesn't know which of the optional parameters the password is referring to

            db.session.add(
                user
            )  #session - you're git add .     .session adds the user to the database session (local host) and then when you commit you add it to the actual database
            db.session.commit()

            return redirect(url_for('signin'))

    except:
        raise Exception('Invalid Form Data: Please Check your form')

    return render_template('signup.html', form=form)
예제 #2
0
def signup():
    form = UserLoginForm()
    try:
        if request.method == 'POST' and form.validate_on_submit():
            email = form.email.data
            password = form.password.data
            print(email, password)
            user = User(email, password=password)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for('signin'))
    except:
        raise Exception('Invalid Form Data: Please check your form')

    return render_template('sign_up.html', form=form)
예제 #3
0
def authorize():
    google = oauth.create_client('google')
    token = google.authorize_access_token()
    response = google.get('userinfo')
    user_info = response.json()
    user = oauth.google.userinfo()
    session['profile'] = user_info

    user = User.query.filter_by(email = user_info['email']).first()
    if user:
        user.first_name = user_info['given_name']
        user.last_name = user_info['family_name']
        user.email = user_info['email']
        user.g_auth_verify = user_info['verified_email']

        db.session.add(user)
        db.session.commit()
        login_user(user)
        session.permanent = True
        return redirect(url_for('home'))

    else:
        g_first_name = user_info['given_name']
        g_last_name = user_info['family_name']
        g_email = user_info['email']
        g_verified = user_info['verified_email']

        user = User(
            first_name = g_first_name,
            last_name = g_last_name,
            email = g_email,
            g_auth_verify= g_verified
        )

        db.session.add(user)
        db.session.commit()
        session.permanent = True
        login_user(user)
        return redirect(url_for('home'))

    print(user_info)
    return redirect(url_for('home'))
예제 #4
0
def authorize():
    google = oauth.create_client('google')
    token = google.authorize_access_token()
    response = google.get('userinfo')
    print(response)
    user_info = response.json()
    user = oauth.google.userinfo()
    session['profile'] = user_info

    #checks if user who logged in via google auth has an account
    user = User.query.filter_by(email=user_info['email']).first()
    if user:
        user.first_name = user_info['given_name']
        user.last_name = user_info['family_name']
        user.email = user_info['email']
        user.g_auth_verify = user_info['verified_email']
        #if none exists, the following updates the user in the table
        db.session.add(user)
        db.session.commit()
        login_user(user)
        session.permanent = True
        return redirect(url_for('home'))

    else:
        g_first_name = user_info['given_name']
        g_last_name = user_info['family_name']
        g_email = user_info['email']
        g_verified = user_info['verified_email']

        user = User(first_name=g_first_name,
                    last_name=g_last_name,
                    email=g_email,
                    g_auth_verify=g_verified)

        db.session.add(user)
        db.session.commit()
        login_user(user)
        session.permanent = True
        return redirect(url_for('home'))

    print(user_info)
    return redirect(url_for('home'))