class RegistrantsHook(EventBaseHook): RE = r'(?P<event>[\w\s]+)/registrants' METHOD_NAME = 'export_registrants' NO_CACHE = True def _getParams(self): super(RegistrantsHook, self)._getParams() self._conf_id = self._pathParams['event'] self._conf = ConferenceHolder().getById(self._conf_id) def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw) def export_registrants(self, aw): registrants = self._conf.getRegistrantsList() registrant_list = [] for registrant in registrants: reg = { "registrant_id": registrant.getId(), "checked_in": registrant.isCheckedIn(), "full_name": registrant.getFullName(title=True, firstNameFirst=True), "checkin_secret": registrant.getCheckInUUID(), } regForm = self._conf.getRegistrationForm() reg["personal_data"] = regForm.getPersonalData().getRegistrantValues(registrant) registrant_list.append(reg) return {"registrants": registrant_list}
def _checkParams(self): event = ConferenceHolder().getById(request.view_args['event_id'], True) if event is None: raise NotFound("No such event") if not event.canManageRegistration(request.oauth.user): raise Forbidden() self.event = event
class SetPaidHook(EventBaseHook): PREFIX = "api" RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/pay' METHOD_NAME = 'api_pay' NO_CACHE = True COMMIT = True HTTP_POST = True def _getParams(self): super(SetPaidHook, self)._getParams() self.auth_key = get_query_parameter(self._queryParams, ["auth_key"]) self.is_paid = get_query_parameter(self._queryParams, ["is_paid"]) == "yes" registrant_id = self._pathParams["registrant_id"] self._conf = ConferenceHolder().getById(self._pathParams['event']) self._registrant = self._conf.getRegistrantById(registrant_id) if not payment_event_settings.get(self._conf, 'enabled'): raise HTTPAPIError('E-payment is not enabled') def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw) def api_pay(self, aw): action = TransactionAction.complete if self._isPayed == '1' else TransactionAction.cancel register_transaction(registrant=self._registrant, amount=self._registrant.getTotal(), currency=self._registrant.getCurrency(), action=action) return { "paid": self._registrant.getPayed(), "amount_paid": self._registrant.getTotal() }
class CheckInHook(EventBaseHook): PREFIX = "api" RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/checkin' METHOD_NAME = 'api_checkin' NO_CACHE = True COMMIT = True HTTP_POST = True def _getParams(self): super(CheckInHook, self)._getParams() self._check_in = get_query_parameter(self._queryParams, ["checked_in"]) == "yes" self._secret = get_query_parameter(self._queryParams, ["secret"]) registrant_id = self._pathParams["registrant_id"] self._conf = ConferenceHolder().getById(self._pathParams['event']) self._registrant = self._conf.getRegistrantById(registrant_id) def _hasAccess(self, aw): return (self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw)) \ and self._secret == self._registrant.getCheckInUUID() def api_checkin(self, aw): self._registrant.setCheckedIn(self._check_in) checkin_date = format_datetime(self._registrant.getAdjustedCheckInDate(), format="short") return { "checked_in": self._check_in, "checkin_date": checkin_date if self._check_in else None }
class RegistrantHook(EventBaseHook): RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)' NO_CACHE = True def _getParams(self): super(RegistrantHook, self)._getParams() self._secret = get_query_parameter(self._queryParams, ["secret"]) self._conf = ConferenceHolder().getById(self._pathParams['event']) registrant_id = self._pathParams["registrant_id"] self._registrant = self._conf.getRegistrantById(registrant_id) self._type = "registrant" def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) and self._secret == self._registrant.getCheckInUUID() def export_registrant(self, aw): registration_date = format_datetime(self._registrant.getAdjustedRegistrationDate(), format="short") checkin_date = format_datetime(self._registrant.getAdjustedCheckInDate(), format="short") self._registrant.getPayed() result = { "registrant_id": self._registrant.getId(), "full_name": self._registrant.getFullName(title=True, firstNameFirst=True), "checked_in": self._registrant.isCheckedIn(), "checkin_date": checkin_date if self._registrant.isCheckedIn() else None, "registration_date": registration_date, "payed": self._registrant.getPayed() if self._conf.getModPay().isActivated() else None, "pay_amount": self._registrant.getTotal() if self._conf.getModPay().isActivated() else None } regForm = self._conf.getRegistrationForm() personalData = regForm.getPersonalData().getRegistrantValues(self._registrant) result.update(personalData) return result
class UpdatePictureHook(EventBaseHook): PREFIX = "api" RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/updatepicture' METHOD_NAME = 'api_update_picture' NO_CACHE = True COMMIT = True HTTP_POST = True def _getParams(self): super(UpdatePictureHook, self)._getParams() self._picture_payload = get_query_parameter(self._queryParams, ["picture_uri"]) self._secret = get_query_parameter(self._queryParams, ["secret"]) registrant_id = self._pathParams["registrant_id"] self._conf = ConferenceHolder().getById(self._pathParams['event']) self._registrant = self._conf.getRegistrantById(registrant_id) def _hasAccess(self, aw): return (self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw)) \ and self._secret == self._registrant.getCheckInUUID() def api_update_picture(self, aw): try: from indico.util.data_uri import DataURI uri = DataURI(self._picture_payload) path = self._registrant.getPicture().getFilePath() data = uri.data _file = open(path,'w') _file.write(data) _file.close() return {"status": "true"} except: return {"status": "false"}
class UpdatePassportHook(EventBaseHook): PREFIX = "api" RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/updatepassport' METHOD_NAME = 'api_update_passport' NO_CACHE = True COMMIT = True HTTP_POST = True def _getParams(self): super(UpdatePassportHook, self)._getParams() raw_passport_info = str(get_query_parameter(self._queryParams, ["passport_info"])) self._passport_info = json.loads(raw_passport_info,object_hook=ascii_encode_dict) self._secret = get_query_parameter(self._queryParams, ["secret"]) registrant_id = self._pathParams["registrant_id"] self._conf = ConferenceHolder().getById(self._pathParams['event']) self._registrant = self._conf.getRegistrantById(registrant_id) def _hasAccess(self, aw): return (self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw)) \ and self._secret == self._registrant.getCheckInUUID() def api_update_passport(self, aw): try: self._registrant.updateFromPassportScan(self._passport_info) return {"status": "true"} except Exception as e: return {"status": "false"}
class RegistrantHook(EventBaseHook): RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)' METHOD_NAME = 'export_registrant' NO_CACHE = True DEFAULT_DETAIL = 'basic' def _getParams(self): super(RegistrantHook, self)._getParams() self.auth_key = get_query_parameter(self._queryParams, ["auth_key"]) self._conf = ConferenceHolder().getById(self._pathParams['event']) registrant_id = self._pathParams["registrant_id"] self._registrant = self._conf.getRegistrantById(registrant_id) def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw) def export_registrant(self, aw): expInt = RegistrantFetcher(aw, self) return expInt.registrant()
class BaseRegistrantsHook(EventBaseHook): METHOD_NAME = 'export_registrants' NO_CACHE = True def _getParams(self): super(BaseRegistrantsHook, self)._getParams() self._conf_id = self._pathParams['event'] self._conf = ConferenceHolder().getById(self._conf_id) self._registrants = self._conf.getRegistrantsList() def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw) def export_registrants(self, aw,bysession=None): registrant_list = [] for registrant in self._registrants: skip = False if bysession: sess = registrant.getSession(bysession) if sess is None: skip = True else: checkedIn = sess.isCheckedIn() else: checkedIn = registrant.isCheckedIn(), if not skip: reg = { "registrant_id": registrant.getId(), "checked_in": checkedIn, "full_name": registrant.getFullName(title=True, firstNameFirst=True), "checkin_secret": registrant.getCheckInUUID(), } if bysession: reg["session"]=bysession regForm = self._conf.getRegistrationForm() reg["personal_data"] = regForm.getPersonalData().getRegistrantValues(registrant) registrant_list.append(reg) return {"registrants": registrant_list}
class SetPaidHook(EventBaseHook): PREFIX = "api" RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/pay' METHOD_NAME = 'api_pay' NO_CACHE = True COMMIT = True HTTP_POST = True def _getParams(self): super(SetPaidHook, self)._getParams() self.auth_key = get_query_parameter(self._queryParams, ["auth_key"]) self.is_paid = get_query_parameter(self._queryParams, ["is_paid"]) == "yes" registrant_id = self._pathParams["registrant_id"] self._conf = ConferenceHolder().getById(self._pathParams['event']) self._registrant = self._conf.getRegistrantById(registrant_id) if not self._conf.getModPay().isActivated(): raise HTTPAPIError('E-payment is not enabled') def _hasAccess(self, aw): return self._conf.canManageRegistration( aw.getUser()) or self._conf.canModify(aw) def api_pay(self, aw): if self.is_paid: self._registrant.setPayed(True) data = {} data["OrderTotal"] = self._registrant.getTotal() data["Currency"] = self._registrant.getRegistrationForm( ).getCurrency() transaction = TransactionPayLaterMod(data) self._registrant.setTransactionInfo(transaction) else: self._registrant.setTransactionInfo(None) self._registrant.setPayed(False) return { "paid": self._registrant.getPayed(), "amount_paid": self._registrant.getTotal() }
class SetPaidHook(EventBaseHook): PREFIX = "api" RE = r'(?P<event>[\w\s]+)/registrant/(?P<registrant_id>[\w\s]+)/pay' METHOD_NAME = 'api_pay' NO_CACHE = True COMMIT = True HTTP_POST = True def _getParams(self): super(SetPaidHook, self)._getParams() self.auth_key = get_query_parameter(self._queryParams, ["auth_key"]) self.is_paid = get_query_parameter(self._queryParams, ["is_paid"]) == "yes" registrant_id = self._pathParams["registrant_id"] self._conf = ConferenceHolder().getById(self._pathParams['event']) self._registrant = self._conf.getRegistrantById(registrant_id) if not self._conf.getModPay().isActivated(): raise HTTPAPIError('E-payment is not enabled') def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw) def api_pay(self, aw): if self.is_paid: self._registrant.setPayed(True) data = {} data["OrderTotal"] = self._registrant.getTotal() data["Currency"] = self._registrant.getRegistrationForm().getCurrency() transaction = TransactionPayLaterMod(data) self._registrant.setTransactionInfo(transaction) else: self._registrant.setTransactionInfo(None) self._registrant.setPayed(False) return { "paid": self._registrant.getPayed(), "amount_paid": self._registrant.getTotal() }
class BaseRegistrantHook(EventBaseHook): METHOD_NAME = 'export_registrant' NO_CACHE = True DEFAULT_DETAIL = 'basic' def _getParams(self): super(BaseRegistrantHook, self)._getParams() self.auth_key = get_query_parameter(self._queryParams, ["auth_key"]) self._conf = ConferenceHolder().getById(self._pathParams['event']) registrant_id = self._pathParams["registrant_id"] self._registrant = self._conf.getRegistrantById(registrant_id) def _hasAccess(self, aw): return self._conf.canManageRegistration(aw.getUser()) or self._conf.canModify(aw) def export_registrant(self, aw, bysession=None): expInt = RegistrantFetcher(aw, self) result = expInt.registrant() if bysession and not self._registrant.getSession(bysession): result["canEnter"] = False result["canEnterMessage"] = "The registrant is not approved for this session" return result