Exemple #1
0
def register_user(G_username, G_userpass):
    I_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    I_pass_sha1 = hashlib.sha1(G_userpass.encode("utf-8")).hexdigest()
    I_keys = "user,pass,createtime"
    I_values = "\"" + G_username + "\",\"" + I_pass_sha1 + "\",\"" + I_time + "\""
    insert_operaction("user", I_keys, I_values)
    return
Exemple #2
0
def register_success():
    G_username = request.form.get('user')
    G_userpass = request.form.get('pass')
    G_userpass_2 = request.form.get('pass2')
    if G_username is None:
        R_message = "用户名为空,请重新注册"
        return render_template('register_error.html', R_message=R_message)
    S_user_str = query_user(G_username)
    if S_user_str is not None:
        R_message = "用户名已存在,请重新注册"
        return render_template('register_error.html', R_message=R_message)
    if G_userpass is None:
        R_message = "密码为空,请重新注册"
        return render_template('register_error.html', R_message=R_message)
    if G_userpass_2 != G_userpass:
        R_message = "两次密码不匹配,请重新注册"
        return render_template('register_error.html', R_message=R_message)
    I_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    I_pass_sha1 = hashlib.sha1(G_userpass.encode("utf-8")).hexdigest()
    I_keys = "user,pass,createtime"
    I_values = "\"" + G_username + "\",\"" + I_pass_sha1 + "\",\"" + I_time + "\""
    insert_operaction("user", I_keys, I_values)
    return render_template('register_success.html',
                           username=G_username,
                           password=G_userpass)
Exemple #3
0
def songshi(post_type):
    if post_type == "tangshi":
        ZH_type = "唐诗"
    elif post_type == "songshi":
        ZH_type = "宋诗"
    elif post_type == "songci":
        ZH_type = "宋词"
    elif post_type == "shijing":
        ZH_type = "诗经"
    else:
        return redirect(url_for('index'))

    shoucang_str = post_type + "_shoucang"

    if request.method == 'POST':
        id = request.form.get('id')
        type = request.form.get('type')
        if type == "shoucang":
            shoucang_I_keys = "user_id,from_id"
            shoucang_User_values = "user = \"" + current_user.get_id() + "\""
            shoucang_User_id = select_operaction("id", "user",
                                                 shoucang_User_values)[0][0]
            shoucang_I_values = "\"" + str(
                shoucang_User_id) + "\",\"" + id + "\""
            insert_operaction(shoucang_str, shoucang_I_keys, shoucang_I_values)
        if type == "yichang":
            yichang_I_keys = "type,from_id"
            yichang_I_values = "\"" + post_type + "\",\"" + id + "\""
            insert_operaction("yichang", yichang_I_keys, yichang_I_values)

    max_id = select_operaction('max(id)', post_type)[0][0]
    random_id = str((random.randint(0, max_id)))
    where_value = "id = " + random_id
    R_str = select_operaction('*', post_type, where_value)
    R_id = R_str[0][0]
    R_title = fanToJian(R_str[0][1].decode('UTF-8'))
    R_author = fanToJian(R_str[0][2].decode('UTF-8'))
    R_paragraphs = reStr(fanToJian(R_str[0][3].decode('UTF-8'))).split('\n')
    return render_template('read.html',
                           id=R_id,
                           title=R_title,
                           author=R_author,
                           paragraphsList=R_paragraphs,
                           EN_type=post_type,
                           ZH_type=ZH_type)