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

Last Login Date/time

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

    Last Login Date/time

    I am trying to record into a database field the last time someone logged into my site. What code do you put in that recognizes the user that logged in and write the date/time to a SQL database field?

    #2
    Re: Last Login Date/time

    I have my login component forward to login.a5w, and that page has xbasic that logs to my log table. (So many logs!) Then login.a5w forwards back to index.a5w

    Comment


      #3
      Re: Last Login Date/time

      Will you post the code you are using? Are you writing to a text file or into a database?

      Comment


        #4
        Re: Last Login Date/time

        This isn't all of it, but it would be the part that matters

        Code:
        '0: Initialize connections
        dim globalcn as sql::connection
        flag = globalcn.open("::name::global")
        if flag == .f. then
        	write2log("Connect to DB",globalcn.CallResult.text)
        end if
        
        'Set up this session variable for style
        session.style = ""
        Session.loggedin = .t.
        
        '1: Log entry into system
        dim sql as c
        dim args as sql::arguments
        args.add("ulink", session.__protected__ulink)
        args.add("region_fk", session.regionnum)
        args.add("event", "Login")
        args.add("user_agent", request.UserAgent)
        args.add("ip", request.remote_addr)
        sql = "INSERT INTO gen_log (ulink, region_fk, event, user_agent, ip) VALUES (:ulink, :region_fk, :event, :user_agent, :ip)"
        flag = globalcn.Execute(sql, args)
        
        'x: Clean up
        globalcn.FreeResult()
        globalcn.Close()
        delete globalcn
        
        'Fin: Redirect to index page after everything is set
        Response.Redirect("index.a5w")
        EDIT: I actually use a custom function write2log() instead of this, but this is what I used to do.
        Last edited by Sparticuz; 06-08-2012, 01:37 PM.

        Comment


          #5
          Re: Last Login Date/time

          I only need to record last login date and time. In your code where are you doing this? Is it ("event", "login") and ("user_agent", request.useragent)? So the first one is recording the login event and the useragent recording the date into sql?

          Comment


            #6
            Re: Last Login Date/time

            That whole area is logging the login in sql.
            I am recording:
            ulink
            region_fk (this is specific to my database)
            event (Since this table is used for other events as well, I set it to "Login")
            user_agent is the user agent of the browser they are logging in from
            ip (IP Address of the user, Be careful with this one, my app is private so I don't worry about it. But there are certain countries where it is illegal to capture this type of information without notifying the user).

            All my tables have a field ModifiedDate which is a timestamp and is set to auto update when the record is inserted or changed. You would probably just want to add a field called time or something similar and have now() written in the sql statement for that value. My code isn't necessarily storing the datetime field explicitly.

            Comment


              #7
              Re: Last Login Date/time

              Can I set sql variables on a5w pages? So if I say "declare @date as datetime" then set "@date = now()" then have sql update to set last login field to @date? If so what is the code, what I have tried is returing an error and the page wont run

              Comment


                #8
                Re: Last Login Date/time

                Code:
                cn.execute("UPDATE user_table SET last_login_time = now() WHERE ulink = " + session.__protected__ulink)
                That should be all you really need. No need to declare a sql variable.

                Comment


                  #9
                  Re: Last Login Date/time

                  I am using an a5w page between the login page and the initial page., the code in the a5w page is like this:

                  cn.open("::Name::Trade")
                  '
                  ' Just to ensure the AEX is current
                  '
                  Server.ClearAEXCache()
                  '
                  session.norway = ""
                  currentusername = a5ws_getcurrentuser()
                  group_list = A5WS_Get_User_Assignments(currentusername)
                  group_list = crlf_to_comma(group_list)
                  if inlist2("XXXXX",group_list)
                  session.XXXXX = "Y"
                  else
                  session.XXXXX ="N"
                  end if

                  IF currentusername <> ""
                  args.set("uname",currentusername)
                  session.initial = sql_lookup(cn,"registeredusers","username=:uname","userinit",args)

                  IF session.initial <>""
                  dim fname as c
                  dim lname as c
                  fname = sql_lookup(cn,"registeredusers","username=:uname","firstname",args)
                  lname = sql_lookup(cn,"registeredusers","username=:uname","lastname",args)
                  session.fullname = alltrim(fname) + " " + alltrim(lname)
                  session.username = currentusername
                  setlogintime(currentusername)
                  END IF
                  END IF
                  cn.Close()
                  Response.Redirect("XXXXXXXX.a5w")
                  the setlogintime function is like this:

                  FUNCTION SetLoginTime AS V (Umail AS C )

                  DIM cn as SQL::Connection
                  DIM args as sql::arguments
                  dim sqlUpdateStatement as c
                  dim flagResult as l

                  flagResult = cn.open("::Name::Trade")
                  if flagResult = .f. then
                  end
                  end if

                  args.add("New__LASTLOGIN",now())
                  args.set("Usermail",Umail)

                  sqlUpdateStatement = <<%txt%
                  UPDATE registeredusers SET LASTLOGIN = :New__LASTLOGIN WHERE USERNAME = :Usermail
                  %txt%
                  cn.Execute(sqlUpdateStatement,args)

                  END FUNCTION

                  Comment


                    #10
                    Re: Last Login Date/time

                    I don't see anything wrong with that, but I don't think it needs to be it's own function, you are already opening the connection on the a5w page, why do it again? You should be able to replace that function with this one line of code.
                    Code:
                    cn.execute("UPDATE registeredusers SET LASTLOGIN = now() WHERE USERNAME = " + currentusername)
                    or for speed:
                    Code:
                    cn.execute(*concat("UPDATE registeredusers SET LASTLOGIN = now() WHERE USERNAME = ",currentusername))
                    EDIT: oh, lol, I though you were OP
                    Last edited by Sparticuz; 06-13-2012, 03:22 PM.

                    Comment


                      #11
                      Re: Last Login Date/time

                      This is what I have now, I am getting an error and the page wont even run, when I comment out the cn.execute the page will run

                      'To capture Last Login date and time
                      '0: Initialize connections
                      dim globalcn as sql::connection
                      flag = globalcn.open("::name::XXXX")

                      '1: Log entry into system
                      dim sql as c
                      dim args as sql::arguments
                      CurrentUserName = a5ws_getcurrentuser() 'CurrentUserName is email_address
                      cn.execute("UPDATE table_name SET last_login = now() where email_address = CurrentUserName")
                      flag = globalcn.Execute(sql, args)

                      'x: Clean u
                      globalcn.FreeResult()
                      globalcn.Close()
                      delete globalcn

                      Comment


                        #12
                        Re: Last Login Date/time

                        It's because your sql statement is incorrect.
                        Code:
                        dim args as sql::arguments
                        args.add("CurrentUserName",a5ws_getcurrentuser()) 'CurrentUserName is email_address
                        flag = globalcn.execute("UPDATE table_name SET last_login = now() where email_address = :CurrentUserName",args)

                        Comment


                          #13
                          Re: Last Login Date/time

                          My MSSQL field is not getting updated. I put this statement in sql query analyzer and it saids that now() is not a recongized built in function

                          UPDATE table_name SET last_login = now() email_address = '[email protected]'


                          Hopefully when I found out this I can get it to work, thanks for your help

                          Comment


                            #14
                            Re: Last Login Date/time

                            I'm not sure what it is for MSSQL, now() is a mysql function.

                            Actually, it's getDate()

                            http://stackoverflow.com/questions/3...-of-mysqls-now

                            Comment


                              #15
                              Re: Last Login Date/time

                              That is sql statement

                              UPDATE table_name SET last_login = now() where email_address = '[email protected]'

                              Comment

                              Working...
                              X