Exemplo n.º 1
0
def login():
    form = LoginFrom()
    # if request.method == 'POST':
    #     # 2.获取请求的参数
    #     us = 'admin'
    #     pa = 'admin'
    #     username = request.form.get('account')
    #     password = request.form.get('pwd')
    #     print(username, password)
    #     flash(u'%s' % password)
    #     if username == us and password == pa:
    #         return render_template('admin/admin.html')
    #     else:
    #         return render_template('admin/login.html', form=form)

    if form.validate_on_submit():
        data = form.data
        admin = Admin.query.filter_by(name=data["account"]).first()
        if not admin.check_pwd(data["pwd"]):
            # print(data['pwd'])
            flash("密码错误!")
            return redirect(url_for("adminmax.login"))
        else:
            session['admin'] = data['account']
            # return url_for('adminmax.index')
            return render_template('admin/admin.html')

    return render_template('admin/login.html', form=form)
Exemplo n.º 2
0
def login():
    form = LoginFrom()

    if form.validate_on_submit():
        data = form.data
        admin = Admin.query.filter_by(name=data["account"]).first()
        if not admin.check_pwd(data["pwd"]):
            flash("密码错误!")
            return redirect(url_for("adminmax.login"))
        else:
            session['admin'] = data['account']
            return render_template('admin/admin.html')

    return render_template('admin/login.html', form=form)
Exemplo n.º 3
0
def login():
    form = LoginFrom()
    if form.validate_on_submit():
        # 提交的时候验证表单
        data = form.data  # 获取表单的数据
        # print(data)
        login_admin = Admin.query.filter_by(name=data['account']).first()
        if not login_admin.check_pwd(data['pwd']):
            # 判断密码错误,然后将错误信息返回,使用flash用于消息闪现
            flash('密码错误!')
            return redirect(url_for('admin.login'))
        # 如果密码正确,session中添加账号记录,然后跳转到request中的next,或者是跳转到后台的首页
        session['login_admin'] = data['account']
        return redirect(request.args.get('next') or url_for('admin.index'))
    return render_template('admin/login.html', form=form)
Exemplo n.º 4
0
def login():
    # 实例化登陆表单
    form = LoginFrom()
    # 提交的的时候获取验正
    if form.validate_on_submit():
        # 获取表单的数据
        data = form.data
        admin = Admin.query.filter_by(name=data['account']).first()
        # 密码错误时,check_pwd返回false,则此时not check_pwd(data["pwd"])为真。
        if not admin.check_pwd(data['pwd']):
            # 消息闪现
            flash('密码错误')
            return redirect(url_for('admin.login'))
        # 如果是正确的,就要定义session的会话进行保存。
        session['admin'] = data['account']
        # return redirect(request.args.get('next')) or url_for('admin.index')
        return redirect(url_for('admin.index'))
    return render_template('admin/login.html', form=form)
Exemplo n.º 5
0
def login():
    form = LoginFrom()
    if form.validate_on_submit():
        data = form.data
        admin = Admin.query.filter_by(name=data["account"]).first()
        if not admin.check_pwd(data["pwd"]):
            flash("密码错误!", 'err')
            return redirect(url_for('admin.login'))
        session["admin"] = data["account"]
        session['admin_id'] = admin.id
        adminlog = Adminlog(
            admin_id=admin.id,
            ip=request.remote_addr,
        )
        db.session.add(adminlog)
        db.session.commit()
        return redirect(request.args.get("next") or url_for('admin.index'))
    return render_template("admin/login.html", form=form)