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.gravator.com/avatar/%s?d=mm&s=120'%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.passwd='******' r.content_type='application/json' r.body=json.dumps(user,ensure_ascii=False).encode('utf-8') return r
def api_register(*, name, email, password): logging.info("enter") check_string(name=name) check_email_passwd(email, name) users = yield from User.findAll('email = ?', [email]) if users: raise APIValueError("email", "Email is already in used") uid = next_id() sha1_passwd = '%s:%s' % (email, password) user = User(name=name.strip(), email=email, password=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image="/static/img/user.png", admin=0) yield from user.save() #make session cooike r = web.Response() r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True) user.password = '******' r.content_type = "application/json" r.body = json.dumps(user, ensure_ascii=False).encode("utf-8") return r
def api_register_user(*, email, name, passwd): # https://www.python.org/dev/peps/pep-3102/ 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 already in use') uid = next_id() sha1_passwd = '%s:%s' % (uid, passwd) # get SHA1 for 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
def api_register_user(*, email, name, passwd): #判断name是否为空: if not name or not name.strip(): raise APIValueError('name') #判断email是否为空及是否满足email格式: if not email or not _RE_EMAIL.match(email): raise APIValueError('email') #判断password首付为空及是否满足password格式: if not passwd or not _RE_SHA1.match(passwd): raise APIValueError('passwd') #数据中查询对应的email信息: users = yield from User.findAll('email=?', [email]) #判断查询结果是否存在,若存在则返回异常提示邮件已存在: if len(users) > 0: raise APIError('register:failed', 'email', 'Email is already in use.') #生成唯一ID: uid = next_id() #重构唯一ID和password成新的字符串: sha1_passwd = '%s:%s' % (uid, passwd) #构建用户对象信息: #hashlib.sha1().hexdigest():取得SHA1哈希摘要算法的摘要值。 user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='http://www(first).gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest()) #将用户信息存储到数据库: yield from user.save() # make session cookie: #构造session cookie信息: r = web.Response() #aiohttp.web.StreamResponse().set_cookie():设置cookie的方法。 r.set_cookie(COOKIE_NAME, user2cookie(user, 86400), max_age=86400, httponly=True) #max_age:定义cookie的有效期(秒); user.passwd = '******' r.content_type = 'application/json' #以json格式序列化响应信息; ensure_ascii默认为True,非ASCII字符也进行转义。如果为False,这些字符将保持原样。 r.body = json.dumps(user, ensure_ascii=False).encode('utf-8') return r
async 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) 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()) 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
async def api_register_user(*, email, name, passwd): if not name or not name.strip(): raise APIValueError('name', 'Name must not be empty.') if not email or not _RE_EAMIL.match(email.lower()): raise APIValueError('email', 'Illegal email.') if not passwd or not _RE_SHA1.match(passwd): raise APIValueError('passwd', 'Illegal passwd.') uid = next_id() passwd_solted = '%s:%s' % (uid, passwd) passwd_sha1 = hashlib.sha1(passwd_solted.encode('utf-8')).hexdigest() image_url = 'http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5( email.encode('utf-8')).hexdigest() user = User(id=uid, name=name.strip(), email=email, passwd=passwd_sha1, image=image_url) 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
async def api_signup_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('signup:failed', 'email', 'Email is already in use') uid = next_id() sha1_passwd = '%s:%s' % (uid, passwd) if name == 'sharon': admin = 1 else: admin = 0 user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), admin=admin) 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
def test(loop): yield from orm.create_pool(loop=loop, user='******', password='******', database='awesome') u = User(admin=True, name='kHRYSTAL', email='*****@*****.**', passwd=hashlib.sha1( ('%s:%s' % (next_id(), 'yyg1990918')).encode('utf-8')).hexdigest(), image='about:blank') yield from u.save()
def api_register_user(*,email,name,passwd): if not name or not name.strip(): 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('register:failed', 'email', 'Email is already in use.') uid=next_id() user=User(id=uid,name=name,email=email,passwd=passwd,image='http://www.gravatar.com/avatar/%s?d=mm&s=120',created_at='1532590440.177') yield from user.save() r=web.Response() r.set_cookie(COOKIE_NAME,user,max_age=0,httponly=True) r.content_type='' r.body=json.dump(user,ensure_ascii=False).encode('utf-8') return r
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_password = '******' % (uid, passwd) user = User(id=uid, name=name.strip(), email=email,passwd=hashlib.sha1(sha1_password.encode('utf-8').hexdigest(), image='')) yield from user.save() 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).enconde('utf-8') return r
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() shal_passwd = '%s:%s' % (uid, passwd) user = User(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(shal_passwd.encode('utf-8')).hexdigest(), image='http://test.download.cycore.cn/test/5ed5fc74-f110-42df-ade8-c5a2f10d572a.png') 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
def register_check(*, email, password, name): """checking the information of the register user""" if not email or not email.strip(): raise APIValueError(field='email', message='Empty field.') if not password or not password.strip(): raise APIValueError(field='password', message='Empty field.') if not name or not name.strip(): raise APIValueError(field='name', message='Empty field.') # check email users = yield from find_models(model='user', where='email=?', args=[email]) if len(users) > 0: raise APIError(error='register:failed', data='email', message='Email is already exist.') uid = next_id() sha1_pwd = '%s:%s' % (uid, password) user = User(id=uid, name=name, email=email, password=hashlib.sha1(sha1_pwd.encode('utf-8')).hexdigest(), image='http://www.gravatar.com/avatar/%s?d=mm&s=120' % hashlib.md5(email.encode('utf-8')).hexdigest()) yield from save_model(user) # make the session cookie r = web.Response() r.set_cookie(name=COOKIE_NAME, value=user2cookie(user, 86400), max_age=86400, httponly=True) user.password = '******' r.content_type = 'application/json' r.body = json.dumps(user, ensure_ascii=False).encode('utf-8') return r
def test(loop): yield from orm.create_pool(loop=loop, user='******', password='******', database='awesome') u=User(admin=True, name='kHRYSTAL', email='*****@*****.**', passwd=hashlib.sha1(('%s:%s' % (next_id(), 'yyg1990918')).encode('utf-8')).hexdigest(), image='about:blank') yield from u.save()