Exemplo n.º 1
0
def login():
	"""
	用户登录
	"""
	logger.info('url = ' + str(request.url))
	# 如果用户已经登录,就不再需要登录,直接返回主页
	if current_user.is_authenticated:
		return redirect(url_for('main.index'))

	form = LoginForm()
	# 登录
	if form.validate_on_submit():
		# 将email转成小写然后取用户数据,注册时也转成了小写
		user = User.query.filter_by(email=form.email.data.lower()).first()
		# 用户不存在或者验证密码错误
		# 取出用户数据后,调用validate_password来判断密码是否匹配,密码都是加密的
		if user is not None and user.validate_password(form.password.data):
			# login_user是flask-login库的,用来保存用户信息
			if login_user(user, form.remember_me.data):
				flash('登录成功!', 'info')
				return redirect_back()
			else:
				flash('你的账号已被禁止登录!', 'warning')
				return redirect(url_for('main.index'))
		flash('错误的邮箱或者密码,请确认后再登录!', 'warning')
	return render_template('auth/login.html', form=form)
Exemplo n.º 2
0
def re_authenticate():
    if login_fresh():
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit() and current_user.validate_password(form.password.data):
        confirm_login()
        return redirect_back()
    return render_template('auth/login.html', form=form)
Exemplo n.º 3
0
Arquivo: auth.py Projeto: joyc/albumy
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.validate_password(form.password.data):
            login_user(user, form.remember_me.data)
            flash('Login success.', 'info')
            return redirect_back()
        flash('Invalid email or password.', 'warning')
    return render_template('auth/login.html', form=form)
Exemplo n.º 4
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.validate_password(form.password.data):
            if login_user(user, form.remember_me.data):
                flash("login success", 'info')
                return redirect_back()
        else:
            flash("Your account is blocked.", "warning")
            return redirect(url_for('main.index'))
        flash("Invalid email or password.", 'warning')
    return render_template('auth/login.html', form=form)
Exemplo n.º 5
0
def re_authenticate():
    ''''对已经登录的用户重新认证,保持 “新鲜”。
    类似 Github 等认证。对于一些敏感操作需要重新认证,例如修改密码。
    '''
    if login_fresh():
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit() and current_user.validate_password(
            form.password.data):
        confirm_login()
        return redirect_back()
    return render_template('auth/login.html', form=form)
Exemplo n.º 6
0
def re_authenticate():
	"""
	重新认证
	"""
	logger.info('url = ' + str(request.url))
	# 刷新
	if login_fresh():
		return redirect(url_for('main.index'))

	form = LoginForm()
	if form.validate_on_submit() and current_user.validate_password(form.password.data):
		confirm_login()
		return redirect_back()
	return render_template('auth/login.html', form=form)
Exemplo n.º 7
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.validate_password(form.password.data):
            if login_user(user, form.remember_me.data):
                flash("Login success.", "info")
                return redirect_back()
            else:
                flash("Your account is blocked.", "warning")
                return redirect(url_for("main.index"))
        flash("Invalid Email or password.", "warning")
    return render_template("auth/login.html", form=form)
Exemplo n.º 8
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.validate_password(form.password.data):
            # login_user(user,form.remember_me.data)
            # 如果用户对象的is_active属性为False,Flask-Login将拒绝登录用户
            if login_user(user, form.remember_me.data):
                flash('登陆成功', 'info')
                return redirect_back()
            else:
                flash('你的账号已被封禁', 'warning')
                return redirect(url_for('main.index'))
        flash('邮箱或密码错误', 'warning')
    return render_template('auth/login.html', form=form)
Exemplo n.º 9
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data.lower()).first()
        if user is not None and user.validate_password(form.password.data):
            # login_user(user, form.remember_me.data)
            # flash('登录成功。', 'success')
            # return redirect_back()
            if login_user(user, form.remember_me.data):
                flash('登录成功。', 'success')
                return redirect_back()
            else:  # 当 login_user() 返回 False 时,说明用户的 active 属性为 False
                flash('你的账号被封了。', 'warning')  # 返回封禁提示
                return redirect(url_for('main.index'))
        flash('无效的邮箱或密码', 'warning')
    return render_template('auth/login.html', form=form)
Exemplo n.º 10
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("main.index"))

    form = LoginForm()
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        remember_me = form.remember_me.data
        user = User.query.filter_by(username=username).first()
        if user is not None and user.validate_password(password):
            if login_user(user, remember_me):
                flash("Welcome back %s" % user.username, 'info')
                return redirect(url_for('user.index', username=username))
            else:
                flash('Your account is blocked', 'warning')
                return redirect(url_for('main.index'))

        flash("Wrong username or password", 'warning')
    return render_template('auth/login.html', form=form)
Exemplo n.º 11
0
def login():
    form = LoginForm()
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    if form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        remember = form.remember.data
        user = User.query.filter_by(username=username).first()
        if user:
            if user.validate_password(password):
                if login_user(user, remember):
                    flash('Welcome back.', 'info')
                    return redirect_back()
                else:
                    flash('Your account is blocked.', 'warning')
                    return redirect(url_for('main.index'))
            flash('Invalid username or password.', 'warning')
        else:
            flash('No account.', 'warning')
    return render_template('auth/login.html', form=form)