Exemple #1
0
def login_verify():
    '''
    Verifies user login, provides session cookie if successful
    '''
    _forms = request.forms

    email = _forms.get('email')
    password = _forms.get('password')

    if login_verify_core(email, password) is True:

        if request.query.action:
            utils.safe_redirect(request.query.action)
        else:
            redirect(BASE_URL)

    else:
        tags = template_tags()

        tags.status = utils.Status(
            type='danger',
            no_sure=True,
            message="Email or password not found.")

        return template('ui/ui_login',
            **tags.__dict__)
Exemple #2
0
        def setup():
            global routes_ready

            if routes_ready is False:

                try:
                    url = bottle.request.urlparts

                    # let's assume there's always going to be redirection to hide the script name

                    path = url.path.rstrip('/').rsplit('/', 1)

                    settings.BASE_URL_PROTOCOL = url.scheme + "://"
                    # The URL scheme

                    settings.BASE_URL_NETLOC = url.netloc
                    # The server name

                    settings.BASE_URL_ROOT = settings.BASE_URL_PROTOCOL + settings.BASE_URL_NETLOC
                    # Everything up to the first / after the server name

                    settings.BASE_URL_PATH = path[0]
                    # Any additional path to the script (subdirectory)

                    settings.BASE_URL = settings.BASE_URL_ROOT + settings.BASE_URL_PATH
                    # The URL we use to reach the script by default

                    make_server(app, settings)

                    routes_ready = True

                except Exception as e:
                    return "Oops: {}".format(e)

            bottle.redirect(settings.BASE_PATH + '/install')
Exemple #3
0
 def wrapper(*a, **ka):
     try:
         user = is_logged_in_core(request)
     except UserNotFound:
         redirect(BASE_URL + "/login?action=" + parse.quote_plus(request.path))
     ka['_user'] = user
     return func (*a, **ka)
Exemple #4
0
        def setup():
            global routes_ready

            if routes_ready is False:

                try:
                    url = bottle.request.urlparts

                    # let's assume there's always going to be redirection to hide the script name

                    path = url.path.rstrip('/').rsplit('/', 1)

                    settings.BASE_URL_PROTOCOL = url.scheme + "://"
                    # The URL scheme

                    settings.BASE_URL_NETLOC = url.netloc
                    # The server name

                    settings.BASE_URL_ROOT = settings.BASE_URL_PROTOCOL + settings.BASE_URL_NETLOC
                    # Everything up to the first / after the server name

                    settings.BASE_URL_PATH = path[0]
                    # Any additional path to the script (subdirectory)

                    settings.BASE_URL = settings.BASE_URL_ROOT + settings.BASE_URL_PATH
                    # The URL we use to reach the script by default

                    make_server(app, settings)

                    routes_ready = True

                except Exception as e:
                    return "Oops: {}".format(e)

            bottle.redirect(settings.BASE_PATH + '/install')
Exemple #5
0
def page_preview(page_id):

    preview_url, page = page_preview_core(page_id)

    utils.disable_protection()

    from core.libs.bottle import redirect
    redirect("{}?_={}".format(preview_url, page.modified_date.microsecond))
Exemple #6
0
 def wrapper(*a, **ka):
     try:
         user = is_logged_in_core(request)
     except UserNotFound:
         redirect(BASE_URL + "/login?action=" +
                  parse.quote_plus(request.path))
     ka['_user'] = user
     return func(*a, **ka)
Exemple #7
0
def is_logged_in(request):
    '''
    Determines if a logged-in user exists, with a redirection wrapper.
    '''

    try:
        user = is_logged_in_core(request)
    except UserNotFound:
        redirect(BASE_URL + "/login?action=" + parse.quote_plus(request.url))
    return user
Exemple #8
0
def is_logged_in(request):
    '''
    Determines if a logged-in user exists, with a redirection wrapper.
    '''

    try:
        user = is_logged_in_core(request)
    except UserNotFound:
        redirect(BASE_URL + "/login?action=" + parse.quote_plus(request.url))
    return user
Exemple #9
0
def new_category(blog_id):

    from core.models import db
    with db.atomic() as txn:

        user = auth.is_logged_in(request)
        blog = Blog.load(blog_id)
        permission = auth.is_blog_editor(user, blog)

        category_list = [n for n in blog.categories]

        category = Category(id=0,
            title='',
            blog=blog)

        top_level_category = Category(
            id=None,
            title='[Top-level category]',
            parent=None
            )

        category_list.insert(0, top_level_category)

        tags = template_tags(
            blog=blog,
            user=user)

    if request.method == "POST":
        with db.atomic() as txn:
            category_title = request.forms.getunicode('category_title')
            try:
                parent_category = int(request.forms.getunicode('category_parent'))
            except ValueError:
                parent_category = None

            with db.atomic() as txn:

                category = Category(blog=blog,
                    title=category_title,
                    parent_category=parent_category
                    )
                category.save()

        redirect('{}/blog/{}/category/{}'.format(
            BASE_URL, blog.id, category.id))

    tpl = template('edit/category',
        category=category,
        category_list=category_list,
        menu=generate_menu('blog_new_category', category),
        search_context=(search_contexts['sites'], None),
        **tags.__dict__)

    return tpl
Exemple #10
0
def template_preview(template_id):
    '''
    Wrapper for previewing a template, as we need to elegantly handle any exceptions
    raised in the underlying process
    '''
    try:
        redirection = template_preview_core(template_id)
    except Exception as e:
        raise e
    else:
        redirect(redirection)
Exemple #11
0
def page_preview(page_id):

    preview_url, page = page_preview_core(page_id)

    utils.disable_protection()

    from core.libs.bottle import redirect
    redirect ("{}?_={}".format(
        preview_url,
        page.modified_date.microsecond
        ))
Exemple #12
0
def disable_plugin(plugin_id):
    with db.atomic():
        try:
            plugin_to_disable = Plugin.select().where(Plugin.id == plugin_id).get()
        except BaseException:
            raise ("Plugin not found")
        else:
            if plugin_to_disable.enabled is False:
                bottle.redirect(BASE_PATH + "/system/plugins")
            else:
                plugin_to_disable.enabled = False
                plugin_to_disable.save()
    from core.boot import reboot
    reboot()
Exemple #13
0
def new_category(blog_id):

    from core.models import db
    with db.atomic() as txn:

        user = auth.is_logged_in(request)
        blog = Blog.load(blog_id)
        permission = auth.is_blog_editor(user, blog)

        category_list = [n for n in blog.categories]

        category = Category(id=0, title='', blog=blog)

        top_level_category = Category(id=None,
                                      title='[Top-level category]',
                                      parent=None)

        category_list.insert(0, top_level_category)

        tags = template_tags(blog=blog, user=user)

    if request.method == "POST":
        with db.atomic() as txn:
            category_title = request.forms.getunicode('category_title')
            try:
                parent_category = int(
                    request.forms.getunicode('category_parent'))
            except ValueError:
                parent_category = None

            with db.atomic() as txn:

                category = Category(blog=blog,
                                    title=category_title,
                                    parent_category=parent_category)
                category.save()

        redirect('{}/blog/{}/category/{}'.format(BASE_URL, blog.id,
                                                 category.id))

    tpl = template('edit/category',
                   category=category,
                   category_list=category_list,
                   menu=generate_menu('blog_new_category', category),
                   search_context=(search_contexts['sites'], None),
                   **tags.__dict__)

    return tpl
Exemple #14
0
def step(step):

    if get_ini('main', 'BASE_URL_ROOT') is not None:
        _s.BASE_URL_ROOT = get_ini('main', 'BASE_URL_ROOT')
        _s.BASE_URL_PATH = get_ini('main', 'BASE_URL_PATH')
        _s.BASE_URL = _s.BASE_URL_ROOT + _s.BASE_URL_PATH

    error_msg = None

    if request.method == "POST":

        try:
            results = step_text[step]['post-step']()
        except SetupError as e:
            results = step_text[step]['pre-step']()
            error_msg = e
        else:
            step += 1
            redirect('{}/install/step-{}'.format(_s.BASE_URL, step))

    else:
        try:
            results = step_text[step]['pre-step']()
        except SetupError as e:
            error_msg = e
            results = {}

    if error_msg is None:
        template_button = button(step, step_text[step]['next_action'])
    else:
        template_button = button(step, None, error_msg)

    return template(tpl,
                    settings=_s,
                    step=step,
                    title=step_text[step]['title'],
                    text=template(step_text[step]['text'],
                                  button=template_button,
                                  form_action='{}/install/step-{}'.format(
                                      _s.BASE_URL, step),
                                  **results),
                    crumbs=crumbs(step),
                    error=error_msg)
Exemple #15
0
def step(step):

    if get_ini('main', 'BASE_URL_ROOT') is not None:
        _s.BASE_URL_ROOT = get_ini('main', 'BASE_URL_ROOT')
        _s.BASE_URL_PATH = get_ini('main', 'BASE_URL_PATH')
        _s.BASE_URL = _s.BASE_URL_ROOT + _s.BASE_URL_PATH

    error_msg = None

    if request.method == "POST":

        try:
            results = step_text[step]['post-step']()
        except SetupError as e:
            results = step_text[step]['pre-step']()
            error_msg = e
        else:
            step += 1
            redirect('{}/install/step-{}'.format(_s.BASE_URL, step))

    else:
        try:
            results = step_text[step]['pre-step']()
        except SetupError as e:
            error_msg = e
            results = {}

    if error_msg is None:
        template_button = button(step, step_text[step]['next_action'])
    else:
        template_button = button(step, None, error_msg)

    return template(tpl,
        settings=_s,
        step=step,
        title=step_text[step]['title'],
        text=template(step_text[step]['text'],
            button=template_button,
            form_action='{}/install/step-{}'.format(_s.BASE_URL, step),
            **results),
        crumbs=crumbs(step),
        error=error_msg)
Exemple #16
0
def new_template(blog_id, tpl_type):
    with db.atomic() as txn:
        user = auth.is_logged_in(request)
        blog = Blog.load(blog_id)
        permission = auth.is_blog_designer(user, blog)

        auth.check_template_lock(blog)

        mappings_index = template_mapping_index.get(tpl_type, None)
        if mappings_index is None:
            raise Exception('Mapping type not found')

        template = Template(
            blog=blog,
            theme=blog.theme,
            template_type=tpl_type,
            publishing_mode=publishing_mode.do_not_publish,
            body='',
        )
        template.save(user)
        template.title = 'Untitled Template #{}'.format(template.id)
        template.save(user)

        if tpl_type != template_type.media:

            new_template_mapping = TemplateMapping(
                template=template,
                is_default=True,
                path_string="'" + utils.create_basename(template.title, blog) +
                "'")

            new_template_mapping.save()
            from core.cms import fileinfo
            fileinfo.build_mapping_xrefs((new_template_mapping, ))

    from settings import BASE_URL
    redirect(BASE_URL + '/template/{}/edit'.format(template.id))
Exemple #17
0
def login_verify():
    '''
    Verifies user login, provides session cookie if successful
    '''
    _forms = request.forms

    email = _forms.get('email')
    password = _forms.get('password')

    if login_verify_core(email, password) is True:

        if request.query.action:
            utils.safe_redirect(request.query.action)
        else:
            redirect(BASE_URL)

    else:
        tags = template_tags()

        tags.status = utils.Status(type='danger',
                                   no_sure=True,
                                   message="Email or password not found.")

        return template('ui/ui_login', **tags.__dict__)
Exemple #18
0
def system_new_user():

    from core.models import db

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    nav_tabs = None
    status = None

    from core.models import User

    if request.method == 'POST':

        new_name = request.forms.getunicode('user_name')
        new_email = request.forms.getunicode('user_email')
        new_password = request.forms.getunicode('user_password')
        new_password_confirm = request.forms.getunicode('user_password_confirm')

        from core.error import UserCreationError

        from core.libs import peewee

        # TODO: make this into a confirmation function a la what we did with blog settings

        new_user = User(
            name=new_name,
            email=new_email,
            password=new_password,
            password_confirm=new_password_confirm)

        try:
            new_user.save_pwd()

        except UserCreationError as e:
            status = utils.Status(
                type='danger',
                no_sure=True,
                message='There were problems creating the new user:'******'danger',
                no_sure=True,
                message='There were problems creating the new user:'******'The new user\'s email or username is the same as another user\'s. Emails and usernames must be unique.']
                )


        except Exception as e:
            raise e
        else:
            db.commit()
            from settings import BASE_URL
            return redirect(BASE_URL + '/system/user/{}'.format(new_user.id))

    else:
        new_user = User(name='',
            email='',
            password='')

    tags = template_tags(user=user)
    tags.status = status

    tpl = template('edit/user_settings',
        edit_user=new_user,
        menu=generate_menu('system_create_user', new_user),
        search_context=(search_contexts['sites'], None),
        nav_tabs=nav_tabs,
        nav_default='basic',
        **tags.__dict__
        )

    return tpl
Exemple #19
0
def safe_redirect(url):
    url_unquoted = urllib.parse.unquote_plus(url)
    if url_unquoted.startswith(BASE_URL + "/"):
        redirect(url)
    else:
        redirect(BASE_URL)
Exemple #20
0
def system_new_user():

    from core.models import db

    user = auth.is_logged_in(request)
    permission = auth.is_sys_admin(user)

    nav_tabs = None
    status = None

    from core.models import User

    if request.method == 'POST':

        new_name = request.forms.getunicode('user_name')
        new_email = request.forms.getunicode('user_email')
        new_password = request.forms.getunicode('user_password')
        new_password_confirm = request.forms.getunicode(
            'user_password_confirm')

        from core.error import UserCreationError

        from core.libs import peewee

        # TODO: make this into a confirmation function a la what we did with blog settings

        new_user = User(name=new_name,
                        email=new_email,
                        password=new_password,
                        password_confirm=new_password_confirm)

        try:
            new_user.save_pwd()

        except UserCreationError as e:
            status = utils.Status(
                type='danger',
                no_sure=True,
                message='There were problems creating the new user:'******'danger',
                no_sure=True,
                message='There were problems creating the new user:'******'The new user\'s email or username is the same as another user\'s. Emails and usernames must be unique.'
                ])

        except Exception as e:
            raise e
        else:
            db.commit()
            from settings import BASE_URL
            return redirect(BASE_URL + '/system/user/{}'.format(new_user.id))

    else:
        new_user = User(name='', email='', password='')

    tags = template_tags(user=user)
    tags.status = status

    tpl = template('edit/user_settings',
                   edit_user=new_user,
                   menu=generate_menu('system_create_user', new_user),
                   search_context=(search_contexts['sites'], None),
                   nav_tabs=nav_tabs,
                   nav_default='basic',
                   **tags.__dict__)

    return tpl