Esempio n. 1
0
def logout(req):
    # if the session has expired, there may be no user in the session dictionary
    user = req.session.get("user", None)
    if user and user.getUserType() in users.getDynamicUserAuthenticators():
        users.authenticators[user.getUserType()].log_user_out(user.dirid, req.session.id)
    try:
        del req.session["user"]
    except:
        pass
    req.request["Location"] = req.makeLink("node", {"id": tree.getRoot("collections").id})
    return httpstatus.HTTP_MOVED_TEMPORARILY
Esempio n. 2
0
def logout(req):
    # if the session has expired, there may be no user in the session dictionary
    user = req.session.get("user", None)
    if user and user.getUserType() in users.getDynamicUserAuthenticators():
        users.authenticators[user.getUserType()].log_user_out(
            user.dirid, req.session.id)
    try:
        del req.session["user"]
    except:
        pass
    req.request["Location"] = req.makeLink(
        "node", {"id": tree.getRoot("collections").id})
    return httpstatus.HTTP_MOVED_TEMPORARILY
Esempio n. 3
0
def validate(req, op):
    """standard validator"""
    try:

        if "style" in req.params:
            req.write(view(req))
            return ""

        for key in req.params.keys():
            if key.startswith("new"):
                # create new user
                return editUser_mask(req, "")

            elif key.startswith("edit_"):
                # edit user
                return editUser_mask(req, str(key[key.index("_") + 1:-2]))

            elif key.startswith("sendmail_") and req.params.get("form_op", "") != "cancel":
                # send email
                return sendmailUser_mask(req, str(key[key.index("_") + 1:-2]))

            elif key.startswith("delete_"):
                # delete user
                user_from_request = users.getUserFromRequest(req)
                username_from_form = key[7:-2]
                dyn_auths = getDynamicUserAuthenticators()
                isDynamic = False
                for dyn_auth in dyn_auths:
                    if username_from_form.startswith(dyn_auth + "|"):
                        isDynamic = (username_from_form, dyn_auth)
                        break
                if isDynamic:
                    log.info("%r is requesting logout of dynamic user %r (%r)" % (user_from_request.getName(), isDynamic[0], isDynamic[1]))
                    deleteUser(isDynamic[0], isDynamic[1])
                else:
                    usertype = req.params.get("usertype", "intern")
                    usernode = getUser(key[7:-2])
                    if not usertype.strip():
                        usertype = usernode.getUserType()
                        if usertype == 'users':
                            # function deleteUser expects usertype='intern'
                            # for children if root->users, but getUserType()
                            # returns 'users' for those
                            usertype = 'intern'
                    log.info("%r is requesting deletion of user %r (%r, %r)" %
                             (user_from_request.getName(), usernode.name, usernode.id, usertype))
                    deleteUser(usernode, usertype=usertype)
                    del_index = users_cache.index(usernode)

                    del users_cache[del_index]

                searchterm_was = req.params.get("searchterm_was", "")
                if searchterm_was:
                    req.params['action'] = 'search'
                    req.params['searchterm'] = searchterm_was
                    req.params['use_macro'] = 'view'
                    req.params['execute_search'] = searchterm_was

                break

            elif key.startswith("tointern_"):
                moveUserToIntern(key[9:-2])
                break

            elif key.startswith("reset_"):
                # reset password
                if req.params["change_passwd"] != "":
                    getUser(key[6:-2]).resetPassword(req.params["change_passwd"])
                else:
                    getUser(key[6:-2]).resetPassword(config.settings["user.passwd"])
                break

        if "form_op" in req.params.keys():
            _option = ""
            for key in req.params.keys():
                if key.startswith("option_"):
                    _option += key[7]

            if req.params.get("form_op") == "save_new":
                # save user values
                if req.params.get("username", "") == "" or req.params.get("usergroups", "") == "" or req.params.get("email", "") == "":
                    return editUser_mask(req, "", 1)  # no username or group selected
                elif existUser(req.params.get("username")):
                    return editUser_mask(req, "", 2)  # user still existing
                else:
                    create_user(
                        req.params.get("username"),
                        req.params.get("email"),
                        req.params.get("usergroups").replace(
                            ";",
                            ","),
                        pwd=req.params.get(
                            "password",
                            ""),
                        lastname=req.params.get(
                            "lastname",
                            ""),
                        firstname=req.params.get("firstname"),
                        telephone=req.params.get("telephone"),
                        comment=req.params.get("comment"),
                        option=_option,
                        organisation=req.params.get(
                            "organisation",
                            ""),
                        identificator=req.params.get(
                            "identificator",
                            ""),
                        type=req.params.get(
                            "usertype",
                            "intern"))

            elif req.params["form_op"] == "save_edit":
                # update user
                if req.params.get("email", "") == "" or req.params.get("username", "") == "" or req.params.get("usergroups", "") == "":
                    return editUser_mask(req, req.params.get("id"), 1)  # no username, email or group selected
                else:
                    update_user(
                        req.params.get(
                            "id",
                            0),
                        req.params.get(
                            "username",
                            ""),
                        req.params.get(
                            "email",
                            ""),
                        req.params.get(
                            "usergroups",
                            "").replace(
                            ";",
                            ","),
                        lastname=req.params.get("lastname"),
                        firstname=req.params.get("firstname"),
                        telephone=req.params.get("telephone"),
                        comment=req.params.get("comment"),
                        option=_option,
                        organisation=req.params.get(
                            "organisation",
                            ""),
                        identificator=req.params.get(
                            "identificator",
                                ""),
                        type=req.params.get(
                            "usertype",
                            "intern"))

            flush_users_cache()
        return view(req)
    except:
        print "Warning: couldn't load module for type", type
        print sys.exc_info()[0], sys.exc_info()[1]
        traceback.print_tb(sys.exc_info()[2])
Esempio n. 4
0
def validate(req, op):
    """standard validator"""
    try:

        if "style" in req.params:
            req.write(view(req))
            return ""

        for key in req.params.keys():
            if key.startswith("new"):
                # create new user
                return editUser_mask(req, "")

            elif key.startswith("edit_"):
                # edit user
                return editUser_mask(req, str(key[key.index("_") + 1:-2]))

            elif key.startswith("sendmail_") and req.params.get(
                    "form_op", "") != "cancel":
                # send email
                return sendmailUser_mask(req, str(key[key.index("_") + 1:-2]))

            elif key.startswith("delete_"):
                # delete user
                user_from_request = users.getUserFromRequest(req)
                username_from_form = key[7:-2]
                dyn_auths = getDynamicUserAuthenticators()
                isDynamic = False
                for dyn_auth in dyn_auths:
                    if username_from_form.startswith(dyn_auth + "|"):
                        isDynamic = (username_from_form, dyn_auth)
                        break
                if isDynamic:
                    log.info(
                        "%r is requesting logout of dynamic user %r (%r)" %
                        (user_from_request.getName(), isDynamic[0],
                         isDynamic[1]))
                    deleteUser(isDynamic[0], isDynamic[1])
                else:
                    usertype = req.params.get("usertype", "intern")
                    usernode = getUser(key[7:-2])
                    if not usertype.strip():
                        usertype = usernode.getUserType()
                        if usertype == 'users':
                            # function deleteUser expects usertype='intern'
                            # for children if root->users, but getUserType()
                            # returns 'users' for those
                            usertype = 'intern'
                    log.info("%r is requesting deletion of user %r (%r, %r)" %
                             (user_from_request.getName(), usernode.name,
                              usernode.id, usertype))
                    deleteUser(usernode, usertype=usertype)
                    del_index = users_cache.index(usernode)

                    del users_cache[del_index]

                searchterm_was = req.params.get("searchterm_was", "")
                if searchterm_was:
                    req.params['action'] = 'search'
                    req.params['searchterm'] = searchterm_was
                    req.params['use_macro'] = 'view'
                    req.params['execute_search'] = searchterm_was

                break

            elif key.startswith("tointern_"):
                moveUserToIntern(key[9:-2])
                break

            elif key.startswith("reset_"):
                # reset password
                if req.params["change_passwd"] != "":
                    getUser(key[6:-2]).resetPassword(
                        req.params["change_passwd"])
                else:
                    getUser(key[6:-2]).resetPassword(
                        config.settings["user.passwd"])
                break

        if "form_op" in req.params.keys():
            _option = ""
            for key in req.params.keys():
                if key.startswith("option_"):
                    _option += key[7]

            if req.params.get("form_op") == "save_new":
                # save user values
                if req.params.get("username", "") == "" or req.params.get(
                        "usergroups", "") == "" or req.params.get("email",
                                                                  "") == "":
                    return editUser_mask(req, "",
                                         1)  # no username or group selected
                elif existUser(req.params.get("username")):
                    return editUser_mask(req, "", 2)  # user still existing
                else:
                    create_user(
                        req.params.get("username"),
                        req.params.get("email"),
                        req.params.get("usergroups").replace(";", ","),
                        pwd=req.params.get("password", ""),
                        lastname=req.params.get("lastname", ""),
                        firstname=req.params.get("firstname"),
                        telephone=req.params.get("telephone"),
                        comment=req.params.get("comment"),
                        option=_option,
                        organisation=req.params.get("organisation", ""),
                        identificator=req.params.get("identificator", ""),
                        type=req.params.get("usertype", "intern"))

            elif req.params["form_op"] == "save_edit":
                # update user
                if req.params.get("email", "") == "" or req.params.get(
                        "username", "") == "" or req.params.get(
                            "usergroups", "") == "":
                    return editUser_mask(
                        req, req.params.get("id"),
                        1)  # no username, email or group selected
                else:
                    update_user(
                        req.params.get("id", 0),
                        req.params.get("username", ""),
                        req.params.get("email", ""),
                        req.params.get("usergroups", "").replace(";", ","),
                        lastname=req.params.get("lastname"),
                        firstname=req.params.get("firstname"),
                        telephone=req.params.get("telephone"),
                        comment=req.params.get("comment"),
                        option=_option,
                        organisation=req.params.get("organisation", ""),
                        identificator=req.params.get("identificator", ""),
                        type=req.params.get("usertype", "intern"))

            flush_users_cache()
        return view(req)
    except:
        print "Warning: couldn't load module for type", type
        print sys.exc_info()[0], sys.exc_info()[1]
        traceback.print_tb(sys.exc_info()[2])