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)
def register_step1(): ''' 用户注册STEP1 参数: 用户名 密码 返回值: SUCCESS / USERNAME_EXIST / INVALID_OPERATION 对form参数进行检查,若不存在 'username' 或 'password' 则返回 INVALID_OPERATION 对用户名进行判重,若用户名已存在,则返回 USER_NAME_EXIST 对密码进行检查,若密码长度小于6位,则返回 INVALID_OPERATION 将session username password插入temp_user数据库中 返回SUCCESS ''' cookies = request.cookies if not 'session' in cookies: return jsonify(rescode=INVALID_OPERATION) session = cookies['session'] form = request.form if not 'username' in form or not 'password' in form: return jsonify(rescode=INVALID_OPERATION) username = form['username'] password = form['password'] from lib import check_username_exist if check_username_exist(session, username) == True: return jsonify(rescode=USERNAME_EXIST) if len(password) < 6: return jsonify(rescode=INVALID_OPERATION) import hashlib password = hashlib.md5(password).hexdigest() from lib import add_temp_user add_temp_user(session, username, password) return jsonify(rescode=SUCCESS)