예제 #1
0
    def _loginUser(self, login):
        """Handle login for the given user
        """
        mtool = getToolByName(self, 'portal_membership')
        user = mtool.getUser(login)
        member = mtool.getMemberById(login)

        # Set login times
        first_login = False
        default = DateTime('2000/01/01')
        login_time = member.getProperty('login_time', default)
        if login_time == default:
            first_login = True
            login_time = DateTime()
        member.setMemberProperties(
            dict(login_time=mtool.ZopeTime(), last_login_time=login_time))

        # Fire login event
        if first_login:
            event.notify(UserInitialLoginInEvent(user))
        else:
            event.notify(UserLoggedInEvent(user))

        # Expire the clipboard
        if self.REQUEST.get('__cp', None) is not None:
            self.REQUEST.RESPONSE.expireCookie('__cp', path='/')

        # Create member area
        mtool.createMemberArea(member_id=login)
예제 #2
0
def loginUser(self, REQUEST=None):
    """ Handle a login for the current user.

        This method takes care of all the standard work that needs to be
        done when a user logs in:
        - clear the copy/cut/paste clipboard
        - PAS credentials update
        - sending a logged-in event
        - storing the login time
        - create the member area if it does not exist
        """
    user = getSecurityManager().getUser()
    if user is None:
        return

    res = self.setLoginTimes()
    if res:
        event.notify(UserInitialLoginInEvent(user))
    else:
        event.notify(UserLoggedInEvent(user))

    if REQUEST is None:
        REQUEST = getattr(self, 'REQUEST', None)
    if REQUEST is None:
        return

    # Expire the clipboard
    if REQUEST.get('__cp', None) is not None:
        REQUEST.RESPONSE.expireCookie('__cp', path='/')

#         import pdb
#         pdb.set_trace()
    self.createMemberArea()
    try:
        pas = getToolByName(self, 'acl_users')
        pas.credentials_cookie_auth.login()
        if res:
            event.notify(MemberAreaCreatedEvent(user))
        #set the cookie __ac so that client can remember it
        myresponse = REQUEST.RESPONSE
        if getattr(REQUEST, "ac_persistent", None):
            cookiename = '__ac'
            cookie = myresponse.cookies.get(cookiename)
            if cookie:
                cookievalue = cookie.pop('value')
                new_date = DateTime() + 7
                cookie['expires'] = new_date.strftime(
                    "%a, %d-%h-%y %H:%m:%S GMT+8")
                myresponse.setCookie(cookiename, cookievalue, **cookie)
    except AttributeError:
        # The cookie plugin may not be present
        pass
    try:
        pass
#             event.notify(AddloginlogsEvent(user))
    except AttributeError:
        pass
예제 #3
0
    def login_user(self, userid, properties):
        uf = getToolByName(self.context, 'acl_users')
        mtool = getToolByName(self, 'portal_membership')
        member = mtool.getMemberById(userid)

        settings = self.sp_settings()
        if member is None and settings.autoprovision_users:
            plugins = uf._getOb('plugins')
            enumerators = plugins.listPlugins(IUserEnumerationPlugin)
            plugin = None
            for id_, enumerator in enumerators:
                if enumerator.meta_type == "collective.saml2auth plugin":
                    plugin = enumerator
                    break
            if plugin is None:
                logger.warning(
                    'Missing PAS plugin. Cannot autoprovision user %s.' %
                    userid)
                return

            plugin.addUser(userid)
            member = mtool.getMemberById(userid)

        # Setup session
        uf.updateCredentials(self.request, self.request.response, userid, '')

        # Update login times and other member properties
        first_login = False
        default = DateTime('2000/01/01')
        login_time = member.getProperty('login_time', default)
        if login_time == default:
            first_login = True
            login_time = DateTime()
        member.setMemberProperties(
            dict(login_time=mtool.ZopeTime(),
                 last_login_time=login_time,
                 **properties))

        # Fire login event
        user = member.getUser()
        if first_login:
            event.notify(UserInitialLoginInEvent(user))
        else:
            event.notify(UserLoggedInEvent(user))

        # Expire the clipboard
        if self.request.get('__cp', None) is not None:
            self.request.response.expireCookie('__cp', path='/')

        # Create member area
        mtool.createMemberArea(member_id=userid)
    def __call__(self):
        oauthWorkFlow = OauthWorkFlow(oauthServerName="facebook")
        client_id, client_secret, scope, redirect_uri = oauthWorkFlow.getRegistryValue(
        )
        code = getattr(self.request, 'code', None)
        facebook = OAuth2Session(client_id,
                                 redirect_uri=redirect_uri,
                                 scope=scope)
        facebook = facebook_compliance_fix(facebook)
        if code == None:
            if hasattr(self.request, 'error'):
                self.request.response.redirect("/")
                return
            authorization_url, state = facebook.authorization_url(
                self.authorization_base_url)
            self.request.response.redirect(authorization_url)
            return
        user = oauthWorkFlow.getUserInfo(facebook, self.token_url,
                                         client_secret, code,
                                         self.getUrl).json()

        # check has id, if True, is a relogin user, if False, is a new user

        userid = safe_unicode("fb%s") % user["id"]

        #########
        userObject = api.user.get(userid=userid)
        if api.user.get(userid=userid) is not None:
            self.context.acl_users.session._setupSession(
                userid.encode("utf-8"), self.context.REQUEST.RESPONSE)
            self.request.RESPONSE.redirect("/")
            #########
            notify(UserLoggedInEvent(userObject))
            return
        userInfo = dict(
            fullname=safe_unicode(user.get("name", "")),
            description=safe_unicode(user.get("about", "")),
            location=safe_unicode(user.get("locale", "")),
            fbGender=safe_unicode(user.get("gender", "")),
            home_page=safe_unicode(user.get("link", "")),
        )
        userObject = oauthWorkFlow.createUser(
            userid, safe_unicode((user.get("email", ""))), userInfo)
        #        self.context.acl_users.session._setupSession(userid.encode("utf-8"), self.context.REQUEST.RESPONSE)
        #        self.request.RESPONSE.redirect("/")
        notify(UserInitialLoginInEvent(userObject))
        return
예제 #5
0
    def _auto_login(self, userid, password):
        aclu = getToolByName(self.context, 'acl_users')
        for name, plugin in aclu.plugins.listPlugins(ICredentialsUpdatePlugin):
            plugin.updateCredentials(self.request, self.request.response,
                                     userid, password)
        user = getSecurityManager().getUser()
        login_time = user.getProperty('login_time', None)
        if login_time is None:
            notify(UserInitialLoginInEvent(user))
        else:
            notify(UserLoggedInEvent(user))

        IStatusMessage(self.request).addStatusMessage(
            _(
                'password_reset_successful',
                default='Password reset successful, '
                'you are logged in now!',
            ),
            'info',
        )
        url = INavigationRoot(self.context).absolute_url()
        self.request.response.redirect(url)
        return
예제 #6
0
    def loginUser(self, REQUEST=None):
        """ Handle a login for the current user.

        This method takes care of all the standard work that needs to be
        done when a user logs in:
        - clear the copy/cut/paste clipboard
        - PAS credentials update
        - sending a logged-in event
        - storing the login time
        - create the member area if it does not exist
        """
        user = getSecurityManager().getUser()
        if user is None:
            return

        if self.setLoginTimes():
            event.notify(UserInitialLoginInEvent(user))
        else:
            event.notify(UserLoggedInEvent(user))

        if REQUEST is None:
            REQUEST = getattr(self, 'REQUEST', None)
        if REQUEST is None:
            return

        # Expire the clipboard
        if REQUEST.get('__cp', None) is not None:
            REQUEST.RESPONSE.expireCookie('__cp', path='/')

        self.createMemberArea()

        try:
            pas = getToolByName(self, 'acl_users')
            pas.credentials_cookie_auth.login()
        except AttributeError:
            # The cookie plugin may not be present
            pass
예제 #7
0
 def fire_login_events(self, first_login, user):
     if first_login:
         notify(UserInitialLoginInEvent(user))
     else:
         notify(UserLoggedInEvent(user))
예제 #8
0
def loginUser(self, REQUEST=None):
    """ Handle a login for the current user.

        This method takes care of all the standard work that needs to be
        done when a user logs in:
        - clear the copy/cut/paste clipboard
        - PAS credentials update
        - sending a logged-in event
        - storing the login time
        - create the member area if it does not exist
        """
    user = getSecurityManager().getUser()
    if user is None:
        return
    try:
        home = self.getHomeFolder(user.getId())
    except:
        home = None
    res = self.setLoginTimes()
    res = res and not home

    loginEvent = NormalUserloginEvent(
        userid=getfullname_orid(user),
        datetime=datetime.datetime.now().strftime(fmt),
        ip=get_ip(),
        type=0,
        description="",
        result=1)
    if loginEvent.available():
        if loginEvent.is_normal_user():
            event.notify(loginEvent)
        else:
            loginEvent = AddloginEvent(
                adminid=getfullname_orid(user),
                userid=" ",
                datetime=datetime.datetime.now().strftime(fmt),
                ip=get_ip(),
                type=0,
                description="",
                result=1)
            event.notify(loginEvent)
    if res:
        event.notify(UserInitialLoginInEvent(user))
        self.createMemberArea()
        event.notify(MemberAreaCreatedEvent(user))
    else:
        event.notify(UserLoggedInEvent(user))

    if REQUEST is None:
        REQUEST = getattr(self, 'REQUEST', None)
    if REQUEST is None:
        return

    # Expire the clipboard
    if REQUEST.get('__cp', None) is not None:
        REQUEST.RESPONSE.expireCookie('__cp', path='/')

    try:
        pas = getToolByName(self, 'acl_users')
        pas.credentials_cookie_auth.login()
    except AttributeError:
        # The cookie plugin may not be present
        pass
예제 #9
0
 def fire_login_event(self, member):
     user = member.getUser()
     if self.first_login:
         event.notify(UserInitialLoginInEvent(user))
     else:
         event.notify(UserLoggedInEvent(user))