Exemplo n.º 1
0
def register():
    form = request.form
    require = ['username', 'password', 'email', 'phone', 'name', 'studentid', 'usertype']
    for item in require:
        if not item in form:
            return jsonify(res=PARAMETER_WRONG)

    username = form['username']
    password = form['password']
    email = form['email']
    phone = form['phone']
    name = form['name']
    studentid = form['studentid']
    usertype = form['usertype']

    from lib import check_username_exist
    if check_username_exist(username) == True:
        return jsonify(res=USERNAME_EXIST)

    files = request.files
    f = files['file']
    filename = f.filename
    filetype = filename.split('.')[-1]
    from lib import generate_session
    code = generate_session()
    filename = code + '.' + filetype
    f.save("static/user/avatar/"+filename)

    from lib import user_register
    user_register(username, password, email, phone, name, studentid, usertype, filename)

    return jsonify(res=SUCCESS)
Exemplo n.º 2
0
def login():
    cookies = request.cookies
    if 'session' in cookies:
        session = cookies['session']
        from lib import get_userid_by_session
        userid = get_userid_by_session(session)
        if userid != None:
            return redirect('/')
    else:
        from lib import generate_session
        session = generate_session()
    resp = make_response(render_template('login.html'))
    resp.set_cookie('session', session, max_age=1200)
    return resp