def signup(self, payload): """ signup function :return: """ try: check_email = email(check=True) payload["email"] = check_email(payload["email"]) except Exception as ex: abort(400, Message="Invalid email") if payload.get('password') != payload.get('confirm_password'): abort(400, Message="Password does not match") count, records = base_obj.get(Collections.USERS, {"email": payload['email']}) if count > 0: abort(400, Message="Email ID Already Exists") payload = custom_marshal(payload, user, 'create') payload['password'] = sha256_crypt.encrypt(payload['password']) _id = base_obj.insert(Collections.USERS, payload) print(_id, type(_id)) link = ACTIVATION_MAIL.format(id=_id) print(link) send_mail([payload['email']], "Corona Location App Account Activation", link, 'signup.html', { 'link': link, 'name': payload['first_name'] })
def create_room(self, payload): """ Create Room for an User :param payload: :return: """ payload = custom_marshal(payload, room_record, 'create') _id = base_obj.insert(COLLECTIONS['ROOMS'], payload)
def create_location(self, payload): """ Create Location for an User :param payload: :return: """ payload = custom_marshal(payload, location_record, 'create') _id = base_obj.insert(Collections.LOCATIONS, payload)
def create_task(self, id, payload): """ Create a task in task room :param payload: :return: """ payload = custom_marshal(payload, task_db_input, 'create') payload['_id'] = ObjectId() result = base_obj.update(COLLECTIONS['ROOMS'], {'_id': ObjectId(id)}, {"$push": { 'tasks': payload }})
def update_room(self, id, payload): """ Update Room :param payload: :return: """ payload = custom_marshal(payload, room_request, 'update') email = get_jwt_identity() result = base_obj.update(COLLECTIONS['ROOMS'], { "_id": ObjectId(id), "meta.created_by": email }, {"$set": payload}) print(result.modified_count) if not result.modified_count: abort(401, "Unauthorized")
def signup(self, payload): """ signup function :return: """ if payload.get('password') != payload.get('confirm_password'): abort(400, "Password does not match") count, records = base_obj.get(COLLECTIONS['USERS'], {"email": payload['email']}) if count > 0: abort(400, "Email ID Already Exists") payload = custom_marshal(payload, user, 'create') payload['password'] = sha256_crypt.encrypt(payload['password']) _id = base_obj.insert(COLLECTIONS['USERS'], payload) print(_id, type(_id)) link = ACTIVATION_MAIL.format(id=_id) print(link)
def create_inventory(self, payload): """ Function to create inventory in mongo :param payload: :return: """ count, records = base_obj.get( COLLECTIONS['INVENTORIES'], { "$and": [{ "inventory_name": payload['inventory_name'] }, { "sigla": payload['sigla'] }] }) if count > 0: abort(400, "Inventory Already Exists") payload = custom_marshal(payload, inventory_record, 'create') _id = base_obj.insert(COLLECTIONS['INVENTORIES'], payload) print(_id, type(_id))
def update_task(self, taskroom_id, task_id, payload): """ Update the task id with payload :param taskroom_id: :param task_id: :param payload: :return: """ email = get_jwt_identity() payload = custom_marshal(payload, task_request, 'update', prefix="tasks.$") result = base_obj.update( COLLECTIONS['ROOMS'], { '_id': ObjectId(taskroom_id), "tasks._id": ObjectId(task_id), "users": email }, {"$set": payload}) print(payload, result)