def notify_managers_about_new_service_in_tariff(self, customer_id, flavor_name): customer = Customer.get_by_id(customer_id) if not customer: logbook.error("Customer {} not found in notify manager", customer_id) return logbook.info("notify manager about adding new service to tariff {}", customer.tariff.name) from api.admin.user import UserApi service_edit_url = urljoin( request_base_url(), posixpath.join(UserApi.ADMIN_FRONTEND_PATH, "tariffs", str(customer.tariff.tariff_id), "services")) customer_url = urljoin( request_base_url(), posixpath.join(UserApi.ADMIN_FRONTEND_PATH, "index", str(customer.customer_id), "info")) subject, body = MessageTemplate.get_rendered_message( MessageTemplate.NEW_SERVICE_IN_TARIFF, language=preferred_language(), account=customer.email, flavor_name=flavor_name, tariff=customer.tariff.name, customer_url=customer_url, service_edit_url=service_edit_url) logbook.info("Sending email notification to delete data of {}", customer.email) send_email.delay(get_customers_manager(customer), subject, body)
def send_email_about_balance_modifying(customer, delta, currency, balance, comment): assert isinstance(delta, Decimal) subscription_info = customer.subscription_info()['billing'] if subscription_info['enable']: modifying_date = utcnow().datetime if delta > 0: template_id = MessageTemplate.CUSTOMER_RECHARGE else: template_id = MessageTemplate.CUSTOMER_WITHDRAW base_url = request_base_url() from api.cabinet.customer import CustomerApi url = urljoin( base_url, posixpath.join(CustomerApi.CABINET_FRONTEND_PATH, "transactions")) subject, body = MessageTemplate.get_rendered_message( template_id, language=customer.locale_language(), money={ 'money': abs(delta), 'currency': currency }, balance={ 'money': balance, 'currency': currency }, comment=comment, withdraw_date=modifying_date, transactions_url=url) send_email.delay(subscription_info['email'], subject, body)
def request_password_reset(self, email): """ Sent email with link to reset password :param Email email: Email_ - user email :return: None. """ self.send_password_reset_email(email, request_base_url()) return {}
def notify_managers_about_new_service_in_tariff(self, customer_id, flavor_name): customer = Customer.get_by_id(customer_id) if not customer: logbook.error("Customer {} not found in notify manager", customer_id) return logbook.info("notify manager about adding new service to tariff {}", customer.tariff.name) from api.admin.user import UserApi service_edit_url = urljoin(request_base_url(), posixpath.join(UserApi.ADMIN_FRONTEND_PATH, "tariffs", str(customer.tariff.tariff_id), "services")) customer_url = urljoin(request_base_url(), posixpath.join(UserApi.ADMIN_FRONTEND_PATH, "index", str(customer.customer_id), "info")) subject, body = MessageTemplate.get_rendered_message(MessageTemplate.NEW_SERVICE_IN_TARIFF, language=preferred_language(), account=customer.email, flavor_name=flavor_name, tariff=customer.tariff.name, customer_url=customer_url, service_edit_url=service_edit_url) logbook.info("Sending email notification to delete data of {}", customer.email) send_email.delay(get_customers_manager(customer), subject, body)
def new_user(self, token, email, role, password=None, name=None): """ Registration of new user. :param Email email: User email (Email_); :param str password: User Password. If the it is empty then the password recovery email will be sent to the email. :param str role: User role. :param str name: User display name [optional] :returns dict user_info: User info. **Example**:: { "user_info": { {"name": "Super Admin", "deleted": null, "email": "*****@*****.**", "role": {'localized_name': {'en': 'Administrator', 'ru': 'Администратор'}, 'role_id': 'admin'} "created": "2015-04-24T11:14:22"} } } """ if not Role.validate(token.role, role): raise errors.UserInvalidRole() if token.role != Role.ADMIN and token.role == role: # user can administrate only users with low priority raise errors.UserInvalidRole() user_info = User.new_user(email, password, role, name=name) if not password: self.send_password_reset_email(email, request_base_url(), for_new_user=True) return {"user_info": display(user_info)}
def send_email_auto_payment_processed(cls, customer, delta, currency, card_type, card_last_four, comment, accepted=True): assert isinstance(delta, Decimal) subscription_info = customer.subscription_info()['billing'] if subscription_info['enable']: modifying_date = utcnow().datetime if accepted: template_id = MessageTemplate.CUSTOMER_RECHARGE_AUTO else: template_id = MessageTemplate.CUSTOMER_RECHARGE_AUTO_REJECT base_url = request_base_url() from api.cabinet.customer import CustomerApi url = urljoin( base_url, posixpath.join(CustomerApi.CABINET_FRONTEND_PATH, "transactions")) subject, body = MessageTemplate.get_rendered_message( template_id, language=customer.locale_language(), money={ 'money': abs(delta), 'currency': currency }, withdraw_date=modifying_date, card_type=card_type, card_last_four=card_last_four, transactions_url=url, comment=comment) send_email.delay(subscription_info['email'], subject, body)