Beispiel #1
0
 def index(self):
     """Handle the front-page."""
     remote_addr = request.environ.get("REMOTE_ADDR", "unknown addr")
     try:
         ip = IPAddress(remote_addr)
     except:
         ip = None
         pass
     if request.identity == None:
         flash(_("Only logged in users can access this site"))
         raise HTTPUnauthorized(_("Only logged in users can access this site"))
     userid = request.identity["repoze.who.userid"]
     user = User.by_user_name(userid)
     if not user:
         log.warn("User %s is not in the database, adding" % userid)
         newUser = User()
         newUser.user_name = userid
         newUser.display_name = request.identity["cn"][0]
         DBSession.add(newUser)
         user = newUser
     for network in excluded_networks:
         if ip in network:
             return dict(page="index", remote_addr=remote_addr, isHome=False, isExcluded=ip in network)
     if remote_addr != user.home_addr:
         user.travel_addr = remote_addr
         user.travel_updated = datetime.now()
         try:
             # if the task is already running just piggy back on the next
             # run
             add_single_task(action=sync_entries, taskname="sync", initialdelay=5)
         except ValueError:
             pass
     return dict(page="index", remote_addr=remote_addr, isHome=remote_addr == user.home_addr, isExcluded=False)
Beispiel #2
0
    def delHome(self, user_id=None, came_from=url("/admin")):
        """
        Redirect the user to the initially requested page when home is removed
        and inform the user the action was performed
        """
        if not user_id:
            user_name = request.identity["repoze.who.userid"]
            user = User.by_user_name(user_name)
        else:
            user = User.by_user_id(user_id)
        user.home_addr = None

        try:
            # if the task is already running just piggy back on the next run
            add_single_task(action=sync_entries, taskname="sync", initialdelay=5)
        except ValueError:
            pass
        flash(_("The home IP has been removed"))
        redirect(came_from)
Beispiel #3
0
    def delTravel(self, user_id, came_from=url("/admin")):
        """
        Redirect the user to the initially requested page when home is removed
        and inform the user the action was performed
        """
        user = User.by_user_id(user_id)
        user.travel_addr = None

        try:
            # if the task is already running just piggy back on the next run
            add_single_task(action=sync_entries, taskname="sync", initialdelay=5)
        except ValueError:
            pass
        flash(_("The travel IP has been removed"))
        redirect(came_from)
Beispiel #4
0
 def sethome(self, came_from=url("/")):
     """Handle homeip requests"""
     remote_addr = request.environ.get("REMOTE_ADDR", "unknown addr")
     msg = _("%s has been set as your home IP" % remote_addr)
     userid = request.identity["repoze.who.userid"]
     user = User.by_user_name(userid)
     user.home_addr = remote_addr
     user.home_updated = datetime.now()
     try:
         # if the task is already running just piggy back on the next run
         add_single_task(action=sync_entries, taskname="sync", initialdelay=5)
     except ValueError:
         pass
     try:
         ip = IPAddress(remote_addr)
     except:
         ip = None
         pass
     for network in excluded_networks:
         if ip in network:
             msg = _("%s has NOT been set as your home IP.  It is on an excluded network" % remote_addr)
             redirect(came_from)
     flash(msg)
     redirect(came_from)