Beispiel #1
0
    def index(self, locker=None, sudo=False):
        """Handle the front-page."""
        if locker is not None and request.response_ext:
            locker += request.response_ext

        olocker = locker
        hosts = None
        user = auth.current_user()
        https = auth.is_https()
        # Find or create the associated user info object.
        # TODO: is there a find_or_create sqlalchemy method?
        if user:
            if sudo and auth.on_scripts_team():
                # override_template(self.index, 'mako:scripts.templates.confirm')
                # return dict(action=url('/new/'+locker),title="Really use Scripts Team bits to request a hostname as locker '%s'?"%locker,question="Only do this in response to a user support request, and after checking to make sure that the request comes from someone authorized to make requests for the locker.",
                #           backurl=url('/index'))
                redirect("/new/%s?confirmed=true" % locker)
            try:
                user_info = (
                    DBSession.query(UserInfo).filter(UserInfo.user == user).one()
                )
            except NoResultFound:
                user_info = UserInfo(user)
                DBSession.add(user_info)
        else:
            user_info = None

        if user is not None:
            if locker is None:
                locker = user
            try:
                hosts = vhosts.list_vhosts(locker)
                hosts.sort(key=lambda k: k[0])
            except auth.AuthError as e:
                flash(e.message)
                # User has been deauthorized from this locker
                if locker in user_info.lockers:
                    user_info.lockers.remove(locker)
                    DBSession.add(user_info)
                if olocker is not None:
                    return self.index()
                else:
                    return dict(hosts={}, locker=locker, user_info=user_info)
            else:
                # Append locker to the list in user_info if it's not there
                if not locker in user_info.lockers:
                    user_info.lockers.append(locker)
                    user_info.lockers.sort()
                    DBSession.add(user_info)
                    flash('You can administer the "%s" locker.' % locker)
        return dict(hosts=hosts, locker=locker, user_info=user_info, https=https)
Beispiel #2
0
def scripts_team_only(func, *args, **kw):
    if not auth.on_scripts_team():
        flash("You are not authorized for this area!")
        redirect("/")
    else:
        return func(*args, **kw)