## Script (Python) "logged_in" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=came_from=None ##title= ## """Prepare user login modified from cps_default/logged_in.py $Id: logged_in.py 34693 2006-03-23 17:44:22Z ogrisel $ """ import DateTime current = DateTime.DateTime() from urllib import unquote def checkRedirect(portal, mtool): to_member_home = False to_workspaces = False ## has_home = mtool.getHomeFolder() ## if has_home: ## to_member_home = True ## if not has_home and mtool.checkPermission('View', portal.workspaces): ## to_workspaces = True return to_member_home, to_workspaces request = context.REQUEST response = request.RESPONSE utool = context.portal_url mtool = context.portal_membership wftool = context.portal_workflow portal = utool.getPortalObject() portal_absolute_url = portal.absolute_url() redirect_url = came_from redirect_to_portal = False to_member_home = False to_workspaces = False to_waeup_student_home = False is_anon = mtool.isAnonymousUser() member = mtool.getAuthenticatedMember() if not redirect_url or redirect_url.endswith('/logged_out'): if not is_anon: if "Student" in member.getRoles(): to_waeup_student_home = True info = context.getStudentInfo() student = info['student'] if info['review_state'] == "created": student.content_status_modify(workflow_action="enter_application_pin") wftool.doActionFor(info['app'],'open',dest_container=info['app']) da = {} pin = request.get('pin') da['app_ac_pin'] = pin da['app_ac_date'] = current info['app_doc'].edit(mapping = da) elif "Manager" in member.getRoles(): pass else: to_member_home, to_workspaces = checkRedirect(portal, mtool) if (not to_member_home) and (not to_workspaces): redirect_to_portal = True else: redirect_url = unquote(redirect_url) # One can be redirected from an http page while the login is done from an # https page. This is a fix for #1205. # A better option here would be to replace the previous portal_absolute_url # prefix in the redirect_url by the current portal absolute URL. if not redirect_url.startswith(portal_absolute_url): if not is_anon: to_member_home, to_workspaces = checkRedirect(portal, mtool) if (not to_member_home) and (not to_workspaces): redirect_to_portal = True if to_waeup_student_home: member.setProperties(last_login_time=current,login_time=current) if info['review_state'] == "application_pin_entered": return response.redirect("%s/passport_entry_view" % student.absolute_url()) return response.redirect("%s" % student.absolute_url()) elif to_member_home: redirect_url = mtool.getHomeFolder().absolute_url() elif to_workspaces: redirect_url = portal.workspaces.absolute_url() elif redirect_to_portal: redirect_url = portal_absolute_url REQUEST = context.REQUEST RESPONSE = REQUEST.RESPONSE # Setup skins if (getattr(utool, 'updateSkinCookie', False) and utool.updateSkinCookie()): context.setupCurrentSkin() # Anonymous if is_anon: RESPONSE.expireCookie('__ac', path='/') return context.user_logged_in_failed() login_time = member.getProperty('login_time', '2000/01/01') first_time = (str(login_time) == '2000/01/01') if first_time and member.has_role('Member'): mtool.createMemberArea() now = context.ZopeTime() member.setProperties(last_login_time=now, login_time=now) if to_member_home or to_workspaces: redirect_url = '%s/?%s' % (redirect_url, 'portal_status_message=psm_logged_in') RESPONSE.redirect(redirect_url)