Exemplo n.º 1
0
def auth():
    last_login = datetime.now()
    account_uri = session['ms_user']['uri']
    user = User.query(User).filter(User.account_uri == account_uri)

    user_dict = {'last_login': last_login, 'account_uri': account_uri}
    if user.count() == 0:
        user_dict['service_name'] = session['ms_service']
        user_dict['display_name'] = session['ms_user']['display_name']
        user_dict['account_id'] = session['ms_user']['id']
        res = User.commit_data(user_dict)
        if not res['success']:
            return res
        user = User.query(User).filter(User.account_uri == account_uri)

    user = user.first()
    user.session.close()

    if not user.radios:
        session['configured'] = False
        return redirect(url_for('user_settings.show_settings'))

    session['configured'] = True
    User.update_row(user_dict)
    return redirect(url_for('radios.radios_list'))
Exemplo n.º 2
0
def signup():
    """
    User sign-up page.

    GET requests serve sign-up page.
    POST requests validate form & user creation.
    """
    form = SignupForm()
    if form.validate_on_submit():
        existing_user = User.query(User).filter_by(
            email=form.email.data).first()
        if existing_user is None:
            user = User(name=form.name.data,
                        email=form.email.data,
                        website=form.website.data)
            user.set_password(form.password.data)
            user.session.add(user)
            user.session.commit()  # Create new user
            login_user(user)  # Log in as newly created user
            return redirect(url_for('main_bp.dashboard'))
        flash('A user already exists with that email address.')
    return render_template('signup.html',
                           title='Create an Account.',
                           form=form,
                           template='signup-page',
                           body="Sign up for a user account.")
Exemplo n.º 3
0
def login():

    if current_user.is_authenticated:
        return redirect(url_for('welcome_page.get_started'))

    form = LoginForm()

    if form.validate_on_submit():
        user = User.query(User).filter_by(email=form.email.data).first()

        if user and user.check_password(password=form.password.data):
            login_user(user)
            next_page = request.args.get('next')
            return redirect(next_page or url_for('welcome_page.get_started'))

        flash('Invalid username/password')
        return redirect(url_for('auth_page.login'))

    return render_template('login.html', form=form)