Ejemplo n.º 1
0
def register():
    u = User(request.form)
    #print('返回的注册内容',u.user, u.password)
    if u.valid():
        print("用户注册成功")
        # 保存到数据库
        print('密码',u.password)
        flash('注册成功了啊')
        log('注册成功', u.username)
        u.save()
        return redirect(url_for('login_view'))
    else:
        print('注册失败', request.form)
        flash('注册失败')
        return redirect(url_for('login_view'))
Ejemplo n.º 2
0
def login():
    u = User(request.form)
    #sql = str(User.query.filter_by(username=u.username).first())
    #print('sql', sql)
    user = User.query.filter_by(username=u.username).first()
    if u.validate(user):
        print('登录成功')
        session['username'] = u.username

        #cookie_id = str(uuid.uuid4())
        #cookie_dict[cookie_id] = user
        #r.set_cookie('cookie_id', cookie_id)

        log('session', session)
        return redirect(url_for('blog_view', username=user.username))
    else:
        print("用户登录失败", user)
        flash('登录失败了呀')
        return redirect(url_for('login_view'))