Alpha Video Training
Results 1 to 10 of 10

Thread: Capture user info after login and store in session variable - web app

  1. #1
    Member
    Real Name
    Rob McMillan
    Join Date
    May 2012
    Location
    Orlando, FL
    Posts
    16

    Default Capture user info after login and store in session variable - web app

    Hello all.

    Made it 3 yrs without having to make a post. But now I am running out of time and patience on this problem. Here we go...

    Trying to capture information for the logged in user and store those values in session variables. I have set up the post login “process” page and set up the page redirect in security. The code I am currently using on the process page is derived from a response posted by Kieth Hubert on 12-24-2011. Here's the sheet music:

    <%a5
    dim tbl as p
    session.CurrentUserName = "wilma" 'a5ws_getcurrentuser()
    'Hard coded user name for testing purposes
    'Begin test code
    'test code modified from the message board > "How to reteive data after login for that particular user id?"

    tbl=table.open("org_empl")

    query.filter=("user_name=var->Sesssion.CurrentUserName")
    tbl.query_create()

    session.org_id=alltrim(tbl.org_id)
    session.first_name=alltrim(tbl.org_empl_first)
    session.last_name=alltrim(tbl.org_empl_last)

    tbl.query_detach()
    tbl.close()
    'End test code

    response.redirect("HomePage.a5w")
    %>

    When I run this it throws an error message that says:
    “Script: TEMPLATE line:9
    tbl.query_create()
    Cannot use function in this context”

    I have tried many other things trying to solve my issue with no success. Ideas??

    Thanks in advance!
    Rob

  2. #2
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON, Canada
    Posts
    1,665

    Default Re: Capture user info after login and store in session variable - web app

    Rob,

    Wow 3 years without a question ... you are way more patient than me

    I'm not an expert by any means, but I'm doing the same thing as you are trying to accomplish, slightly differently.
    I don't see where you are declaring the session variable before using it, ie) dim session.CurrentUserName as c

    Have a look at my code, perhaps it might turn on a light bulb for you. Obviously your connection string and table names will be different.
    Code:
    <%a5
    'dim variables
    dim session.current_user_fname as c
    dim session.current_user_lname as c
    
    'get current user firstname & lastname
    cn = "::name::Engineering"
    table = "Employees"
    filter = "username = '" + a5ws_getCurrentUser() + "'"
    result_fname = "firstname"
    result_lname = "lastname"
    
    session.current_user_fname = sql_lookup(cn,table,filter,result_fname)
    session.current_user_lname = sql_lookup(cn,table,filter,result_lname)
    
    'send the logged-in user to the index page
    response.redirect("home.a5w")
    
    %>
    Stephen

  3. #3
    Member
    Real Name
    Rob McMillan
    Join Date
    May 2012
    Location
    Orlando, FL
    Posts
    16

    Default Re: Capture user info after login and store in session variable - web app

    Stephen,

    Thanks for your response. Wish it had been 3 yrs without a question! Had plenty, just got the answers the hard way. Figured it may help the learning process. Anyway...

    Still unable to find my problem since I am using DBF and you are using SQL. There are syntax differences that I don't know since I have not worked with SQL yet. I am quite sure this is a syntax issue. Something simple that I have overlooked in setting up my query. Looks like SQL handles queries in a different way. Not sure why it is telling me "Cannot use function in this context" on the "tbl.query_create()."

    I have also tried:
    dim qry as p 'and then create the query with >
    qry=tbl.query_create()

    Still nothing! BTW...I have now dimmed all my variables even though I wasn't using "option strict" since it is better form to do so (I believe).

    Rob

  4. #4
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,620

    Default Re: Capture user info after login and store in session variable - web app

    It's looking for your table in your webroot, where it probably isn't and shouldn't be. So, the server needs to know where it is:

    tbl=table.open("[pathalias.adb_path]\org_empl")

    This assumes you've correctly set that alias in your profile settings.
    -Steve


  5. #5
    Member
    Real Name
    Rob McMillan
    Join Date
    May 2012
    Location
    Orlando, FL
    Posts
    16

    Default Re: Capture user info after login and store in session variable - web app

    Just to make sure that the path alias has been setup correctly, I made a completely new profile. Also changed the code on the process page to match:

    tbl=table.open("[pathalias.adb_path]\org_empl")

    Everything works fine through the login process until page redirect. Then I am issued the following:

    500 Internal Server Error
    Script Error
    Error:Script:" /a5AmnetProfile/Process_page.a5w" line:22
    tbl.query_create()
    Cannot use function in this context

    Not that I really have a clue, but it seems as though it doesn't like the "tbl.query_create()." Maybe it is a problem locating the table but that should be resolved now.

  6. #6
    VAR Pat Bremkamp's Avatar
    Real Name
    Pat Bremkamp
    Join Date
    Apr 2000
    Location
    Oregon, USA
    Posts
    2,629

    Default Re: Capture user info after login and store in session variable - web app

    Rob, I haven't used dbf for a while, but here is some code out of the processing page of an old V9 app

    <%a5
    '==== get the permission ids if logged in
    dim session.__protected__Username as c = DEFAULT ""
    dim session.__protected__AgencyId as c = DEFAULT "No"
    dim session.__protected__RealtorId as c = DEFAULT "No"
    dim session.__protected__DborId as c = DEFAULT "No"
    if eval_valid("session.__protected__UserId")=.t.
    dim ptbl as p
    ptbl=table.open("[PathAlias.ADB_Path]\people.dbf")
    ptbl.index_primary_put("Pe_Id")
    vFound=ptbl.fetch_find(session.__protected__UserId)
    if vFound>0
    session.__protected__UserName=alltrim(ptbl.lastname)+" "+alltrim(ptbl.firstname)
    session.__protected__AgencyId=ptbl.Agency
    session.__protected__RealtorId=ptbl.Realtor
    session.__protected__DborId=ptbl.Dbor
    end if
    ptbl.close()
    end if
    %>

    Now days with V11, you should use variable_exists() instead of eval_valid(), you don't need the "__protected__", do not dim the session variables and set them all up to be character, so there are some changes to make here.
    Pat Bremkamp
    MindKicks Consulting

  7. #7
    Volunteer Moderator Steve Workings's Avatar
    Real Name
    Steve Workings
    Join Date
    Apr 2000
    Location
    The Dreaded Chair
    Posts
    5,620

    Default Re: Capture user info after login and store in session variable - web app

    I hadn't looked through your code completely, but this probably needs to be changed to:

    query.filter=("user_name='" + var->Sesssion.CurrentUserName + "'")

    Pay close attention to the single and double quotes I have in there -- put it in Notepad and make it real big if you have to.
    -Steve


  8. #8
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON, Canada
    Posts
    1,665

    Default Re: Capture user info after login and store in session variable - web app

    Also, is this a typo?

    query.filter=("user_name=var->Sesssion.CurrentUserName")

  9. #9
    Member
    Real Name
    Rob McMillan
    Join Date
    May 2012
    Location
    Orlando, FL
    Posts
    16

    Default Re: Capture user info after login and store in session variable - web app

    A big thanks to all for the input. I made the change suggested by brother Workings -- query.filter=("user_name='" + var->Sesssion.CurrentUserName + "'") And yes, Stephen, Sesssion was a typo in the code and has been corrected since I'm sure that wasn't helping things! All seems to be working as intended at this point.

    Thanks again for the help!
    Rob

  10. #10
    Member 2ninerniner2's Avatar
    Real Name
    Lyle
    Join Date
    Mar 2012
    Location
    Calgary, AB
    Posts
    236

    Default Re: Capture user info after login and store in session variable - web app

    Quote Originally Posted by iRadiate View Post

    Have a look at my code, perhaps it might turn on a light bulb for you. Obviously your connection string and table names will be different.
    Code:
    <%a5
    'dim variables
    dim session.current_user_fname as c
    dim session.current_user_lname as c
    
    'get current user firstname & lastname
    cn = "::name::Engineering"
    table = "Employees"
    filter = "username = '" + a5ws_getCurrentUser() + "'"
    result_fname = "firstname"
    result_lname = "lastname"
    
    session.current_user_fname = sql_lookup(cn,table,filter,result_fname)
    session.current_user_lname = sql_lookup(cn,table,filter,result_lname)
    
    'send the logged-in user to the index page
    response.redirect("home.a5w")
    
    %>
    Stephen
    Stephen - you the man! ... light bulb came on!

    This is EXACTLY what I was about to post here about but did a search of the forum first and voila!.

    I was going through Steve Workings video on how to do this and add it to my app. Worked just fine as in the video, but I wanted to also have the Last Name. Now I do :)

    Putting the following in the header area of the Tabbed UI and also in the text for the Logout button gives me precisely what I was looking to achieve:

    Header
    Code:
    <%A5
    
    if a5ws_getcurrentuser() <> ""
    	?"Logged in as: " + session.current_user_fname + " " + session.current_user_lname
    end if
    
    %>
    Button
    Code:
    Logout
    <br>
    <%A5
    
    if a5ws_getcurrentuser() <> ""
    	?session.current_user_fname + " " + session.current_user_lname
    end if
    
    %>

Similar Threads

  1. Get Session Variable Info To Reflects In A Heading Variable On A Report
    By Kobus Visser in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 11-12-2010, 10:52 AM
  2. How do I store a user and populate a date field upon an update/insert via my web app?
    By envisionsolutions in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 03-30-2010, 05:01 PM
  3. Capture IP Address of Web User
    By Charlain in forum Application Server Version 8
    Replies: 2
    Last Post: 05-18-2008, 11:42 PM
  4. digital photo store web app
    By Bob Arbuthnot in forum Application Server Version 8
    Replies: 0
    Last Post: 06-21-2007, 02:13 PM
  5. capture login user session
    By michaelt in forum Alpha Five Version 6
    Replies: 2
    Last Post: 03-10-2006, 09:21 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
  •