Ejemplo n.º 1
0
def test_login():
	session.clear()
	clear_test_user()
	user = ctrl_user_manager.register("ycat","passwtest",sex_type.Male,23)
	utility.check_log(user.user_id,"注册成功",1,0)
	utility.check_log(user.user_id,"登陆成功",1,1)
	user = ctrl_user_manager.register("ycat2","passwtest",sex_type.Female,35)
	utility.check_log(user.user_id,"注册成功",1,0)
	utility.check_log(user.user_id,"登陆成功",1,1)
	assert 2 == len(session.g_session_data)
	assert not session.login("noexit","passwtest")
	utility.check_log(-1,"noexit登陆失败",0)
	user = session.login("ycat","passwtest")
	#utility.check_log(user.user_id,"登陆成功",1)
	ycatID = user.session_id
	utility.set_session_id(user.session_id)
	assert user
	assert user == session.get()
	assert user.sex == 1
	assert user.nickname == "ycat"
	assert user.user_id != 0
	assert 23 == user.age
	assert user.certf_state == 0
	#session.clear()
	
	user = session.login("ycat2","passwtest")
	utility.set_session_id(user.session_id)
	assert user
	assert user.sex == 0
	assert user.nickname == "ycat2"
	assert user.user_id != 0
	assert user.certf_state == 0
	assert user == session.get()
	assert 2 == len(session.g_session_data)
	session.logout()
	assert not session.get()
	assert 1 == len(session.g_session_data)
	assert session.g_session_data[ycatID].session_id == ycatID
	
	assert 35 == user.age
	
	for i in range(10):
		assert session._is_repeat_login("ycat","passwtest")
		assert not session._is_repeat_login("ycat","passwtest_wrong")
		assert session.login("ycat","passwtest") #repeat login but session keep same 
	assert 1 == len(session.g_session_data)
	
	session.clear();

	clear_test_user()
Ejemplo n.º 2
0
def generate_csrf_token():
    session = wa2.get_request().registry['session']
    t = session.get('_csrf_token')
    if not t:
        t = utils.newToken()
        session['_csrf_token'] = t
    return t
Ejemplo n.º 3
0
def progress(request):
    if "sessionid" not in request.args:
        return Response(json.dumps({"status": "error", "message": "Sessionid missing."}))
    obj = session.get(request.args["sessionid"])
    if obj is None:
        return Response(json.dumps({"status": "error", "message": "No such session."}))
    obj["status"] = "success"
    return Response(json.dumps(obj))
Ejemplo n.º 4
0
	def get(self):
		session_ = session.get(self)
		if session_ is None:
			self.redirect('login.html', permanent = True)
			return None
		fileName = self.request.uri
		fileName = fileName[fileName.rfind('/') + 1:]
		if fileName is None or len(fileName) == 0:
			fileName = 'index.html'
		self.render("html/%s" % fileName)
Ejemplo n.º 5
0
def url_test_get_record():
	ctrl_record._is_right_id(0)
	v = ctrl_record.read(session.get().user_id)
	ret = {}
	for r in ctrl_record._record_map:
		if r in v:
			ret[r] = (ctrl_record._record_map[r],v[r])
		else:
			ret[r] = (ctrl_record._record_map[r],"")
	return json.dumps(ret) 
Ejemplo n.º 6
0
def url_register():
	try:
		ids =  bottle.request.params.ids.split("@@")
		vals = bottle.request.params.vals.split("@@")
		r = {}
		for i,v in zip(ids,vals):
			r[int(i)] = v
		ctrl_record.save(session.get().user_id,r);	
		return json.dumps({"result":"true"});
	except Exception as error:
		utility.write_log(-1,"更改喜好信息失败"+ str(error),0)
		return json.dumps({"result":"false"});
Ejemplo n.º 7
0
def test_login_too_many():
	clear_test_user2()
	user = ctrl_user_manager.register("ycat3","passwtest",sex_type.Female,35)
	utility.check_log(user.user_id,"注册成功",1,0)
	r = web_login("ycat3","passwtest")
	assert r["result"] == "true"  
	assert r["msg"] == "ycat3, 欢迎您回来"
	utility.set_session_id(r["session"])
	user = session.get()
	utility.check_log(user.user_id,"登陆成功",1,1)
	
	for i in range(20):
		r = web_login("ycat3","wrongpassword_" +str(i))
		assert r ==  {"result":"false","msg":"用户名或密码不正确"}
		assert 1+i == g_loginFailedCount["ycat3"]
	assert len(g_loginFailedCount) == 1
	
	r = web_login("ycat3","wrongpassword20")
	assert r ==  {"result":"false","msg":"登陆次数过多,请30分钟后重试"}
	r = web_login("ycat3","passwtest")
	assert r ==  {"result":"false","msg":"登陆次数过多,请30分钟后重试"}
	r = web_login("ycat3","passwtest")
	assert r ==  {"result":"false","msg":"登陆次数过多,请30分钟后重试"}

	common.timer.set_pass_ticks(30*60*1000 + 5000)
	time.sleep(3)
	r = web_login("ycat3","passwtest") 
	assert r["result"] == "true"  
	assert r["msg"] == "ycat3, 欢迎您回来"
	utility.set_session_id(r["session"])
	user = session.get()
	utility.check_log(user.user_id,"登陆成功",1)
	assert len(g_loginFailedCount) == 0
	
	clear_test_user2()
	utility.get_timer().stop()
Ejemplo n.º 8
0
def test_user_age():
	test_user_manager.clear_test_user()
	now = datetime.datetime(2014,5,27,12,50,43)
	utility.set_now(now)
	assert utility.now() == now
	
	s = web_register.ctrl_user_manager.register("ycattest","123test",web_register.sex_type.Male,35)
	utility.set_session_id(s.session_id)
	assert session.get().age == 35
	session.logout()
	
	utility.set_now(datetime.datetime(2015,5,27,12,50,43))
	s = session.login("ycattest","123test")
	assert s.age == 36

	test_user_manager.clear_test_user()
	utility.set_now(None)
Ejemplo n.º 9
0
def save_description(request):
    if request.method != "POST":
        return not_found()
    if "sessionid" not in request.form or "description" not in request.form:
        return Response(
            json.dumps({"status": "error", "message": "Could not save description. Required parameters missing."})
        )

    description = request.form["description"]
    obj = session.get(request.form["sessionid"])
    if obj is None or "filename" not in obj:
        return Response(json.dumps({"status": "error", "message": "Could not save metadata file."}))

    filename = obj["filename"]
    metadata = filehelper.save_metadata(filename, {"description": description})
    try:
        title = metadata["title"]
        url = obj["url"]
    except KeyError:
        title = "(upload in progress...)"
        url = ""
    return Response(json.dumps({"status": "success", "title": title, "description": description, "url": url}))
    return Response(json.dumps({"status": "success", "title": title, "description": description, "url": obj["url"]}))
Ejemplo n.º 10
0
def url_show_record():
	d = session.get_dist()
	utility.update_c_table(d,"c_record")
	d["record_value"] = ctrl_record.read(session.get().user_id)
	return d
Ejemplo n.º 11
0
def get_data_from_session():
    while True:
        line = session.get()
        line = line.decode('cp1251', errors='ignore')
        sys.stdout.write(line+'\n')
        sys.stdout.flush()
Ejemplo n.º 12
0
def get_data_from_session():
    while True:
        line = session.get()
        stream.feed(line.decode('cp1251')+u'\n\r')
        ui.plainTextEdit.appendPlainText(line.decode('cp1251'))
Ejemplo n.º 13
0
def getPlaces(building):
    url = placesUrl.replace(":building", building)
    response = session.get(url)
    return response.json()
Ejemplo n.º 14
0
def getBuildings():
    response = session.get(buildingsUrl)
    return response.json()