def signup_activation(session, state, tid, token, language): node = config.ConfigFactory(session, 1, 'node') if not node.get_val(u'enable_signup'): raise errors.ForbiddenOperation signup = session.query(models.Signup).filter( models.Signup.activation_token == token).one_or_none() if signup is None: return {} if not session.query( models.Config).filter(models.Config.tid == signup.tid).count(): tenant = session.query( models.Tenant).filter(models.Tenant.id == signup.tid).one() mode = node.get_val('mode') db_initialize_tenant(session, tenant, mode) password_admin = generateRandomKey(16) password_recipient = generateRandomKey(16) node_name = signup.organization_name if signup.organization_name else signup.subdomain wizard = { 'node_language': signup.language, 'node_name': node_name, 'admin_name': signup.name + ' ' + signup.surname, 'admin_password': password_admin, 'admin_mail_address': signup.email, 'receiver_name': signup.name + ' ' + signup.surname, 'receiver_password': password_recipient, 'receiver_mail_address': signup.email, 'profile': 'default', 'enable_developers_exception_notification': True } db_wizard(session, state, signup.tid, wizard, False, language) ids = [ r[0] for r in session.query(models.User.id).filter( models.UserTenant.user_id == models.User.id, models.UserTenant.tenant_id == signup.tid) ] template_vars = { 'type': 'activation', 'node': db_admin_serialize_node(session, 1, language), 'notification': db_get_notification(session, 1, language), 'signup': serialize_signup(signup), 'password_admin': password_admin, 'password_recipient': password_recipient } state.format_and_send_mail(session, 1, {'mail_address': signup.email}, template_vars) db_refresh_memory_variables(session, [1])
def signup_activation(session, state, tid, token, language): config = ConfigFactory(session, 1) if not config.get_val(u'enable_signup'): raise errors.ForbiddenOperation signup = session.query(models.Signup).filter(models.Signup.activation_token == token).one_or_none() if signup is None: return {} if not session.query(models.Config).filter(models.Config.tid == signup.tid).count(): tenant = session.query(models.Tenant).filter(models.Tenant.id == signup.tid).one() mode = config.get_val('mode') db_initialize_tenant(session, tenant, mode) password_admin = generateRandomKey(16) password_recipient = generateRandomKey(16) node_name = signup.organization_name if signup.organization_name else signup.subdomain wizard = { 'node_language': signup.language, 'node_name': node_name, 'admin_name': signup.name + ' ' + signup.surname, 'admin_password': password_admin, 'admin_mail_address': signup.email, 'receiver_name': signup.name + ' ' + signup.surname, 'receiver_password': password_recipient, 'receiver_mail_address': signup.email, 'profile': 'default', 'enable_developers_exception_notification': True } db_wizard(session, signup.tid, wizard, False, language) ids = [r[0] for r in session.query(models.User.id).filter(models.UserTenant.user_id == models.User.id, models.UserTenant.tenant_id == signup.tid)] template_vars = { 'type': 'activation', 'node': db_admin_serialize_node(session, 1, language), 'notification': db_get_notification(session, 1, language), 'signup': serialize_signup(signup), 'password_admin': password_admin, 'password_recipient': password_recipient } state.format_and_send_mail(session, 1, {'mail_address': signup.email}, template_vars) db_refresh_memory_variables(session, [1])
def signup_activation(session, token, hostname, language): """ Transaction registering the activation of a platform registered via signup :param session: An ORM session :param token: A activation token :param language: A language of the request """ config = ConfigFactory(session, 1) if not config.get_val('enable_signup'): raise errors.ForbiddenOperation ret = session.query(models.Signup, models.Tenant) \ .filter(models.Signup.activation_token == token, models.Tenant.id == models.Signup.tid).one_or_none() if ret is None: return {} signup, tenant = ret[0], ret[1] signup.activation_token = None mode = config.get_val('mode') db_initialize_tenant(session, tenant, mode) password_admin = generateRandomKey(16) password_receiver = generateRandomKey(16) node_name = signup.organization_name if signup.organization_name else signup.subdomain wizard = { 'node_language': signup.language, 'node_name': node_name, 'admin_username': '******', 'admin_name': signup.name + ' ' + signup.surname, 'admin_password': password_admin, 'admin_mail_address': signup.email, 'receiver_username': '******', 'receiver_name': signup.name + ' ' + signup.surname, 'receiver_password': password_receiver, 'receiver_mail_address': signup.email, 'profile': 'default', 'skip_recipient_account_creation': False, 'enable_developers_exception_notification': True } db_wizard(session, signup.tid, hostname, wizard) template_vars = { 'type': 'activation', 'node': db_admin_serialize_node(session, 1, language), 'notification': db_get_notification(session, 1, language), 'signup': serialize_signup(signup), 'password_admin': wizard['admin_password'], 'password_recipient': wizard['receiver_password'] } State.format_and_send_mail(session, 1, {'mail_address': signup.email}, template_vars) db_refresh_memory_variables(session, [signup.tid])
def signup_activation(session, state, tid, token, language): node = config.ConfigFactory(session, 1, 'node') if not node.get_val(u'enable_signup'): raise errors.ForbiddenOperation signup = session.query(models.Signup).filter( models.Signup.activation_token == token).one_or_none() if signup is None: return {} if not session.query( models.Config).filter(models.Config.tid == signup.tid).count(): db_initialize_tenant(session, signup.tid) create_admin = not node.get_val(u'signup_no_admin_user') if create_admin: signup.password_admin = generateRandomKey(16) signup.password_recipient = generateRandomKey(16) wizard = { 'node_language': signup.language, 'node_name': signup.subdomain, 'admin_name': signup.name + ' ' + signup.surname, 'admin_password': signup.password_admin, 'admin_mail_address': signup.email, 'receiver_name': signup.name + ' ' + signup.surname, 'receiver_password': signup.password_recipient, 'receiver_mail_address': signup.email, 'profile': 'default', 'enable_developers_exception_notification': True } db_wizard(session, state, signup.tid, wizard, create_admin, False, language) ids = [ r[0] for r in session.query(models.User.id).filter( models.UserTenant.user_id == models.User.id, models.UserTenant.tenant_id == signup.tid) ] session.query(models.User).filter(models.User.id.in_(ids)).update( {'password_change_needed': False}, synchronize_session='fetch') template_vars = { 'type': 'activation', 'node': db_admin_serialize_node(session, 1, language), 'notification': db_get_notification(session, 1, language), 'signup': serialize_signup(signup), 'activation_url': '', 'expiration_date': datetime_to_ISO8601(signup.registration_date + timedelta(days=30)) } state.format_and_send_mail(session, 1, {'mail_address': signup.email}, template_vars) if session.query(models.Tenant).filter( models.Tenant.id == signup.tid).one_or_none() is not None: admin = session.query(models.User).filter( models.User.role == u'admin', models.User.username == u'admin', models.UserTenant.user_id == models.User.id, models.UserTenant.tenant_id == signup.tid).one_or_none() recipient = session.query(models.User).filter( models.User.role == u'receiver', models.User.username == u'recipient', models.UserTenant.user_id == models.User.id, models.UserTenant.tenant_id == signup.tid).one_or_none() ret_dict = { 'platform_url': 'https://%s.%s' % (signup.subdomain, node.get_val(u'rootdomain')), 'login_url': 'https://%s.%s/#/login' % (signup.subdomain, node.get_val(u'rootdomain')), 'expiration_date': datetime_to_ISO8601(signup.registration_date + timedelta(days=7)) } if admin is not None: ret_dict['login_url_admin'] = 'https://%s.%s/#/login?token=%s' % ( signup.subdomain, node.get_val(u'rootdomain'), admin.auth_token) ret_dict['password_admin'] = signup.password_admin if recipient is not None: ret_dict[ 'login_url_recipient'] = 'https://%s.%s/#/login?token=%s' % ( signup.subdomain, node.get_val(u'rootdomain'), recipient.auth_token) ret_dict['password_recipient'] = signup.password_recipient return ret_dict return {}