示例#1
0
def signup(session, state, tid, request, language):
    node = config.ConfigFactory(session, 1, 'node')

    if not node.get_val(u'enable_signup'):
        raise errors.ForbiddenOperation

    request['activation_token'] = generateRandomKey(32)
    request['language'] = language

    signup = models.Signup(request)

    session.add(signup)

    session.flush()

    ret = {
        'signup':
        serialize_signup(signup),
        'activation_url':
        'https://%s/#/activation?token=%s' %
        (node.get_val(u'rootdomain'), signup.activation_token),
        'expiration_date':
        datetime_to_ISO8601(signup.registration_date + timedelta(days=30))
    }

    # We need to send two emails
    #
    # The first one is sent to the platform owner with the activation email.
    #
    # The second goes to the instance administrators notifying them that a new
    # platform has been added.

    # Email 1 - Activation Link
    template_vars = copy.deepcopy(ret)
    template_vars.update({
        'type':
        'signup',
        'node':
        db_admin_serialize_node(session, 1, language),
        'notification':
        db_get_notification(session, 1, language),
    })

    state.format_and_send_mail(session, 1, {'mail_address': signup.email},
                               template_vars)

    # Email 2 - Admin Notification
    for user_desc in db_get_admin_users(session, 1):
        template_vars = copy.deepcopy(ret)
        template_vars.update({
            'type':
            'admin_signup_alert',
            'signup':
            serialize_signup(signup),
            'node':
            db_admin_serialize_node(session, 1, user_desc['language']),
            'notification':
            db_get_notification(session, 1, user_desc['language']),
            'user':
            user_desc
        })

        state.format_and_send_mail(session, 1, user_desc, template_vars)

    return ret
示例#2
0
 def generate_proof_of_work(self):
     if State.tenant_cache[self.tid].enable_proof_of_work:
         self.proof_of_work = {
             'question': generateRandomKey(20),
             'solved': False
         }
示例#3
0
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 {}
示例#4
0
def get_auth_token():
    return text_type(generateRandomKey(32))
示例#5
0
 def __init__(self, tid, user_id, user_role, user_status):
     self.id = generateRandomKey(42)
     self.tid = tid
     self.user_id = user_id
     self.user_role = user_role
     self.user_status = user_status
示例#6
0
def fsops_pgp_encrypt(state, sf, key, fingerprint):
    """
    Encrypt the file for a speficic key

    return
        path of encrypted file,
        length of the encrypted file
    """
    pgpctx = PGPContext(state.settings.tmp_path)

    pgpctx.load_key(key)

    with sf.open('rb') as f:
        encrypted_file_path = os.path.join(os.path.abspath(state.settings.attachments_path), "pgp_encrypted-%s" % generateRandomKey(16))
        _, encrypted_file_size = pgpctx.encrypt_file(fingerprint, f, encrypted_file_path)

    return encrypted_file_path, encrypted_file_size
示例#7
0
def get_auth_token():
    return unicode(generateRandomKey(32))