예제 #1
0
파일: MoeServer.py 프로젝트: CCIyx/Flask
def searchUser():
    # check login status
    session_id = request.cookies.get('SESSION_ID', '')
    user = databaseq.get_user_by_session_id(session_id)
    if not user:
        return {'code': 'no user'}
    current_uid = user[0]
    # keyword = request.form['searchContent']
    data_recv = request.get_data(as_text=True)
    data_recv_json = json.loads(data_recv)
    keyword = data_recv_json['Searchkeyword']
    users = databaseq.search_user(keyword)
    databaseq.get_user_by_name("asd")
    data = {'code': 'ok'}
    user_names = {}
    user_isfriend = {}
    frontend_action = {}
    index = 0
    for idx, user in enumerate(users):
        user_name = user[1]
        if user[0] != current_uid:
            user_names[index] = user_name
            isfriend = databaseq.check_friend(current_uid, user[0])
            if isfriend:
                user_isfriend[index] = "已关注"
                frontend_action[index] = "/NoFocusFriend"
            else:
                user_isfriend[index] = "未关注"
                frontend_action[index] = "/FocusFriend"
            index = index + 1
    data['data'] = user_names
    data['isfriend'] = user_isfriend
    data['action'] = frontend_action
    return json.dumps(data)
예제 #2
0
파일: MoeServer.py 프로젝트: CCIyx/Flask
def NoFocusFriend():
    session_id = request.cookies.get('SESSION_ID', '')
    user = databaseq.get_user_by_session_id(session_id)
    if not user:
        return render_template("sign.html", error='please login')

    current_uid = user[0]
    fname = request.form['uid']
    friend = databaseq.get_user_by_name(fname)
    fid = friend[0]
    databaseq.del_friend(current_uid, fid)
    resp = redirect(url_for('friendlist'))
    return resp
예제 #3
0
def GoForFriend():
    # check login status
    session_id = request.cookies.get('SESSION_ID', '')
    user = databaseq.get_user_by_session_id(session_id)
    if not user:
        return render_template("sign.html", error='please login')

    fname = request.form['fname']
    user = databaseq.get_user_by_name(fname) 
    current_hid = user[4]
    helper = databaseq.get_helper(current_hid)
    model_id = helper[1]
    costume_id = helper[2]
    return render_template("home.html", mode=model_id, cos=costume_id, show_button="display:none;")
예제 #4
0
def login():
    username = request.form['username']
    password = request.form['password']
    success = helper.check_login(username, password)
    if not success:
        return render_template("sign.html", error='用户名密码错误')

    # create session_id
    session_id = helper.generate_session_id()
    user = databaseq.get_user_by_name(username)
    uid = user[0]
    databaseq.insert_session(session_id, uid)

    resp = redirect(url_for('home'))
    resp.set_cookie('SESSION_ID', session_id)
    return resp
예제 #5
0
파일: MoeServer.py 프로젝트: CCIyx/Flask
def signup():
    username = request.form['username']
    password = request.form['password']
    email = request.form['emailaddr']

    # try to signup
    success = databaseq.signup(username, password, email)
    if not success:
        return render_template("sign.html", error='username exists')

    # create session_id
    session_id = helper.generate_session_id()
    user = databaseq.get_user_by_name(username)
    uid = user[0]
    databaseq.insert_session(session_id, uid)
    # init user data
    helper.user_init(uid)
    resp = redirect(url_for('home'))
    resp.set_cookie('SESSION_ID', session_id)
    return resp