Ejemplo n.º 1
0
def invite():
    """Send invitation.

    Admins are allowed to invite admins and members, members - only members.
    """
    masks = row_mysql_queries.get_masks()
    form = forms.Invite()
    if form.validate_on_submit():
        # Check if required conf setting exists
        _conf = flask.current_app.config
        if not 'KEYSTONE_CONF' in _conf or not 'NEO4J_API_URL' in _conf:
            raise Exception("""No required settings:
            KEYSTONE_CONF or NEO4J_API_URL, invitations wasn't sent""", "")
        user_email = form.email.data
        if not utils.username_is_taken(user_email):
            try:
                utils.neo4j_api_call('/users', {
                    "email": user_email
                }, 'GET')[0]
                flask.flash(
                    'User with email "%s" is already registered' % user_email,
                    'error')
            except (KeyError, NotFound):
                # NOTE(apugachev) success, user does not exist
                hash_code = str(uuid.uuid4())
                domain = user_email.split('@')[-1]
                if (domain,) not in masks:
                    flask.flash('Not allowed email mask')
                else:
                    row_mysql_queries.save_invitation(
                        user_email, hash_code, form.role.data)
                    invite_link = flask.url_for('.finish', invitation_hash=hash_code)
                    msg = mail.Message('Invitation', recipients=[user_email])
                    msg.body = flask.render_template(
                        'invitations/email_body.txt', invite_link=invite_link)
                    utils.send_msg(msg)
                    flask.flash('Invitation sent successfully', 'info')
    return {
        'form': form,
        'masks': masks,
        'title': bp.name.replace('_', ' ').capitalize(),
        'subtitle': 'Send invitation'
    }
Ejemplo n.º 2
0
def invite():
    """Send invitation.

    Admins are allowed to invite admins and members, members - only members.
    """
    masks = row_mysql_queries.get_masks()
    form = forms.Invite()
    if form.validate_on_submit():
        # Check if required conf setting exists
        _conf = flask.current_app.config
        if not 'KEYSTONE_CONF' in _conf or not 'NEO4J_API_URL' in _conf:
            raise Exception(
                """No required settings:
            KEYSTONE_CONF or NEO4J_API_URL, invitations wasn't sent""", "")
        user_email = form.email.data
        if not utils.username_is_taken(user_email):
            try:
                utils.neo4j_api_call('/users', {"email": user_email}, 'GET')[0]
                flask.flash(
                    'User with email "%s" is already registered' % user_email,
                    'error')
            except (KeyError, NotFound):
                # NOTE(apugachev) success, user does not exist
                hash_code = str(uuid.uuid4())
                domain = user_email.split('@')[-1]
                if (domain, ) not in masks:
                    flask.flash('Not allowed email mask')
                else:
                    row_mysql_queries.save_invitation(user_email, hash_code,
                                                      form.role.data)
                    invite_link = flask.url_for('.finish',
                                                invitation_hash=hash_code)
                    msg = mail.Message('Invitation', recipients=[user_email])
                    msg.body = flask.render_template(
                        'invitations/email_body.txt', invite_link=invite_link)
                    utils.send_msg(msg)
                    flask.flash('Invitation sent successfully', 'info')
    return {
        'form': form,
        'masks': masks,
        'title': bp.name.replace('_', ' ').capitalize(),
        'subtitle': 'Send invitation'
    }
Ejemplo n.º 3
0
                for r in all_roles:
                    if r.name.lower() == role.lower():
                        clients.admin_clients().keystone.roles.add_user_role(
                            new_keystone_user, r,
                            tenant=clients.get_systenant_id()
                        )
                        break
                else:
                    flask.current_app.logger(
                        'Matching Keystone role for %s nto found.' % role.lower(), 
                        'error')
            return new_keystone_user
        except Exception, e:
            raise Exception("Registration fail", e.message)

    if utils.username_is_taken(email):
        raise Exception('Username is already taken')

    keystone_user = register_in_keystone()

    if keystone_user is not None:
        try:
            user = _register_in_ODB(username, email, password)
            return user
        except Exception, e:
            # revert new user creation in Keystone
            roles = keystone_user.list_roles()
            for role in roles:
                clients.admin_clients().keystone.tenants.remove_user(
                    role.tenant['id'], keystone_user, role.role['id'])
            clients.admin_clients().keystone.users.delete(keystone_user)
Ejemplo n.º 4
0
                for r in all_roles:
                    if r.name.lower() == role.lower():
                        clients.admin_clients().keystone.roles.add_user_role(
                            new_keystone_user,
                            r,
                            tenant=clients.get_systenant_id())
                        break
                else:
                    flask.current_app.logger(
                        'Matching Keystone role for %s nto found.' %
                        role.lower(), 'error')
            return new_keystone_user
        except Exception, e:
            raise Exception("Registration fail", e.message)

    if utils.username_is_taken(email):
        raise Exception('Username is already taken')

    keystone_user = register_in_keystone()

    if keystone_user is not None:
        try:
            user = _register_in_ODB(username, email, password)
            return user
        except Exception, e:
            # revert new user creation in Keystone
            roles = keystone_user.list_roles()
            for role in roles:
                clients.admin_clients().keystone.tenants.remove_user(
                    role.tenant['id'], keystone_user, role.role['id'])
            clients.admin_clients().keystone.users.delete(keystone_user)