예제 #1
0
def login():
    if 'user' in session:
        print('User Found')
        return render_template('/index.html', data=session['user'].name)
    form = LoginForm()
    jsonPayload = None
    if form.validate_on_submit():
        jsonPayload = {
                'username':form.username.data,
                'password':form.password.data
            }
        result = requests.post('http://0.0.0.0:5000/auth/login', json=jsonPayload)

        result = result.json()
        if result['status'] != 'fail':
            user = Session_User(form.username.data,result['auth_token'],result['user']['user_id'])
            #print(user.uid)
            session['user'] = user
            next_page = request.args.get('next')
            if not next_page or url_parse(next_page).netloc != '':
                next_page = url_for('web.mydashboard')
            return redirect(next_page)
        else:
            flash('Invalid username or password')
            return redirect(url_for('web.login'))
    return render_template('/login.html', title='Sign In', form=form)
예제 #2
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        user = User.query.filter_by(username=username).first()
        if user.check_password(password):
            login_user(user)
            flash('you have logged in!', 'info')
            return redirect(url_for('web.show_todo_list'))
        else:
            flash('Invalid username or password', 'danger')
    return render_template('login.html', form=form)