Alpha Video Training
Results 1 to 13 of 13

Thread: Login redirect by user type

  1. #1
    Member
    Real Name
    Rick Knight
    Join Date
    Aug 2006
    Location
    Cincinnati, Oh
    Posts
    27

    Default Login redirect by user type

    I have created the login dialog and successfully log in and have been redirected to the proper form(a5w) that I wanted it to go to. But now I need to direct the logged on user, to 1 of 2 forms based upon their user type (I = internal & C = customer). I cannot seem to get a grip on the DLG-Login Dialog Component sample.

    I think this is because of the conventions of xbasic and my unfamilarity with this code (many years of using vb and vba).

    Basicly the code has to validate user name, password and get the user type.
    The type then redirects the authenticated user to a specific target page.

    Any thoughts or suggestions?

  2. #2
    "Certified" Alphaholic Phil Rolf's Avatar
    Real Name
    Philip Rolf
    Join Date
    Apr 2000
    Location
    Kentucky
    Posts
    1,539

    Default Re: Login redirect by user type

    In the "after validate", simply place an if statement to direct to appropriate page. In fact I think there is an example of this displayed on the AV page.

  3. #3
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: Login redirect by user type

    Rick,

    You'd have aftervalidate statements similar to the following:

    level = lookup("<ADB_Path>\customers.dbf,"customerID="+quote(session.username),"Level")
    session.__protected__securitylevel = Level

    .....

    select
    case level = 1
    response.redirect("thispage.a5w")
    case level = 2
    response.redirect("thatpage.a5w")
    case else
    response.redirect("defaultpage.a5w")
    end select

    Elsewhere in your application you would refer to the level by the session.__protected__securitylevel variable. Those are special vars that the user can not maliciously set via a URL.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  4. #4
    Member
    Real Name
    Rick Knight
    Join Date
    Aug 2006
    Location
    Cincinnati, Oh
    Posts
    27

    Default Re: Login redirect by user type

    Thanks,
    I will try these suggestions today and advise results.

  5. #5
    "Certified" Alphaholic Keith Hubert's Avatar
    Real Name
    Keith Hubert
    Join Date
    Jul 2000
    Location
    London, UK
    Posts
    6,930

    Default Re: Login redirect by user type

    Rick

    First you have to Validate the session variable;

    session.type=lookup("[PathAlias.ADB_Path]\user_names","user_name=" + quote(user_name),"Type")

    Then as Steve says in the Aftervalidate you direct the user, in my case I used the following:

    if session.type="A"
    response.redirect("Admin.a5w")
    else if session.type="T"
    response.redirect("Teachers.a5w")
    else if session.type="S"
    response.redirect("Students.a5w")
    else if eval_valid("session.targetUrl") then
    if session.targetURL <> "" then
    Currentform.RedirectTarget = session.targetURL
    end if
    end if

    I hope this helps you as it did me.
    Regards
    Keith Hubert
    Alpha Guild Member
    London.
    KHDB Management Systems
    Skype = keith.hubert


    For your day-to-day Needs, you Need an Alpha Database!

  6. #6
    Member
    Real Name
    Rick Knight
    Join Date
    Aug 2006
    Location
    Cincinnati, Oh
    Posts
    27

    Default Re: Login redirect by user type

    Working on it right now. I'll give it a try
    Thanks for your input

  7. #7
    Member
    Real Name
    Rick Knight
    Join Date
    Aug 2006
    Location
    Cincinnati, Oh
    Posts
    27

    Default Re: Login redirect by user type

    Both redirect senerios worked. The problem I encountered was that
    although it appeared that the code was running, I never left the login page.

    It turns out that I was being redirected, by the page header statement in the requested pages (<A5 a5w_include("logintest.a5w") %> ) back to the login. Once these statements were removed everything went OK.

    Now I need ti fix the logintest statements.

  8. #8
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: Login redirect by user type

    Logintest.a5w checks to see if a variable is True that the person is properly logged in. A typical logintest.a5w looks like this:

    <%a5
    session.targetURL = request.request_uri
    if eval_valid("session.__protected__IsLoggedOn") = .f. then
    response.redirect("login.a5w")
    end
    end if
    %>

    Note that it is testing for session.__protected__IsLoggedOn. If you are not properly setting that value in the event code for your login dialog, then it will always be False, and the logintest code will pass the user back to the login page.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  9. #9
    Member
    Real Name
    Rick Knight
    Join Date
    Aug 2006
    Location
    Cincinnati, Oh
    Posts
    27

    Default Re: Login redirect by user type

    I do appreciate your feedback on this.
    I set up my before and after events based upon that data provided in the "How the login feature works".

    Here's my validate:
    'look for blank entry in user name or password & return error message
    if User_Name = "" .or. Password = "" then
    CurrentForm.Has_Error = .t.
    CurrentForm.Error_Message = "&nbsp; Error0: User name or password cannot be blank."
    else
    'Validate user name and password
    Dim Correct_Password as C
    Dim Correct_Type as C
    Correct_Password = Lookup("<ADB_Path>\User_Names", "User_Name=" + quote(User_Name),"Password")
    If Correct_Password <> Password then
    CurrentForm.Has_Error = .t.
    CurrentForm.Error_Message = "&nbsp; Error1: Invalid User name or Password."
    End If
    'Get session type
    Correct_Type = Lookup("<ADB_Path>\User_Names", "User_Name=" + quote(User_Name),"Type")
    end if

    And here's my after validate:

    If Eval_Valid("correct_type") then
    if correct_type = "C"
    currentform.redirecttarget = "Survey.a5w"
    else if correct_type = "I"
    currentform.redirecttarget = "Surveyview.a5w"
    end if
    end if

    My logintest is:

    <%A5
    If eval_Valid("session.FlagIsLoggedIn") = .f. then
    session.targetURL = request.request_uri
    response.redirect("login.a5w")
    end
    end if
    %>

    So I see from your reply that my logintest needs changing..but I'm uncertain about what is need in the validate event for the session._protect-IsLoggon

  10. #10
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: Login redirect by user type

    So that's it then. You are testing for "session.FlagIsLoggedIn" in logintest, but not setting it to TRUE anywhere in the login events. Just add the following as the first line in your aftervalidate for login.


    session.FlagIsLoggedIn = .t.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  11. #11
    Member
    Real Name
    Rick Knight
    Join Date
    Aug 2006
    Location
    Cincinnati, Oh
    Posts
    27

    Default Re: Login redirect by user type

    Thanks Steve, That did the trick.

  12. #12
    Guest
    Real Name
    John Mays
    Join Date
    Apr 2004
    Posts
    199

    Default Re: Login redirect by user type

    Hi All

    Once again probably a stupid question form me, But have used your above example to get my users to redirect to their own pages, I however wish to stop say a level one user jumping to a level 2 page if he finds out the url.

    What code can I use to acomplish this and where would I put it.

    Any help will be once again appreciated

    Thanks

    John

  13. #13
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,842

    Default Re: Login redirect by user type

    If you look at the logintest.a5w you see that it redirects users back to the login page if they are not logged in. This process looks to see if the value to session.Is_logged_In (or whatever your variable is named) is True. You can use the same logic to return a user to the login page if the open a page above their security level. For example, in a Level2 page, put a5w_include("mustblevel2.a5w") and have the mustblevel2.a5w page contain code similar to logintest.a5w that tests if their security level is level 2. If not, redirect them to the login page with a nasty note about trying to access pages without authorization.

    You can also log the attempt by sending yourself an email in the mustblevel2.a5w. If they are not level 2 or above, send them to the login page, and also send youself an email.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

Similar Threads

  1. Replies: 4
    Last Post: 06-01-2006, 02:03 PM
  2. USER or ADMIN LOGIN ?
    By den1s in forum Web Application Server v7
    Replies: 17
    Last Post: 03-03-2006, 04:12 PM
  3. Specify user login
    By Imran Ahmad in forum Alpha Five Version 5
    Replies: 2
    Last Post: 06-05-2003, 06:39 AM
  4. User Login
    By Sean Tucker in forum Alpha Five Version 4
    Replies: 5
    Last Post: 11-07-2001, 05:43 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •