def post(self): json_data = request.get_json(force=True) if not json_data: return {'message': 'No input data provided'}, 400 # Validate and deserialize input data, errors = user_schema.load(json_data) if errors: return errors, 400 user = User.query.filter_by(username=data['username']).first() if user: return {'message': 'user already exists'}, 400 user = User( username=json_data['username'], password = json_data['password'] ) user.save() result = user_schema.dump(user).data del result["password"] token = flask_jwt_extended.create_access_token(identity=result) result ["token"] = token return { "status": 'success', 'data': result }, 201
def register(fullname,username,password): user=User(full_name=fullname,user_name=username,password=password) user.save() wallet = Wallet.create(customer_id=user) transaction=Transaction.create(customer_id=user,timestamp=datetime.now()) print("Registration complete")
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 APIValueError('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
def test_save(loop): yield from orm.create_pool(loop, user='******', password='******', db='awesome') u = User(name='hi', email='*****@*****.**', passwd='hi', image='about:blank') # pdb.set_trace() yield from u.save()
def test(): yield from orm.create_pool(loop, user='******', password='******', database='awesome') u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank') yield from u.save()
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 APIValueError('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
def test(loop): yield from orm.create_pool(loop=loop,user='******', password='******', db='awesome') u = User(name='Test', email='*****@*****.**', passwd='1234567890', image='about:blank') yield from u.save()