def get_info(): global temp_user cur_user = DbUser(temp_user.address, temp_user.name, temp_user.phone, temp_user.headers) cur_user.id = DbUser.get_id_by_email(temp_user.address) if not cur_user.id: DbUser.create(cur_user.email, cur_user.name, cur_user.phone, cur_user.creds) else: DbUser.update_creds(cur_user.id, cur_user.creds) session_id = session.login_user(temp_user.address) my_logger.debug(session.users_dict) my_logger.debug("LOGGED IN NEW USER!") my_logger.debug("email: %s", cur_user.email) my_logger.debug("user_id: %s", cur_user.id) my_logger.debug("\nUser: %s", temp_user.address) my_logger.debug(temp_user.freebusy) # Clear all of the "old" ranges the user currently has Range.delete_user_ranges(cur_user.id) # Create the new ranges in our database for c_range in temp_user.freebusy: Range.create_range(cur_user.id, c_range['start'], c_range['end']) # Build the HTTP response res = flask.jsonify(freebusy=temp_user.freebusy, name=temp_user.name, phone=temp_user.phone, session_id=session_id) my_logger.debug("callback response: %s", res.get_data(as_text=True)) return res
def callback(): global current_handler_instance name, user_address, phone, pic_url, freebusy, headers =\ current_handler_instance.callback_handler() print("user info:", name, user_address, phone, pic_url, len(freebusy)) cur_user = DbUser(user_address, name, phone, headers) # current user cur_user.id = DbUser.get_id_by_email(user_address) if not cur_user.id: c_user_id = DbUser.create(cur_user.email, name, phone, headers) else: DbUser.update_creds(cur_user.id, headers) session_id = session.login_user(user_address) my_logger.debug(session.users_dict) my_logger.debug("LOGGED IN NEW USER!") my_logger.debug("email: %s", cur_user.email) my_logger.debug("user_id: %s", cur_user.id) my_logger.debug("\nUser: %s", user_address) my_logger.debug(freebusy) # Clear all of the "old" ranges the user currently has Range.delete_user_ranges(cur_user.id) # Create the new ranges in our database for c_range in freebusy: Range.create_range(cur_user.id, c_range['start'], c_range['end']) # Build the HTTP response res = flask.jsonify(freebusy=freebusy, name=name, phone=phone, session_id=session_id) my_logger.debug("callback response: %s", res.get_data(as_text=True)) return res
def refresh_one_user_ranges_token(user_id, user_token): current_handler_instance = RequestHandler(None) freebusy = current_handler_instance.get_user_ranges(authorization=user_token) # Clear all of the "old" ranges the user currently has Range.delete_user_ranges(user_id) # Create the new ranges in our database for c_range in freebusy: Range.create_range(user_id, c_range['start'], c_range['end'])
def new_range(): params = flask.request.args session_id = params.get(SESSION_ID_HTTP_PARAM_NAME) try: owner_id = session.handle_user_user_id(session_id) except Unauthorized: return unauthorized_resp start: datetime = params.get('start') end: datetime = params.get('end') # owner_id = DbUser.get_id_by_email(current_user.email) # owner_id = DbUser.get_id_by_email("*****@*****.**") # owner_id = current_user.id # owner_address = session.get_address_by_session_id(session_id) # owner_id = DbUser.get_id_by_email(owner_address) print(start, end) now = datetime.now(tz=timezone(timedelta(hours=2), 'IST')) new_start: datetime = datetime.strptime(start, "%H:%M") final_start = datetime(now.year, now.month, now.day, new_start.hour, new_start.minute).isoformat() + 'Z' new_end: datetime = datetime.strptime(end, "%H:%M") final_end = datetime(now.year, now.month, now.day, new_end.hour, new_end.minute).isoformat() + 'Z' # final_start: datetime = datetime.strptime(start, "%H:%M %Y-%m-%dT%H:%M:%SZ") # final_end: datetime = datetime.strptime(end, "%H:%M %Y-%m-%dT%H:%M:%SZ") print(final_start, final_end) success = Range.create_range(owner_id, final_start, final_end) res = flask.jsonify(success=success) return res
def ranges_callback(): global current_quickstart_instance my_logger.debug("ranges callback") freebusy, user_address, name, phone, user_credentials = current_quickstart_instance.make_requests( ) cur_user = DbUser(user_address, name, phone, user_credentials) # current user my_logger.debug("cUser after constructor:") my_logger.debug(cur_user) cur_user.id = DbUser.get_id_by_email(user_address) my_logger.debug("user.id in callback: %s", cur_user.id) if not cur_user.id: c_user_id = DbUser.create(cur_user.email, name, phone, user_credentials) else: DbUser.update_creds(cur_user.id, user_credentials) # logging in the user session_id = session.login_user(user_address) my_logger.debug(session.users_dict) my_logger.debug("LOGGED IN NEW USER!") my_logger.debug("email: %s", cur_user.email) my_logger.debug("user_id: %s", cur_user.id) my_logger.debug("\nUser: %s", user_address) my_logger.debug(freebusy) # Clear all of the "old" ranges the user currently has Range.delete_user_ranges(cur_user.id) # Create the new ranges in our database for c_range in freebusy: Range.create_range(cur_user.id, c_range['start'], c_range['end']) # Build the HTTP response res = flask.jsonify(freebusy=freebusy, name=name, phone=phone, session_id=session_id) my_logger.debug("callback response: %s", res.get_data(as_text=True)) return res
def refresh_one_user_ranges(user_id, user_creds): first = list(user_creds.keys())[0] if type(first) is int: current_handler_instance = RequestHandler(None) name, user_address, phone, pic_url, freebusy, headers = \ current_handler_instance.get_user_ranges(authorization=user_creds) else: # user_creds: dict[int: Credentials] = self.get_user_creds(user_id) # print("creating quickstart instance") current_quickstart_instance = Quickstart() # print("making the requests") freebusy, user_address, name, phone, user_credentials = \ current_quickstart_instance.make_requests(given_creds=user_creds) # print("done") # print(freebusy) # cur_user = DbUser(user_address, name, phone, user_credentials) # user_id = DbUser.get_id_by_email(user_address) # Clear all of the "old" ranges the user currently has Range.delete_user_ranges(user_id) # Create the new ranges in our database for c_range in freebusy: Range.create_range(user_id, c_range['start'], c_range['end'])