示例#1
0
文件: __init__.py 项目: keios/PyRfK
def login():
    form = login_form(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        try:
            user = User.get_user(username=username)
            if user and user.check_password(password=form.password.data):
                user.authenticated = True
                remember = form.remember.data
                if login_user(user, remember=remember):
                    user.last_login = now()
                    loc = rfk.helper.get_location(request.remote_addr)
                    if 'country_code' in loc and loc[
                            'country_code'] is not None:
                        user.country = loc['country_code']
                    rfk.database.session.commit()
                    flash('Logged in!', 'success')
                    return redirect(
                        request.args.get('next') or url_for('index'))
                else:
                    form.username.errors.append(
                        'There was an error while logging you in.')
                    flash('There was an error while logging you in.', 'error')
            else:
                form.username.errors.append('Invalid User or Password.')
                flash('Invalid username or password.')
        except UserNotFoundException:
            form.username.errors.append('Invalid User or Password.')
            flash('Invalid username or password.')
    return render_template('login.html', form=form, TITLE='Login')
示例#2
0
def login():
    form = login_form(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        try:
            user = User.get_user(username=username)
            if user and user.check_password(password=form.password.data):
                user.authenticated = True
                remember = form.remember.data
                if login_user(user, remember=remember):
                    if not user.last_login:
                        flash(gettext('<strong>Tip:</strong> It appears that this is your first login, if you need any help please visit our help section by clicking <a href="/help">here</a>.'), 'info')
                    user.last_login = now()
                    loc = rfk.helper.get_location(request.remote_addr)
                    if 'country_code' in loc and loc['country_code'] is not None:
                        user.country = loc['country_code']
                    rfk.database.session.commit()
                    flash(gettext('Login successful. Welcome %s!' % user.username), 'success')
                    return redirect(request.args.get('next') or url_for('index'))
                else:
                    form.username.errors.append(gettext('There was an error while logging you in.'))
                    #flash('There was an error while logging you in.', 'error')
            else:
                form.username.errors.append(gettext('Invalid User or Password.'))
                #flash('Invalid username or password.')
        except UserNotFoundException:
            form.username.errors.append(gettext('Invalid User or Password.'))
            #flash('Invalid username or password.')
    return render_template('login.html', form=form, TITLE='Login')
示例#3
0
文件: __init__.py 项目: keios/PyRfK
def login():
    form = login_form(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        try:
            user = User.get_user(username=username)
            if user and user.check_password(password=form.password.data):
                user.authenticated = True
                remember = form.remember.data
                if login_user(user, remember=remember):
                    user.last_login = now()
                    loc = rfk.helper.get_location(request.remote_addr)
                    if 'country_code' in loc and loc['country_code'] is not None:
                        user.country = loc['country_code']
                    rfk.database.session.commit()
                    flash('Logged in!', 'success')
                    return redirect(request.args.get('next') or url_for('index'))
                else:
                    form.username.errors.append('There was an error while logging you in.')
                    flash('There was an error while logging you in.', 'error')
            else:
                form.username.errors.append('Invalid User or Password.')
                flash('Invalid username or password.')
        except UserNotFoundException:
            form.username.errors.append('Invalid User or Password.')
            flash('Invalid username or password.')
    return render_template('login.html', form=form, TITLE='Login')
示例#4
0
def login():
    form = login_form(request.form)
    if request.method == 'POST' and form.validate():
        username = form.username.data
        try:
            user = User.get_user(username=username)
            if user and user.check_password(password=form.password.data):
                user.authenticated = True
                remember = form.remember.data
                if login_user(user, remember=remember):
                    if not user.last_login:
                        flash(
                            gettext(
                                '<strong>Tip:</strong> It appears that this is your first login, if you need any help please visit our help section by clicking <a href="/help">here</a>.'
                            ), 'info')
                    user.last_login = now()
                    loc = rfk.helper.get_location(request.remote_addr)
                    if 'country_code' in loc and loc[
                            'country_code'] is not None:
                        user.country = loc['country_code']
                    rfk.database.session.commit()
                    flash(
                        gettext('Login successful. Welcome %s!' %
                                user.username), 'success')
                    return redirect(
                        request.args.get('next') or url_for('index'))
                else:
                    form.username.errors.append(
                        gettext('There was an error while logging you in.'))
                    #flash('There was an error while logging you in.', 'error')
            else:
                form.username.errors.append(
                    gettext('Invalid User or Password.'))
                #flash('Invalid username or password.')
        except UserNotFoundException:
            form.username.errors.append(gettext('Invalid User or Password.'))
            #flash('Invalid username or password.')
    return render_template('login.html', form=form, TITLE=gettext('Login'))