def api_register_fbuser(*, email, name, passwd, number, birthday): 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') if not number.isdigit(): raise APIValueError('number should > 0') #if not birthday: # raise APIValueError('birthday') print("number:" + number) #validation user fbusers = yield from FBUser.findAll('email=?', [email]) if len(fbusers) > 0: raise APIError('register:failed', 'email', 'Email is already in use.') uid = next_id() sha1_passwd = '%s:%s' % (uid, passwd) fbuser = FBUser(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), number=number, birthday=birthday.strip()) yield from fbuser.save() # make session cookie: r = web.Response() r.set_cookie(COOKIE_NAME, user2cookie(fbuser, 86400), max_age=86400, httponly=True) fbuser.passwd = '******' r.content_type = 'application/json' r.body = json.dumps(fbuser, cls=CJsonEncoder, ensure_ascii=False).encode('utf-8') return r
def api_register_fbuser(*, 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 FBUser.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) fbuser = FBUser(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 fbuser.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 editpref(request): """lets the user set her preferences """ # me = request.facebook.graph.get_object('me') me = {} me['name'] = 'xyz' me['id'] = '69DFS3242R' try: # get user data from DB fbuser = FBUser.objects.get(fbid=me['id']) except FBUser.DoesNotExist: # that id is not in the DB, so create it # I am not using get_or_create() because # the user might have changed her name on FB fbuser = FBUser(fbid=me['id'], name=me['name']) fbuser.save() form = forms.UserPrefForm(instance=fbuser) #return render_to_response('editpref.html', # {'form': form}, # context_instance=RequestContext(request)) return render(request, 'editpref.html', {'form': form})
def api_register_fbuser(*, email, name, passwd, number, birthday): 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') if not number.isdigit(): raise APIValueError('number should > 0') #if not birthday: # raise APIValueError('birthday') print("number:" + number) #validation user fbusers = yield from FBUser.findAll('email=?', [email]) if len(fbusers) > 0: raise APIError('register:failed', 'email', 'Email is already in use.') uid = next_id() sha1_passwd = '%s:%s' % (uid, passwd) fbuser = FBUser(id=uid, name=name.strip(), email=email, passwd=hashlib.sha1( sha1_passwd.encode('utf-8')).hexdigest(), number=number, birthday=birthday.strip()) yield from fbuser.save() # make session cookie: r = web.Response() r.set_cookie(COOKIE_NAME, user2cookie(fbuser, 86400), max_age=86400, httponly=True) fbuser.passwd = '******' r.content_type = 'application/json' r.body = json.dumps(fbuser, cls=CJsonEncoder, ensure_ascii=False).encode('utf-8') return r
def api_register_fbuser(*, 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 FBUser.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) fbuser = FBUser(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 fbuser.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