async def find_orgnization_account(app, org_name, pancard, email): try: query = {"pancard": pancard, "org_name": org_name, "email": email} cursor = await r.table(app.config.DATABASE["users"])\ .filter(query)\ .run(app.config.DB) except Exception as e: logging.info(f"No account failed with error --<{e}>--") raise DBError(f"Database Error{e}") return await cursor_to_result(cursor)
async def insert_account(app, data): if not data: logging.info("Empty data cannot be insrted into the Database") return try: f = await r.table(app.config.DATABASE["users"])\ .insert(data)\ .run(app.config.DB) except Exception as e: logging.error(f"Insert account failed with error --<{e}>--") raise DBError(e) return
async def userLogin(request): message = json.loads(request.body) logger.debug(f'Message is: {message}') if 'macAddress' in message: mapper = group_mapper mapped_users = mapper.map(message) logger.debug(f'mapped_user is {mapped_users}') for user in mapped_users: try: provision_client(*user) logging.info(f"Provisioning user {user[2]} with MAC {user[1]} into group {user[3]}") except meraki.exceptions.APIError as e: logger.error( f"Meraki API error while provisioning client {user[2]} ({user[1]}) into network {user[0]}: {e}") return response.json(message, status=200)
async def claim_account(app, user_id, email, phone_number, indian_time): """ This will be called when the user claims its pending account on pending_users table, The account should already have been created in users table and now same user in pending_users table must be updated with "claimed_by": users_zero_pub claimed: True, claimed_on: Time stamp """ result = await r.table(app.config.DATABASE["pending_users"])\ .filter({"user_id": user_id, "email": email, "phone_number": phone_number})\ .update({"claimed": True, "claimed_on": indian_time})\ .run(app.config.DB) logging.info( f"Result after updating pending user table for {user_id} is {result}") if not bool(result): raise Exception("User coudnt be found in Pending table") return
async def insert_otps(app, _type, otp, user_id, value, validity): ##TODO make provision to block sending otp after 5 tries/ try: if _type == "email": data = { "email_otp": otp, "user_id": user_id, "validity": validity, "otp_verified": False, "email": value } logging.info(data) f = await r.table(app.config.DATABASE["otp_email"])\ .insert(data, conflict="update")\ .run(app.config.DB) else: data = { "mobile_otp": otp, "user_id": user_id, "validity": validity, "otp_verified": False, "phone_number": value } logging.info(data) f = await r.table(app.config.DATABASE["otp_mobile"])\ .insert(data, conflict="update")\ .run(app.config.DB) logging.info(f"Insert otp data successful with message --<{f}>--") except Exception as e: logging.error(f"Insert otp in {_type} failed with error --<{e}>--") return