예제 #1
0
def test_filter_subscriber_list(request):
    user = User(request)
    event = events.Event(request)

    print "User is subscribed to this event on jabber."
    print "This means, that he should stay on the list."
    user.jid = "*****@*****.**"
    user.jabber_subscribed_events = [events.Event.__name__]
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, True)
    assert subscribers["en"]

    print "User is not subscribed to this event on jabber."
    print "The list should be empty."
    user.jid = "*****@*****.**"
    user.jabber_subscribed_events = []
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, True)
    assert not subscribers["en"]

    print "User is subscribed to this event on email."
    print "This means, that he should stay on the list."
    user.email = "*****@*****.**"
    user.email_subscribed_events = [events.Event.__name__]
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, False)
    assert subscribers["en"]

    print "User is not subscribed to this event on email."
    print "The list should be empty."
    user.email = "*****@*****.**"
    user.email_subscribed_events = []
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, False)
    assert not subscribers["en"]
예제 #2
0
def test_filter_subscriber_list(request):
    user = User(request)
    event = events.Event(request)

    print "User is subscribed to this event on jabber."
    print "This means, that he should stay on the list."
    user.jid = "*****@*****.**"
    user.jabber_subscribed_events = [events.Event.__name__]
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, True)
    assert subscribers["en"]

    print "User is not subscribed to this event on jabber."
    print "The list should be empty."
    user.jid = "*****@*****.**"
    user.jabber_subscribed_events = []
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, True)
    assert not subscribers["en"]

    print "User is subscribed to this event on email."
    print "This means, that he should stay on the list."
    user.email = "*****@*****.**"
    user.email_subscribed_events = [events.Event.__name__]
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, False)
    assert subscribers["en"]

    print "User is not subscribed to this event on email."
    print "The list should be empty."
    user.email = "*****@*****.**"
    user.email_subscribed_events = []
    subscribers = {"en": [user]}
    notification.filter_subscriber_list(event, subscribers, False)
    assert not subscribers["en"]
예제 #3
0
    def request(self, request, user_obj, **kw):
        """ authenticate via external cookie """
        import Cookie
        user = None
        try_next = True  # if True, moin tries the next auth method
        cookiename = "whatever"  # +++ external cookie name you want to use

        try:
            cookie = Cookie.SimpleCookie(request.saved_cookie)
        except Cookie.CookieError:
            # ignore invalid cookies
            cookie = None
        if cookie and cookiename in cookie:
            import urllib
            cookievalue = cookie[cookiename].value
            # +++ now we decode and parse the cookie value - edit this to fit your needs.
            # the minimum we need to get is auth_username. aliasname and email is optional.
            cookievalue = urllib.unquote(
                cookievalue)  # cookie value is urlencoded, decode it
            cookievalue = cookievalue.decode(
                'iso-8859-1')  # decode cookie charset to unicode
            cookievalue = cookievalue.split(
                '#')  # cookie has format loginname#firstname#lastname#email

            auth_username = cookievalue[
                0]  # having this cookie means user auth has already been done!
            aliasname = email = ''
            try:
                aliasname = "%s %s" % (
                    cookievalue[1], cookievalue[2]
                )  # aliasname is for cosmetical stuff only
                email = cookievalue[3]
            except IndexError:  # +++ this is for debugging it, in case it does not work
                if 0:
                    f = open("cookie.log", "w")
                    f.write(repr(cookie))
                    f.write(repr(cookievalue))
                    f.close()
                pass

            from MoinMoin.user import User
            # giving auth_username to User constructor means that authentication has already been done.
            user = User(request,
                        name=auth_username,
                        auth_username=auth_username,
                        auth_method=self.name)

            changed = False
            if aliasname != user.aliasname:  # was the aliasname externally updated?
                user.aliasname = aliasname
                changed = True  # yes -> update user profile
            if email != user.email:  # was the email addr externally updated?
                user.email = email
                changed = True  # yes -> update user profile

            if user:
                user.create_or_update(changed)
            if user and user.valid:  # did we succeed making up a valid user?
                try_next = False  # stop processing auth method list
        return user, try_next
예제 #4
0
    def request(self, request, user_obj, **kw):
        """ authenticate via external cookie """
        import Cookie

        user = None
        try_next = True  # if True, moin tries the next auth method
        cookiename = "whatever"  # +++ external cookie name you want to use

        try:
            cookie = Cookie.SimpleCookie(request.saved_cookie)
        except Cookie.CookieError:
            # ignore invalid cookies
            cookie = None
        if cookie and cookiename in cookie:
            import urllib

            cookievalue = cookie[cookiename].value
            # +++ now we decode and parse the cookie value - edit this to fit your needs.
            # the minimum we need to get is auth_username. aliasname and email is optional.
            cookievalue = urllib.unquote(cookievalue)  # cookie value is urlencoded, decode it
            cookievalue = cookievalue.decode("iso-8859-1")  # decode cookie charset to unicode
            cookievalue = cookievalue.split("#")  # cookie has format loginname#firstname#lastname#email

            auth_username = cookievalue[0]  # having this cookie means user auth has already been done!
            aliasname = email = ""
            try:
                aliasname = "%s %s" % (cookievalue[1], cookievalue[2])  # aliasname is for cosmetical stuff only
                email = cookievalue[3]
            except IndexError:  # +++ this is for debugging it, in case it does not work
                if 0:
                    f = open("cookie.log", "w")
                    f.write(repr(cookie))
                    f.write(repr(cookievalue))
                    f.close()
                pass

            from MoinMoin.user import User

            # giving auth_username to User constructor means that authentication has already been done.
            user = User(request, name=auth_username, auth_username=auth_username, auth_method=self.name)

            changed = False
            if aliasname != user.aliasname:  # was the aliasname externally updated?
                user.aliasname = aliasname
                changed = True  # yes -> update user profile
            if email != user.email:  # was the email addr externally updated?
                user.email = email
                changed = True  # yes -> update user profile

            if user:
                user.create_or_update(changed)
            if user and user.valid:  # did we succeed making up a valid user?
                try_next = False  # stop processing auth method list
        return user, try_next
예제 #5
0
파일: auth.py 프로젝트: imosts/flume
 def __call__(self, request, **kw):
     def handle_egroupware(session):
         """ Extracts name, fullname and email from the session. """
         username = session['egw_session']['session_lid'].split("@", 1)[0]
         known_accounts = session['egw_info_cache']['accounts']['cache']['account_data']
         
         # if the next line breaks, then the cache was not filled with the current
         # user information
         user_info = [value for key, value in known_accounts.items()
                      if value['account_lid'] == username][0]
         name = user_info.get('fullname', '')
         email = user_info.get('email', '')
         
         dec = lambda x: x and x.decode("iso-8859-1")
         
         return dec(username), dec(email), dec(name)
     
     import Cookie, urllib
     from MoinMoin.user import User
     from MoinMoin.util import sessionParser
 
     user_obj = kw.get('user_obj')
     try:
         cookie = Cookie.SimpleCookie(request.saved_cookie)
     except Cookie.CookieError: # ignore invalid cookies
         cookie = None
     if cookie:
         for cookiename in cookie.keys():
             cookievalue = urllib.unquote(cookie[cookiename].value).decode('iso-8859-1')
             session = sessionParser.loadSession(cookievalue, path=self.s_path, prefix=self.s_prefix)
             if session:
                 if "egw" in self.apps and session.get('egw_session', None):
                     username, email, name = handle_egroupware(session)
                     break
         else:
             return user_obj, True
         
         user = User(request, name=username, auth_username=username)
         
         changed = False
         if name != user.aliasname:
             user.aliasname = name
             changed = True
         if email != user.email:
             user.email = email
             changed = True
         
         if user:
             user.create_or_update(changed)
         if user and user.valid:
             return user, True # True to get other methods called, too
     return user_obj, True # continue with next method in auth list