Exemplo n.º 1
0
    def GET(self):
        self.view.partial("sidebar", "partials/admin/sidebar",
                          {"command": "users"})
        try:
            user = um.User(self.request.id)

        except NotFoundError:
            return NotFound()

        self.view.title = user.username

        deleted = self.request.get_param("d", False)
        reported = self.request.get_param("r", False)

        parts = {"user": user.id}

        if deleted:
            parts["deleted"] = True

        if reported:
            parts["reported"] = True

        query = r.table(rm.Recipe.table).filter(parts)
        res = RethinkCollection(rm.Recipe, query=query)
        page = Paginate(res,
                        self.request,
                        "title",
                        sort_direction_default="desc")

        return {"recipes": page, "user": user, "command": "recipes"}
Exemplo n.º 2
0
    def GET(self):
        self.view.partial("sidebar", "partials/admin/sidebar",
                          {"command": "users"})
        try:
            user = um.User(self.request.id)

        except NotFoundError:
            return NotFound()

        self.view.title = user.username

        disabled = self.request.get_param("q")
        hidden_ids = r.table(pm.Phot.table).filter({
            "user": user.id
        }).filter(r.row["disable"].eq(True)).concat_map(
            lambda doc: [doc["id"]]).coerce_to("array").run()

        if disabled == "enabled":
            query = r.table(pm.Phot.table).filter({
                "user": user.id
            }).filter(lambda doc: ~r.expr(hidden_ids).contains(doc["id"]))

        else:
            query = r.table(pm.Phot.table).filter({
                "user": user.id
            }).filter(lambda doc: r.expr(hidden_ids).contains(doc["id"]))

        res = RethinkCollection(pm.Phot, query=query)

        page = Paginate(res, self.request, "created")

        self.view.data = {"page": page, "user": user, "command": "phots"}

        return self.view
Exemplo n.º 3
0
    def GET(self):
        self.view.partial("sidebar", "partials/admin/sidebar", {"command": "users"})
        try:
            user = um.User(self.request.id)

        except NotFoundError:
            return NotFound()

        self.view.title = user.username

        t = self.request.get_param("filter", "to")
        if t == "cc":
            row_filt = "cc_addresses"
        elif t == "bcc":
            row_filt = "bcc_addresses"
        else:
            row_filt = "to_addresses"

        parts = r.table(em.Email.table).filter(lambda row: row[row_filt].contains(user.id))

        result = RethinkCollection(em.Email, query=parts)
        page = Paginate(result, self.request, "created", sort_direction_default="asc")

        self.view.data = {"page": page,
                          "user": user,
                          "command": "emails"}

        return self.view
Exemplo n.º 4
0
    def user(self, val):
        if isinstance(val, um.User):
            self._data[self._user_field] = val.id
        else:
            self._data[self._user_field] = val

        self._user_cache = um.User(self._data[self._user_field])
Exemplo n.º 5
0
    def POST(self):
        error = False
        user = um.User(self.session.id)

        email = self.request.get_param("email")
        password = self.request.get_param("password")

        if email and email != user.email:
            found = r.table(um.User.table).filter({"email": email})\
                .map(lambda u: u["id"]).coerce_to("array").run()

            if email in found:
                error = True
                self.view.data = {
                    "error":
                    "email",
                    "msg":
                    "That email is already registered, please choose another."
                }
            else:
                user.email = email

        if password:
            user.set_password(password)
            self.session.push_alert(
                "Password updated, please make sure to use it :)",
                level="warning")

        user.save()

        if error:
            return self.view

        return Redirect("/account")
Exemplo n.º 6
0
    def user(self, val):
        if isinstance(val, um.User):
            self.data["user"] = val.id
        else:
            self.data["user"] = val

        self._user_cache = um.User(self.data["user"]) if self.data["user"] else None
        self.data["groups"] = self._user_cache["groups"]
Exemplo n.º 7
0
    def who(self):
        if self.user:
            if not hasattr(self, "_formated_author"):
                self._formated_author = um.User(self.user)

            return self._formated_author
        else:
            return None
Exemplo n.º 8
0
    def who_cc(self):
        fin = []
        for user in self.cc_addresses:
            if "@" not in user:
                fin.append(um.User(user).email)
            else:
                fin.append(user)

        return fin
Exemplo n.º 9
0
 def user(self):
     if not hasattr(self, "_user_cache") or self._user_cache is None:
         if "user" in self.data:
             self._user_cache = um.User(self.data.get("user"))
             if not self._user_cache.id:
                 self._user_cache = None
         else:
             self._user_cache = None
     return self._user_cache
Exemplo n.º 10
0
    def build(self):
        email = em.Email(self.data)

        if email:
            logger.info("Sending email {}".format(email.id))

            to = [
                um.User(a).email if "@" not in a else a
                for a in email.to_addresses
            ]
            bcc = [
                um.User(a).email if "@" not in a else a
                for a in email.bcc_addresses
            ]
            cc = [
                um.User(a).email if "@" not in a else a
                for a in email.cc_addresses
            ]

            envelope = Envelope(from_addr="{}@transientbug.com".format(
                email.service),
                                to_addr=to,
                                bcc_addr=bcc,
                                cc_addr=cc,
                                subject=email.subject,
                                text_body=email.content["text"],
                                html_body=email.content["html"])

            if c.send_email:
                envelope.send('localhost', port=25)

            if c.debug:
                logger.info(email)

            email.sent = arrow.utcnow().timestamp
            email.save()
            logger.info("Sent email {}".format(email.id))
Exemplo n.º 11
0
    def GET(self):
        self.view.partial("sidebar", "partials/admin/sidebar",
                          {"command": "users"})
        try:
            user = um.User(self.request.id)

        except NotFoundError:
            return NotFound()

        print self.request.url_params

        self.view.title = user.username

        self.view.data = {"user": user, "command": ""}

        return self.view
Exemplo n.º 12
0
    def GET(self):
        self.view.partial("sidebar", "partials/admin/sidebar",
                          {"command": "users"})
        try:
            user = um.User(self.request.id)

        except NotFoundError:
            return NotFound()

        self.view.title = user.username

        # I should figure out a way to do this filter stuff a little easier... hmm
        filter_parts = {"user": user.id}
        public = self.request.get_param("public")
        draft = self.request.get_param("draft")
        disabled = self.request.get_param("disable")
        reported = self.request.get_param("reported", False)
        sort_by = self.request.get_param("sort_by", "created")

        if not sort_by in [
                "created", "title", "public", "reported", "draft", "disable",
                "author.id"
        ]:
            sort_by = "created"

            # should this be something I try to start doing? :/
            self.session.push_alert(
                "Couldn't figure out what to sort by, as a result of an invalid value for sort_by.",
                level="error")

        if public:
            filter_parts["public"] = False if public == "private" else True
        if draft:
            filter_parts["draft"] = False if draft == "published" else True
        if disabled:
            filter_parts["disable"] = False if disabled == "enabled" else True

        filter_parts["reported"] = reported

        q = r.table(nm.Note.table).filter(filter_parts)

        res = RethinkCollection(nm.Note, query=q)
        page = Paginate(res, self.request, sort_by)

        self.view.data = {"note_page": page, "user": user, "command": "notes"}

        return self.view
Exemplo n.º 13
0
    def login(self, user, password):
        """
        Tries to find the user in the database,then tries to use the plain text
        password from `password` to match against the known password hash in
        the users object. If the user is successfully logged in then the
        sessions `user` entry is set to that of the users id

        :param user: Str of the username or ID to try and login
        :type user: Str
        :param password: Clear text str of the users password to hash and check
        :type password: Str

        :returns: True if the user was successfully logged in

        :raises SessionError: Will raise a subclass of
            :py:class:`.SessionError` if there was a problem logging the user in
        """
        reg = "(?i)^{}$".format(user)
        foundUser = r.table(um.User.table)\
                .filter(lambda doc: doc["username"].match(reg))\
                .coerce_to("array")\
                .run()

        if foundUser:
            foundUser = um.User(**foundUser[0])
            if not foundUser.disable:
                if str(foundUser.password) == bcrypt.hashpw(str(password), str(foundUser.password)):
                    self.user = foundUser
                    return True

                else:
                    raise use.PasswordError("Your password appears to \
                            be wrong.")

            else:
                raise use.DisableError("Your user is currently disabled. \
                        Please contact an admin for additional information.")

        raise use.UsernameError("We can't find your user, are you \
                sure you have the correct information?")
Exemplo n.º 14
0
    def POST(self):
        try:
            user = um.User(self.request.id)
        except NotFoundError:
            return NotFound()

        password = self.request.get_param("password")
        disable = self.request.get_param("disable", False)
        email = self.request.get_param("email")
        groups = self.request.get_param("groups")
        clear_reset = self.request.get_param("clear_reset", False)

        if type(groups) is not list:
            groups = [groups]

        groups = [
            group.strip(" ").replace(" ", "_").lower() for group in groups
            if group
        ]

        user.groups = groups

        if password:
            user.set_password(password)
            self.session.push_alert(
                "Password updated, please let the user know the new password",
                level="warning")

        if email and email != user.email:
            # TODO: Only allow change if email isn't in the database yet
            user.email = email

        if clear_reset:
            del user.reset_code

        user.disable = disable

        user.save()

        return Redirect("/admin/users/" + self.request.id)
Exemplo n.º 15
0
    def GET(self):
        user = um.User(self.session.id)

        t = self.request.get_param("filter", "to")
        if t == "cc":
            row_filt = "cc_addresses"
        elif t == "bcc":
            row_filt = "bcc_addresses"
        else:
            row_filt = "to_addresses"

        parts = r.table(
            em.Email.table).filter(lambda row: row[row_filt].contains(user.id))

        result = RethinkCollection(em.Email, query=parts)
        page = Paginate(result,
                        self.request,
                        "created",
                        sort_direction_default="asc")

        self.view.data = {"user": user, "page": page, "command": "emails"}

        return self.view
Exemplo n.º 16
0
    def GET(self):
        user = um.User(self.session.id)

        self.view.data = {"user": user}
        return self.view
Exemplo n.º 17
0
 def user(self):
     if not hasattr(self, "_user_cache") or self._user_cache is None:
         self._user_cache = um.User(self._data.get(self._user_field))
         if not self._user_cache.id:
             self._user_cache = None
     return self._user_cache