Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Get Logged In Users values from sql table

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get Logged In Users values from sql table

    i am trying to initialise vaiables for use thoughout the app once a user has logged in. i have this but it's not working and i dont really know where im going wrong.

    Code:
    '-- Get the current User which will return the email address.
    dim cu as c = Context.Security.CurrentUser 'a5ws_getcurrentuser()  
    
    'Open SQL DB and retrieve values for the logged in user
    dim cn as sql::connection
    connection = "::name::MM3"
    
    if cn.open(connection) then
    	dim args as sql::Arguments
    	dim rs as sql::ResultSet
    	dim session.contactname as c
    	dim session.employeecompany as c
    	dim session.contactfileloc as c
    	dim session.contactemail as C
    	dim session.contactid as c
    	dim session.employeerole as c
    	dim session.contacttype as C
    
    	args.add("currentuser",cu)
    	
    	dim sqluser as c = "SELECT email, firstname, surname, file_location, contactid, employeerole, contacttype, organisation FROM contacts WHERE email = :currentuser "
    	
    	if cn.Execute(sqluser,args) then
    		rs = cn.ResultSet
    		if rs.DataIsNull(1) = .f. then '--Test if the rs has any data
    			session.contactname = alltrim("firstname") + " " + alltrim("surname")
    			session.employeecompany = "organisation"
    			session.contactfileloc = "file_location"
    			session.contactemail = "Email"
    			session.contactid  = convert_type(rs.data("contactid"),"C")
    			session.employeerole = "Employeerole"
    			session.contacttype = "ContactType"
    		else
    			'-- for debugging show a message here if the rs did not have any data
    		end if
    	end if
    end if

  • #2
    Re: Get Logged In Users values from sql table

    What happens when you debug it?

    Comment


    • #3
      Re: Get Logged In Users values from sql table

      Except for contactid, you're not going after any data from the recordset.

      alltrim("firstname") is simply trimming the static value "firstname"... it has nothing to do with returned data.
      You're assigning session.employeecompany the static value "organisation".

      At the very least I believe you want rs.data("firstname"), rs.data("organisation"), etc.

      I'd also have to ask what you're doing with all the session variables... what's the purpose? Is this a UX or a Grid?
      Last edited by Davidk; 03-01-2017, 05:20 PM.

      Comment


      • #4
        Re: Get Logged In Users values from sql table

        Originally posted by Davidk View Post
        Except for contactid, you're not going after any data from the recordset.

        alltrim("firstname") is simply trimming the static value "firstname"... it has nothing to do with returned data.
        You're assign session.employeecompany the static value "organisation".

        At the very least I believe you want rs.data("firstname"), rs.data("organisation"), etc.
        this makes sense, thank you

        I'd also have to ask what you're doing with all the session variables... what's the purpose? Is this a UX or a Grid?
        this is an an .a5w page which the login in component directs the user to first. they are used throughout the application, i probably could call some of them as they are needed but some are used all the time.

        Comment


        • #5
          Re: Get Logged In Users values from sql table

          Cool... just curious... thanks.

          Comment


          • #6
            Re: Get Logged In Users values from sql table

            I use this to debug and for production:

            if substr(request.script_name,2,11) = "LivePreview" .or. substr(request.script_name,1,5) = "a5res"
            vUserName = "[email protected]"
            else
            vUserName = Context.Security.CurrentUser
            end if

            Comment


            • #7
              Re: Get Logged In Users values from sql table

              Thanks Lee,

              That works very well.

              Pieter

              Comment


              • #8
                Re: Get Logged In Users values from sql table

                Richard, you have this on an a5w page? Do you have the <%a5 and %> tags around the whole block?

                Here's what I have, a bit old so I should update the context.security object methods, nevertheless it works fine. I also believe it's not necessary to dim session variables anymore, perhaps someone can confirm that.

                Code:
                <%a5
                
                'dim variables
                dim session.current_user_fname as c
                dim session.current_user_lname as c
                dim session.current_user_email as c
                dim session.current_user_department as c
                dim session.current_user_position as c
                dim session.UserID as c
                dim session.UserGroup as c
                dim session.ipaddress as c
                
                'get logged-in user's ip address
                session.ipaddress = request.remote_addr 
                
                'get current user firstname, lastname & email
                cn = "::name::Engineering"
                table = "Employees"
                filter = "username = '" + a5ws_getCurrentUser() + "'"
                result_fname = "firstname"
                result_lname = "lastname"
                result_email = "email"
                result_department = "department"
                result_position = "position"
                
                session.current_user_fname = sql_lookup(cn,table,filter,result_fname)
                session.current_user_lname = sql_lookup(cn,table,filter,result_lname)
                session.current_user_email = sql_lookup(cn,table,filter,result_email)
                session.current_user_department = sql_lookup(cn,table,filter,result_department)
                session.current_user_position = sql_lookup(cn,table,filter,result_position)
                session.UserID = a5ws_getcurrentuser()
                session.UserGroup = a5ws_get_user_assignments(session.UserID)
                
                'send the logged-in user to the index page
                response.redirect("home.a5w")
                %>
                Alpha Anywhere v12.4.6.4.0 Build 8000-5628 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                Comment


                • #9
                  Re: Get Logged In Users values from sql table

                  stephen
                  the code is perfect but i have a question, you have
                  Code:
                  session.current_user_fname = sql_lookup(cn,table,filter,result_fname)
                  session.current_user_lname = sql_lookup(cn,table,filter,result_lname)
                  session.current_user_email = sql_lookup(cn,table,filter,result_email)
                  session.current_user_department = sql_lookup(cn,table,filter,result_department)
                  session.current_user_position = sql_lookup(cn,table,filter,result_position)
                  this means you are making a call (or at least alpha is) to the back end each time you need one variable. ( alpha will open the connection, table, get the variable close the table and connection each time).
                  is that better than making one call to the back end ( you have connection string declared already) then assign the values from the result set?
                  (not that computers or server will complain).
                  thanks for reading

                  gandhi

                  version 11 3381 - 4096
                  mysql backend
                  http://www.alphawebprogramming.blogspot.com
                  [email protected]
                  Skype:[email protected]
                  1 914 924 5171

                  Comment


                  • #10
                    Re: Get Logged In Users values from sql table

                    thanks Stephen, i did have the tags. Your method has worked perfectly for me.

                    Originally posted by iRadiate View Post
                    Richard, you have this on an a5w page? Do you have the <%a5 and %> tags around the whole block?

                    Here's what I have, a bit old so I should update the context.security object methods, nevertheless it works fine. I also believe it's not necessary to dim session variables anymore, perhaps someone can confirm that.

                    Code:
                    <%a5
                    
                    'dim variables
                    dim session.current_user_fname as c
                    dim session.current_user_lname as c
                    dim session.current_user_email as c
                    dim session.current_user_department as c
                    dim session.current_user_position as c
                    dim session.UserID as c
                    dim session.UserGroup as c
                    dim session.ipaddress as c
                    
                    'get logged-in user's ip address
                    session.ipaddress = request.remote_addr 
                    
                    'get current user firstname, lastname & email
                    cn = "::name::Engineering"
                    table = "Employees"
                    filter = "username = '" + a5ws_getCurrentUser() + "'"
                    result_fname = "firstname"
                    result_lname = "lastname"
                    result_email = "email"
                    result_department = "department"
                    result_position = "position"
                    
                    session.current_user_fname = sql_lookup(cn,table,filter,result_fname)
                    session.current_user_lname = sql_lookup(cn,table,filter,result_lname)
                    session.current_user_email = sql_lookup(cn,table,filter,result_email)
                    session.current_user_department = sql_lookup(cn,table,filter,result_department)
                    session.current_user_position = sql_lookup(cn,table,filter,result_position)
                    session.UserID = a5ws_getcurrentuser()
                    session.UserGroup = a5ws_get_user_assignments(session.UserID)
                    
                    'send the logged-in user to the index page
                    response.redirect("home.a5w")
                    %>

                    Comment


                    • #11
                      Re: Get Logged In Users values from sql table

                      If you really want to use sql_lookup, then pass in an open connection as suggested in the doc here...

                      http://documentation.alphasoftware.c...20Function.xml

                      It will be much faster since the connection is already established for each call.

                      However, your original code concept, Richard, is better.

                      Comment


                      • #12
                        Re: Get Logged In Users values from sql table

                        I will come back to this later, i just couldn't get my first attempt to work and it was stopping me from doing further work hopefully as i develop my application ill work it out.

                        Originally posted by Davidk View Post
                        If you really want to use sql_lookup, then pass in an open connection as suggested in the doc here...

                        http://documentation.alphasoftware.c...20Function.xml

                        It will be much faster since the connection is already established for each call.

                        However, your original code concept, Richard, is better.

                        Comment


                        • #13
                          Re: Get Logged In Users values from sql table

                          I do this simply as an intermediary step between the login page and the application.
                          It is transparent to the user and sets the session variables I use in various places in the application without having to make further sql calls to open a connection later on. It works for me.
                          Alpha Anywhere v12.4.6.4.0 Build 8000-5628 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                          Comment


                          • #14
                            Re: Get Logged In Users values from sql table

                            I've had many problems with this technique. It seems like session variables will expire at random and odd times as the users are using the program. Has any one else had this experience?

                            Comment


                            • #15
                              Re: Get Logged In Users values from sql table

                              Originally posted by lvasic View Post
                              I've had many problems with this technique. It seems like session variables will expire at random and odd times as the users are using the program. Has any one else had this experience?
                              Lee, I've been doing it this way for years (it's why the code may be a little outdated) and not once have I had a problem with expiring session variables. Maybe it's the way I use them, basically to display the logged in users name and group on the main page, to send CC email notices the logged-in user, etc.
                              I also have my server set to end all sessions after 2 hours of inactivity unless the user renews the session or begins working again.
                              Last edited by iRadiate; 03-04-2017, 06:14 PM.
                              Alpha Anywhere v12.4.6.4.0 Build 8000-5628 IIS v10.0 on Windows Server 2019 Std in Hyper-V

                              Comment

                              Working...
                              X