Exemplo n.º 1
0
 def _new_map_from_user(self, user, name, filepath):
     """ Create a new mapfile entry in database. """
     map = Map(name, filepath)
     map.user = Session.query(User).filter(User.login==user).one()
     Session.add(map)
     Session.commit()
     return map
Exemplo n.º 2
0
 def _new_map_from_user(self, user, name, filepath):
     """ Create a new mapfile entry in database. """
     map = Map(name, filepath)
     map.user = Session.query(User).filter(User.login == user).one()
     Session.add(map)
     Session.commit()
     return map
Exemplo n.º 3
0
    def register(self):
        # ensure a login and password are not null
        if ("login" not in request.params or request.params["login"] == "") or (
            "password" not in request.params or request.params["password"] == ""
        ):
            session["flash"] = _("Login or password should not be empty. Please register again.")
            session.save()
            redirect_to(controller="main", action="signin")

        # ensure the login doesn't exceed 30 chars
        if len(request.params["login"]) > 30:
            session["flash"] = _("Login should not exceed 30 characters. Please register again.")
            session.save()
            redirect_to(controller="main", action="signin")

        # ensure a user with the same login does not exist
        user = meta.Session.query(User).filter(User.login == request.params["login"]).all()
        if len(user) != 0:
            session["flash"] = _('The login "%s" is already in use. Please register again.') % request.params["login"]
            session.save()
            redirect_to(controller="main", action="signin")

        # create a new user in default group
        gp = meta.Session.query(Group).filter(Group.name == config["default_group"]).one()
        new_user = User()
        new_user.name = request.params["login"]
        new_user.login = request.params["login"]
        new_user.password = request.params["password"]
        new_user.groups.append(gp)
        meta.Session.add(new_user)

        # create a sample mapfile for this new user
        mapfile_name = "Sample mapfile"
        mapfile = create_default_mapfile()
        # special mapfile for demo site
        # mapfile = Mapfile()
        # mapfile.from_file(os.path.join(config['mapserver_dir'],'demo_mapfile.map'))
        dict = mapfile.to_dict()
        if "projection" not in dict:
            dict["projection"] = "init=epsg:4326"
        mapfile.from_dict(dict)
        mapfile.set_name(mapfile_name)
        map_pathname = h.gen_mapname()
        mapfile.to_file(os.path.join(config["mapfiles_dir"], map_pathname))
        # create the map in db
        map = Map(mapfile_name, map_pathname)
        map.user = new_user
        meta.Session.add(map)

        meta.Session.commit()

        session["flash"] = _("You have just registered. Please log in to use Studio.")
        session.save()

        redirect_to(controller="main", action="signin")
Exemplo n.º 4
0
    def register(self):
        # ensure a login and password are not null
        if ('login' not in request.params or request.params['login'] == '') or \
           ('password' not in request.params or request.params['password'] == ''):
            session['flash'] = _(
                'Login or password should not be empty. Please register again.'
            )
            session.save()
            redirect_to(controller='main', action='signin')

        # ensure the login doesn't exceed 30 chars
        if len(request.params['login']) > 30:
            session['flash'] = _(
                'Login should not exceed 30 characters. Please register again.'
            )
            session.save()
            redirect_to(controller='main', action='signin')

        # ensure a user with the same login does not exist
        user = meta.Session.query(User).filter(
            User.login == request.params['login']).all()
        if len(user) != 0:
            session['flash'] = _('The login "%s" is already in use. Please register again.') \
                    %request.params['login']
            session.save()
            redirect_to(controller='main', action='signin')

        # create a new user in default group
        gp = meta.Session.query(Group).filter(
            Group.name == config["default_group"]).one()
        new_user = User()
        new_user.name = request.params['login']
        new_user.login = request.params['login']
        new_user.password = request.params['password']
        new_user.groups.append(gp)
        meta.Session.add(new_user)

        # create a sample mapfile for this new user
        mapfile_name = "Sample mapfile"
        mapfile = create_default_mapfile()
        # special mapfile for demo site
        #mapfile = Mapfile()
        #mapfile.from_file(os.path.join(config['mapserver_dir'],'demo_mapfile.map'))
        dict = mapfile.to_dict()
        if 'projection' not in dict:
            dict['projection'] = "init=epsg:4326"
        mapfile.from_dict(dict)
        mapfile.set_name(mapfile_name)
        map_pathname = h.gen_mapname()
        mapfile.to_file(os.path.join(config['mapfiles_dir'], map_pathname))
        # create the map in db
        map = Map(mapfile_name, map_pathname)
        map.user = new_user
        meta.Session.add(map)

        meta.Session.commit()

        session['flash'] = _(
            'You have just registered. Please log in to use Studio.')
        session.save()

        redirect_to(controller='main', action='signin')