def create(event, context): body = { "message": "Go Serverless v1.0! Your function executed successfully!", "input": event } # body = { # role : value # } # from event find pathParameters and extract id from there # if 'event' in event: # id = event['id'] # else: # body = {"Error" : "Manditory field ID not provided"} # return response = { # "statusCode": 500, # "body": json.dumps(body) # } # user = User.get(User.id == 1) # # user = User.get(id=id) payload = json.loads(event['body']) name = payload['name'] if 'name' in payload else None address1 = payload['address1'] if 'address1' in payload else None address2 = payload['address2'] if 'address2' in payload else None state = payload['state'] if 'state' in payload else None city = payload['city'] if 'city' in payload else None zip = payload['zip'] if 'zip' in payload else None phone = payload['phone'] if 'phone' in payload else None web = payload['web'] if 'web' in payload else None contact_name = payload[ 'contact_name'] if 'contact_name' in payload else None contact_email = payload[ 'contact_email'] if 'contact_email' in payload else None account = Account(name = name , address1 = address1, address2 = address2, state = state, \ city = city, zip = zip, phone = phone, web = web, contact_name = contact_name, contact_email = contact_email) account.save() # user = User(role = 'Admin', user_name = 'Sumanth', first_name = 'Sumanth', last_name = 'Reddy', phone_number = '+914567890987', email_id = '*****@*****.**') # user.save() response = {"statusCode": 200, "body": json.dumps(account.id)} return response # Use this code if you don't use the http event with the LAMBDA-PROXY # integration """
def post(self): # try: data = parser.parse_args() print(hashlib.md5(data['password'].encode()).hexdigest()) if User.query.filter(User.username == data['username']).first(): return {"error": "User already exists"} u = User(username=data['username'], password=hashlib.md5(data['password'].encode()).hexdigest()) u.save() s = Account(username=(data['username'])) s.save() access_token = create_access_token(identity=data['username']) refresh_token = create_refresh_token(identity=data['username']) return { 'username': data['username'], 'access_token': access_token, 'refresh_token': refresh_token }