Пример #1
0
def test_data():
    SQLModel.init_db()

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(
        title='test todo',
        user_id=u.id,
    )
    t = TodoAjax.new(form)

    form = dict(
        content='test_weibo',
        user_id=u.id,
    )

    w = Weibo.new(form)

    form = dict(
        content='test_comment',
        user_id=u.id,
        weibo_id=1,
    )

    w = Comment.new(form)
Пример #2
0
def create_posts(posts: [int, str, str]):
    tag = s.query(Tag).filter_by(name='Истории').one()
    for post in posts:
        post = Post(*post)
        post.tags.append(tag)
        s.add(post)
    s.commit()
Пример #3
0
def fake_data():
    SQLModel.init_db()

    Test.new({})

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(title='test todo ajax', )
    t = TodoAjax.add(form, u.id)
Пример #4
0
def login(request):
    form = request.form()
    user, result = User.login(form)
    if user.is_guest():
        return redirect('/user/login/view?result={}'.format(result))
    else:
        session_id = Session.add(user_id=user.id)
        return redirect('/user/login/view?result={}'.format(result),
                        session_id)
Пример #5
0
def login(request):
    log('login, headers', request.headers)
    log('login, cookies', request.cookies)
    form = request.form()
    user, result = User.login(form)
    if user.is_guest():
        return redirect('/user/login/view?result={}'.format(result))
    else:
        session_id = Session.add(user_id=user.id)
        return redirect('/user/login/view?result={}'.format(result), session_id)
Пример #6
0
def test_data():
    SQLModel.init_db()

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(content='test weibo', )
    w = Weibo.add(form, u.id)
    form = dict(
        content='test comment',
        weibo_id=w.id,
    )
    Weibo.comment_add(form, u.id)

    SQLModel.connection.close()
Пример #7
0
def fake_data():
    SQLModel.init_db()

    Test.new({})

    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    form = dict(title='test todo ajax', )
    todo = Todo.add(form, u.id)
    t = TodoAjax.add(form, u.id)

    form = dict(content='test weibo', )
    weibo = Weibo.add(form, u.id)
    comment = Comment.add(form, u.id)
Пример #8
0
def test_data():
    SQLModel.init_db()

    Test.new({})

    # guest user
    form = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u, result = User.register(form)

    Session.add(u.id)

    # test todo insert
    form = dict(
        title='test todo',
        user_id=u.id,
    )
    Todo.insert(form)

    # test weibo insert
    form = dict(
        content='test weibo',
        user_id=u.id,
    )
    weibo_id = Weibo.insert(form)

    # test comment insert
    form = dict(
        content='test comment',
        weibo_id=weibo_id,
        user_id=u.id,
    )
    Comment.insert(form)

    SQLModel.connection.close()
Пример #9
0
def login(request):
    """
    登录页面的路由函数
    """
    log('login, headers', request.headers)
    log('login, cookies', request.cookies)
    user_current = current_user(request)
    log('current user', user_current)
    form = request.form()
    user, result = User.login(form)
    if user.is_guest():
        return redirect('/user/login/view?result={}'.format(result))
    else:
        session_id = Session.add(user_id=user.id)
        return redirect('/user/login/view?result={}'.format(result), session_id)
def route_login(request):
    """
    登录页面的路由函数
    """
    log('login, headers', request.headers)
    log('login, cookies', request.cookies)
    user_current = current_user(request)
    log('current user', user_current)

    form = request.form()
    user_login, result = User.login_user(form)
    result = urllib.parse.quote_plus(result)
    if user_login is not None:
        session_id = Session.add(user_login.id)
        headers = {'Set-Cookie': 'session_id={}'.format(session_id)}
    else:
        headers = {}
    return redirect('/login/view', result=result, headers=headers)
def doSignin():
    usr = request.form.get('usr')
    pwd = request.form.get('pwd') + '#$%^&*$@' + usr
    rem = request.form.get('rem')
    pwd = md5(pwd.encode())
    acc = Account()
    v = acc.getAccount((usr, pwd.digest()))
    if v:
        res = make_response(redirect("/authen"))
        token = randomString(32)
        ses = Session()
        ret = ses.add((token, v['id']))
        if rem == "1":
            res.set_cookie("session", token, max_age=30 * 3600 * 24)
        else:
            res.set_cookie("session", token)
        return res
    else:
        return render_template('authen/signin.html', err="Log In Failed")
Пример #12
0
def doSignin():
    usr = request.form.get('usr')
    pwd = request.form.get('pwd') + '!@$*&#' + usr 
    pwd = md5(pwd.encode()) 
    rem = request.form.get('rem')
    acc = Account()
    v = acc.getAccount( (usr,pwd.digest()))
    if v:
        res = make_response(redirect('/authen'))
        #set cookies
        token = randomStr(32)
        ses = Session()
        ret = ses.add((token, v['id']))
        if rem == '1':
            res.set_cookie('session', token, max_age= 69 * 24 * 3600)
        else:
            res.set_cookie('session', token)
        return res
    return render_template('authen/signin.html', err = 'Sign in Failed')
Пример #13
0
def create_admin(name: str, email: str, password: str):
    s.add(Admin(name, email, password))
    s.commit()
Пример #14
0
def create_tags(names: [str]):
    for name in names:
        s.add(Tag(name))
    s.commit()
Пример #15
0
def fake_data():
    log('fake data')
    SQLModel.init_db()

    Test.new({})

    form1 = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    form2 = dict(
        username='******',
        password='******',
        role=UserRole.normal,
    )
    u2, result = User.register(form1)
    u1, result = User.register(form2)

    Session.add(u1.id)
    Session.add(u2.id)

    form = dict(title='test todo ajax', )
    t = TodoAjax.add(form, u1.id)

    # weibo
    form1 = dict(
        content="weibo test user zjt",
        user_id=u1.id,
    )
    form2 = dict(
        content="weibo test user abc",
        user_id=u2.id,
    )
    w1 = Weibo.add(form1, u1.id).id
    w2 = Weibo.add(form2, u2.id).id
    w1 = Weibo.add(form1, u2.id).id
    w2 = Weibo.add(form2, u1.id).id

    # comment
    form1 = dict(
        content="weibo test user zjt",
        user_id=u1.id,
        weibo_id=w1,
    )
    form2 = dict(
        content="weibo test user abc",
        user_id=u2.id,
        weibo_id=w1,
    )
    # comment
    form3 = dict(
        content="weibo test user zjt",
        user_id=u1.id,
        weibo_id=w2,
    )
    form4 = dict(
        content="weibo test user abc",
        user_id=u2.id,
        weibo_id=w2,
    )
    Comment.new(form1)
    Comment.new(form2)
    Comment.new(form3)
    Comment.new(form4)

    SQLModel.connection.close()