Index: WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py
===================================================================
--- WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py	(revision 998)
+++ WAeUP_SRP/trunk/skins/waeup_custom/logged_in.py	(revision 999)
@@ -45,70 +45,60 @@
 member = mtool.getAuthenticatedMember()
 
-if True or 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']
-            students = context.portal_url.getPortalObject().campus.students
-            student = getattr(students,str(member))
-            student_app = getattr(student,'application')
-            student_pume = getattr(student,'pume',None)
-            s_review_state = wftool.getInfoFor(student,'review_state',None)
-            a_review_state = wftool.getInfoFor(student_app,'review_state',None)
-            #if info['review_state'] in ("student_created","admitted") and\
-            #wftool.getInfoFor(info['app'],'review_state',None) == 'created' :
-            if s_review_state in ("student_created","admitted") and\
-            a_review_state == 'created' :
-                #student.content_status_modify(workflow_action="enter_clearance_pin")
-                #wftool.doActionFor(info['app'],'open')
-                wftool.doActionFor(student_app,'open')
-                #wftool.doActionFor(info['pume'],'close')
-                #if info['pume'] is not None:
-                if student_pume is not None:
-                  #wftool.doActionFor(info['pume'],'close')
-                  wftool.doActionFor(student_pume,'close')
+if not is_anon:
+    if "Student" in member.getRoles():
+        to_waeup_student_home = True
+        students = context.portal_url.getPortalObject().campus.students
+        student = getattr(students,str(member))
+        student_app = getattr(student,'application')
+        student_pume = getattr(student,'pume',None)
+        s_review_state = wftool.getInfoFor(student,'review_state',None)
+        a_review_state = wftool.getInfoFor(student_app,'review_state',None)
+        app_doc = student_app.getContent()
+        #from Products.zdb import set_trace
+        #set_trace()
+        if s_review_state in ("student_created","admitted") and\
+        a_review_state == 'created' :
+            wftool.doActionFor(student_app,'open')
+            if student_pume is not None:
+              wftool.doActionFor(student_pume,'close')
+            da = {}
+            pin = request.get('pin')
+            if not pin:
+                jamb_reg_no = app_doc.jamb_reg_no
+                for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
+                    res = context.portal_pins(student=reg_no)
+                    if len(res) > 0:
+                        break
+                if len(res) > 0:
+                    p = res[0].pin
+                    if len(p) > 10:
+                        pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
+                    else:
+                        pin = p
+            da['app_ac_pin'] = pin
+            da['app_ac_date'] = current
+            app_doc.edit(mapping = da)
+        elif s_review_state in ("admitted") and a_review_state == 'opened' and\
+        not app_doc.app_ac_pin:
+            jamb_reg_no = app_doc.jamb_reg_no
+            for reg_no in (jamb_reg_no,jamb_reg_no.lower(),jamb_reg_no.upper()):
+                res = context.portal_pins(student=reg_no)
+                if len(res) > 0:
+                    break
+            if len(res) > 0:
+                p = res[0].pin
+                if len(p) > 10:
+                    pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
+                else:
+                    pin = p
                 da = {}
-                pin = request.get('pin')
-                app_doc = student_app.getContent()
-                if not pin:
-                    app_doc = student_app.getContent()
-                    jamb_reg_no = app_doc.jamb_reg_no
-                    res = context.portal_pins(student=jamb_reg_no)
-                    if len(res) == 1:
-                        p = res[0].pin
-                        if len(p) > 10:
-                            pin = "%s-%s-%s" % (p[:3],p[3:4],p[4:])
-                        else:
-                            pin = p
-##                email = request.get('email')
-                #app_doc = info['app_doc']
                 da['app_ac_pin'] = pin
-##                da['app_email'] = email
-                da['app_ac_date'] = current
                 app_doc.edit(mapping = da)
-##                dc = {}
-##                dc['clr_ac_pin'] = pin
-##                dc['entry_date'] = current
-##                dc['session'] = "%s" % current.year()
-##                dc['lga'] = app_doc.jamb_lga
-##                info['clear_doc'].edit(mapping = dc)
-        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
+    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
 
 if to_waeup_student_home:
