当前位置: 首页>>代码示例>>Python>>正文


Python apis.APIValueError方法代码示例

本文整理汇总了Python中apis.APIValueError方法的典型用法代码示例。如果您正苦于以下问题:Python apis.APIValueError方法的具体用法?Python apis.APIValueError怎么用?Python apis.APIValueError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在apis的用法示例。


在下文中一共展示了apis.APIValueError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: authenticate

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def authenticate(*,email,passwd):
	if not email:
		raise APIValueError('email','Invalid email')
	if not passwd:
		raise APIValueError('passwd','Invalid passwd')
	users = await User.findAll('email=?',[email])
	if len(users) == 0:
		raise APIValueError('email','Email not exist.')
	user = users[0]
	# check passwd
	sha1 = hashlib.sha1()
	sha1.update(user.id.encode('utf-8'))
	sha1.update(b':')
	sha1.update(passwd.encode('utf-8'))
	if user.passwd != sha1.hexdigest():
		raise APIValueError('passwd','passwd error')
	# authenticate ok set cookie
	r = web.Response()
	r.set_cookie(COOKIE_NAME,user2cookie(user,86400),max_age=86400,httponly=True)
	user.passwd = '******'
	r.content_type = 'application/json'
	r.body = json.dumps(user,ensure_ascii=False).encode('utf-8')
	return r

# ?? 
开发者ID:syusonn,项目名称:awesome-python3-webapp,代码行数:27,代码来源:handlers.py

示例2: api_register_user

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_register_user(*,email,name,passwd):
	if not name or not name.strip():
		raise APIValueError('name')
	if not email or not _RE_EMAIL.match(email):
		raise APIValueError('email')
	if not passwd or not _RE_SHA1.match(passwd):
		raise APIValueError('passwd')
	users = await User.findAll('email=?',[email])
	if len(users) > 0:
		raise APIError('register:failed','email','Email is already in use')
	uid = next_id()
	sha1_passwd = '%s:%s' % (uid,passwd)
	encrypt_passwd = hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest()
	image = 'https://1.gravatar.com/avatar/%s?s=200&r=pg&d=mm'
	user = User(id=uid,name=name.strip(),email=email,passwd=encrypt_passwd,image=image % hashlib.md5(email.encode('utf-8')).hexdigest())
	await user.save()
	# make session cookie
	r = web.Response()
	r.set_cookie(COOKIE_NAME,user2cookie(user,86400),max_age=86400,httponly=True)
	user.passwd = '******'
	r.content_type = 'application/json'
	r.body = json.dumps(user,ensure_ascii=False).encode('utf-8')
	return r 
开发者ID:syusonn,项目名称:awesome-python3-webapp,代码行数:25,代码来源:handlers.py

示例3: api_create_blog

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_create_blog(request,*,name,summary,content):
	check_admin(request)
	if not name or not name.strip():
		raise APIValueError('name','name cannot be empty')
	if not  summary or not summary.strip():
		raise APIValueError('summary','summary cannot be empty')
	if not content or not content.strip():
		raise APIValueError('content','content cannot be empty')
	user = request.__user__
	blog = Blog(
		user_id = user.id,
		user_name= user.name,
		user_image = user.image,
		name = name.strip(),
		summary = summary.strip(),
		content = content.strip()
	)
	await blog.save()
	return blog 
开发者ID:syusonn,项目名称:awesome-python3-webapp,代码行数:21,代码来源:handlers.py

示例4: api_register_user

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_register_user(*, email, name, password):
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not password or not _RE_SHA1.match(password):
        raise APIValueError('password')

    users = yield from User.find_all('email=?', [email])
    if len(users) > 0:
        raise APIError('Register failed', 'email', 'Email is already in use.')

    uid = next_id()
    sha1_password = '{}:{}'.format(uid, password)
    logging.info('register password:{}, sha1_password:{}'.format(password, sha1_password))
    user = User(id=uid, name= name.strip(), email= email, password = hashlib.sha1(sha1_password.encode('utf-8')).hexdigest(), image='http://www.gravatar.com/avatar/{}?d=mm&s=120'.format(hashlib.md5(email.encode('utf-8')).hexdigest()))
    yield from user.save()

    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.password = '*' * 8
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
开发者ID:tianzhenyun,项目名称:python-awesome-web,代码行数:26,代码来源:handlers.py

示例5: authenticate

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def authenticate(*, email, password):
    if not email:
        raise APIValueError('email', 'Invalid Email')
    if not password:
        raise APIValueError('password', 'Invalid Password')
    users = yield from User.find_all('email=?', [email])
    if len(users) == 0:
        raise APIValueError('email', 'Email not exist')

    user = users[0]

    #check password
    sha1_password = '{}:{}'.format(user.id, password)
    logging.info('login password:{}, sha1_password:{}'.format(password, sha1_password))
    if user.password != hashlib.sha1(sha1_password.encode('utf-8')).hexdigest():
        raise APIValueError('password', 'Invalid Password.')
    # authenticate ok, set cookie
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.password = '*' * 8
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
开发者ID:tianzhenyun,项目名称:python-awesome-web,代码行数:25,代码来源:handlers.py

示例6: register_uauser

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def register_uauser():
    i = ctx.request.input(name='', email='', password='')
    name = i.name.strip()
    email = i.email.strip().lower()
    password = i.password

    if not name:
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not password or not _RE_MD5.match(password):
        raise APIValueError('password')
    user = User.find_first('where email=?', email)
    if user:
        raise APIError('register:failed', 'email', 'Email is already in use.')
    user = User(name=name, email=email, password=password,
                image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email).hexdigest())
    user.insert()

    cookie = make_signed_cookie(user.id, user.password, None)
    ctx.response.set_cookie(_COOKIE_NAME, cookie)
    return user 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:24,代码来源:urls.py

示例7: api_create_blog

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_create_blog():
    check_admin()
    i = ctx.request.input(name='', summary='', content='')
    name = i.name.strip()
    summary = i.summary.strip()
    content = i.content.strip()
    if not name:
        raise APIValueError('name', 'name cannot be empty.')
    if not summary:
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    user = ctx.request.user
    blog = Blog(user_id=user.id, user_name=user.name,
                name=name, summary=summary, content=content)
    blog.insert()
    return blog 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:19,代码来源:urls.py

示例8: api_update_blog

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_update_blog(blog_id):
    check_admin()
    i = ctx.request.input(name='', summary='', content='')
    name = i.name.strip()
    summary = i.summary.strip()
    content = i.content.strip()
    if not name:
        raise APIValueError('name', 'name cannot be empty.')
    if not summary:
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content:
        raise APIValueError('content', 'content cannot be empty.')
    blog = Blog.get(blog_id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    blog.name = name
    blog.summary = summary
    blog.content = content
    blog.update()
    return blog 
开发者ID:tzshlyt,项目名称:python-webapp-blog,代码行数:22,代码来源:urls.py

示例9: api_create_blog

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_create_blog(request, *, name, summary, content):
    check_admin(request) # ??????
    # ??????????
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    # ??????
    blog = Blog(user_id=request.__user__.id, user_name=request.__user__.name, user_image=request.__user__.image, name=name.strip(), summary=summary.strip(), content=content.strip())
    yield from blog.save()  # ?????????
    return blog  # ??????


# day12??
# API:???? 
开发者ID:ReedSun,项目名称:Preeminent,代码行数:19,代码来源:handlers.py

示例10: api_create_comment

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_create_comment(id, request, *, content):
    user = request.__user__
    # ????
    if user is None:
        raise APIPermissionError('Please signin first.')
    # ??????????
    if not content or not content.strip():
        raise APIValueError('content')
    # ????????
    blog = yield from Blog.find(id)
    if blog is None:
        raise APIResourceNotFoundError('Blog')
    # ??????
    comment = Comment(blog_id=blog.id, user_id=user.id, user_name=user.name, user_image=user.image, content=content.strip())
    yield from comment.save()  # ?????????
    return comment  # ????

# day14??
# API????? 
开发者ID:ReedSun,项目名称:Preeminent,代码行数:21,代码来源:handlers.py

示例11: api_update_blog

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_update_blog(id, request, *, name, summary, content):
    check_admin(request)  # ??????
    blog = yield from Blog.find(id)  # ?????????????
    # ????????
    if not name or not name.strip():
        raise APIValueError('name', 'name cannot be empty.')
    if not summary or not summary.strip():
        raise APIValueError('summary', 'summary cannot be empty.')
    if not content or not content.strip():
        raise APIValueError('content', 'content cannot be empty.')
    blog.name = name.strip()
    blog.summary = summary.strip()
    blog.content = content.strip()
    yield from blog.update()  # ????
    return blog  # ??????

# day14??
# API:???? 
开发者ID:ReedSun,项目名称:Preeminent,代码行数:20,代码来源:handlers.py

示例12: authenticate

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def authenticate(*, email, passwd):
    if not email:
        raise APIValueError('email', 'Invalid email.')
    if not passwd:
        raise APIValueError('passwd', 'Invalid password.')
    users = yield from User.findAll('email=?', [email])
    if len(users) == 0:
        raise APIValueError('email', 'Email not exist.')
    user = users[0]
    # check passwd:
    sha1 = hashlib.sha1()
    sha1.update(user.id.encode('utf-8'))
    sha1.update(b':')
    sha1.update(passwd.encode('utf-8'))
    if user.passwd != sha1.hexdigest():
        raise APIValueError('passwd', 'Invalid password.')
    # authenticate ok, set cookie:
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.passwd = '******'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
开发者ID:xsingHu,项目名称:xs-python-architecture,代码行数:25,代码来源:handlers.py

示例13: api_register_user

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_register_user(*, email, name, passwd):
    if not name or not name.strip():
        raise APIValueError('name')
    if not email or not _RE_EMAIL.match(email):
        raise APIValueError('email')
    if not passwd or not _RE_SHA1.match(passwd):
        raise APIValueError('passwd')
    users = yield from User.findAll('email=?', [email])
    if len(users) > 0:
        raise APIError('register:failed', 'email', 'Email is already in use.')
    uid = next_id()
    sha1_passwd = '%s:%s' % (uid, passwd)
    user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest())
    yield from user.save()
    # make session cookie:
    r = web.Response()
    r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
    user.passwd = '******'
    r.content_type = 'application/json'
    r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
    return r 
开发者ID:xsingHu,项目名称:xs-python-architecture,代码行数:23,代码来源:handlers.py

示例14: authenticate

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def authenticate(*, email, passwd):
	if not email:
		raise APIValueError('email', 'Invalid email.')
	if not passwd:
		raise APIValueError('passwd', 'Invalid password')
	users = await User.findAll('email=?', [email])
	if len(users) == 0:
		raise APIValueError('email', 'Email not exist.')
	user = users[0]
	# check passwd:
	sha1 = hashlib.sha1()
	sha1.update(user.id.encode('utf-8'))
	sha1.update(b':')
	sha1.update(passwd.encode('utf-8'))
	if user.passwd != sha1.hexdigest():
		raise APIValueError('passwd', 'Invalid password.')
	# authenticate ok, set cookie:
	r = web.Response()
	r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True)
	user.passwd = '******'
	r.content_type = 'application/json'
	r.body = json.dumps(user, ensure_ascii=False).encode('utf-8')
	return r 
开发者ID:TsangTen,项目名称:awesome-webapp,代码行数:25,代码来源:handlers.py

示例15: api_create_blog

# 需要导入模块: import apis [as 别名]
# 或者: from apis import APIValueError [as 别名]
def api_create_blog(request, *, name, summary, content):
	check_admin(request)
	if not name or not name.strip():
		raise APIValueError('name', 'name cannot be empty.')
	if not summary or not summary.strip():
		raise APIValueError('summary', 'summary cannot be empty.')
	if not content or not content.strip():
		raise APIValueError('content', 'content cannot be empty.')
	blog = Blog(
			user_id=request.__user__.id, 
			user_name=request.__user__.name, 
			user_image=request.__user__.image,
			name=name.strip(),
			summary=summary.strip(),
			content=content.strip()
		)
	await blog.save()
	return blog 
开发者ID:TsangTen,项目名称:awesome-webapp,代码行数:20,代码来源:handlers.py


注:本文中的apis.APIValueError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。