Ejemplo n.º 1
0
    def modify(self):
        self._object = user = usergroup.User(env.request.parameters.get("name", env.request.user.name))

        if not env.request.parameters["language"] in localization.getLanguagesIdentifiers():
            raise error.PrewikkaUserError(N_("Invalid Language"), N_("Specified language does not exist"), log_priority=log.WARNING)

        list(hookmanager.trigger("HOOK_USERMANAGEMENT_USER_MODIFY", user))
        if not env.request.parameters["timezone"] in localization.get_timezones():
            raise error.PrewikkaUserError(N_("Invalid Timezone"), N_("Specified timezone does not exist"), log_priority=log.WARNING)

        need_reload = False
        user.begin_properties_change()

        for param, reload in (("fullname", False), ("email", False), ("theme", True), ("language", True), ("timezone", False)):
            if user == env.request.user and reload and env.request.parameters.get(param) != user.get_property(param):
                need_reload = True

            user.set_property(param, env.request.parameters.get(param))

        if user == env.request.user:
            user.set_locale()

        user.commit_properties_change()

        # Make sure nothing is returned (reset the default dataset)
        env.request.dataset = None

        if need_reload:
            return response.PrewikkaDirectResponse({"type": "reload"})

        return response.PrewikkaRedirectResponse(url_for(".display"), 303)
Ejemplo n.º 2
0
    def render(self):
        login = self.parameters.get("login", self.user.login)

        if login != self.user.login and not self.user.has(User.PERM_USER_MANAGEMENT):
            raise Error.PrewikkaUserError("Permission Denied", "Cannot modify other users settings", log=Log.WARNING)

        if self.user.has(User.PERM_USER_MANAGEMENT):
            self.env.db.setPermissions(login, self.parameters["permissions"])
            if login == self.user.login:
                self.user.permissions = self.parameters["permissions"]

        lang = self.parameters["language"]
        if not lang in localization.getLanguagesIdentifiers():
            raise Error.PrewikkaUserError("Invalid Language", "Specified language does not exist", log=Log.WARNING)

        if login == self.user.login:
            self.user.setLanguage(lang)

        self.env.db.setLanguage(login, lang)

        if self.parameters.has_key("password_new") and self.parameters.has_key("password_new_confirmation"):
            if login == self.user.login:
                try:
                    self.env.auth.checkPassword(login, self.parameters.get("password_current", ""))
                except Auth.AuthError, e:
                    raise Error.PrewikkaUserError("Password Error", "Invalid Password specified")

            if self.parameters["password_new"] != self.parameters["password_new_confirmation"]:
                raise Error.PrewikkaUserError("Password Error", "Password mismatch")

            self.env.auth.setPassword(login, self.parameters["password_new"])
Ejemplo n.º 3
0
    def render(self):
        login = self.parameters.get("name", env.request.user.name)

        self._object = user = usergroup.User(login)

        env.db.set_property(user, "fullname", self.parameters.get("fullname"))
        env.db.set_property(user, "email", self.parameters.get("email"))
        env.db.set_property(user, "theme", self.parameters.get("theme"))

        lang = self.parameters["language"]
        if not lang in localization.getLanguagesIdentifiers():
            raise error.PrewikkaUserError(
                _("Invalid Language"), N_("Specified language does not exist"), log_priority=log.WARNING
            )

        env.db.set_property(user, "language", lang)
        if user == env.request.user:
            env.request.user.set_locale()

        timezone = self.parameters["timezone"]
        if not timezone in localization.get_timezones():
            raise error.PrewikkaUserError(
                _("Invalid Timezone"), N_("Specified timezone does not exist"), log_priority=log.WARNING
            )

        env.db.set_property(user, "timezone", timezone)

        # Make sure nothing is returned (reset the default dataset)
        self.dataset = None