def regist(): if request.method == 'GET': return flask.render_template('regist.html') else: telephone = request.form.get('telephone') username = request.form.get('username') password1 = request.form.get('password1') password2 = request.form.get('password2') message = validate(telephone=telephone,username=username,password1=password1,password2=password2) flash(message) #数据验证 # if telephone or username != '': # user = User.query.filter(User.telephone == telephone).first() # if user: # return u'该手机号已被注册,请更换手机号码!' # else: # if password1 != password2: # return u'两次密码输入不一致!' # else: # user = User(telephone=telephone,username=username,password=password1) # db.session.add(user) # db.session.commit() # # 如果注册成功,就让页面跳转到登录页面 # return redirect(url_for('login')) # else: # return u'手机号或用户名不能为空!' if message == '注册成功': session['status'] = 'OK' return redirect(url_for('login')) else: session['status'] = 'BAD' return flask.render_template('regist.html')
def consensus(path): dirs = [f.path for f in os.scandir(path) if f.is_dir() and "__" not in f.path] #print(dirs) dirs.sort() with open(f"{dirs[0]}/meta.json") as meta: data = json.load(meta) #print(data) for item in data: prefix = item['prefix'] index = item['index'] metrics = item['metrics'] props = item['props'] candidates = [] for dir in dirs: files = glob.glob(f"{dir}/{prefix}*.csv") files.sort() candidates.append(files[-1]) print(candidates) verify.validate(prefix, index, metrics, props, candidates)
def login(): if request.method == 'GET': return flask.render_template('login.html') else: telephone = request.form.get('telephone') password = request.form.get('password') # user = User.query.filter(User.telephone == telephone, User.password == password).first() # user = User.query.filter(User.telephone == telephone).first() # if user and user.check_password(password): # session['user_id'] = user.id # #如果想在31天内都不需要登录 # session.permanent = True # return redirect(url_for('index')) # else: # return u'手机号码或密码错误,请确认后再登录!' message = validate(telephone=telephone,password1=password) flash(message) user = session.get('user_id') if user: session['status'] = 'Login_OK' return redirect(url_for('index')) else: return flask.render_template('login.html')
def tests_hard_one(): x = '{}{Code}[Fellows](())' actual = validate(x) expected = True assert actual == expected
def test_validate_returns_True_with_an_easy_one(): x = '[]' actual = validate(x) expected = True assert actual == expected
def test_false_with_text(): x = '[{9tails}]}' actual = validate(x) expected = False assert actual == expected
def test_with_text(): x = '[(hello)]' actual = validate(x) expected = True assert actual == expected
def test_non_bal_returns_false(): x = '[}]' actual = validate(x) expected = False assert actual == expected
def test_valid_curly(): x = '{}' actual = validate(x) expected = True assert actual == expected
def test_valid_paren(): x = '()' actual = validate(x) expected = True assert actual == expected