Stonefield Query calls the Application.BeforeLogin script just before presenting the Login dialog to the user. One possible use for this script is to automatically log a user in; if the script calls the Login method of the Users collection and that method succeeds, no login dialog is shown to the user. The example in the help topic for Login shows this. Another use is to automatically fill the Users collections with the names of the users from the target application; the example in the help topic for IsValidUser shows this.

Parameters
A reference to the Stonefield Query Application object.

Return Value
True if the application should continue, False if it should terminate.

Example
Visual FoxPro
This example programmatically adds a user to Stonefield Query if they don't already exist. Note the check for the user object after calling AddItem: if it fails (for example, all of the licenses have been assigned), AddItem returns null.

lparameters toApplication as SQApplication
local loUser as User
loUser = toApplication.Users.Item('SGREEN')
if vartype(loUser) <> 'O'
  loUser = toApplication.Users.AddItem('SGREEN')
  if vartype(loUser) <> 'O'
    loUser.Advanced = .T.
    loUser.FirstName = 'Sam'
    loUser.LastName = 'Green'
    loUser.Email = 'sgreen@somewhere.com'
    loUser.Password = 'testing'
    loUser.Roles = 'Managers'
  endif
endif
return .T.

Visual FoxPro
This example logs the user in using their network ID (this code assumes the password is the same as the user name).

lparameters toApplication as SQApplication
local lcUser, lcName, lnSize, llReturn
lcName = chr(0)
lnSize = 64
lcUser = replicate(lcName, lnSize)
declare integer WNetGetUser in Win32API ;
  string@ cName, string@ cUser, integer@ nBufferSize
WNetGetUser(@lcName, @lcUser, @lnSize)
lcUser = left(lcUser, at(chr(0), lcUser) - 1)
if not empty(lcUser)
  llReturn = toApplication.Users.Login(lcUser, lcUser)
endif not empty(lcUser)
return llReturn

VBScript
This example simply logs the user in as ADMIN.

function Main(Application)
Main = Application.Users.Login("ADMIN", "ADMIN")
end function

JavaScript
This example simply logs the user in as ADMIN.

function Main(Application) {
return Application.Users.Login('ADMIN', 'ADMIN') ;
}

C#
This example simply logs the user in as ADMIN.

Please note that the method in this script must be named Application_BeforeLogin.

public static bool Application_BeforeLogin(SFQApplication sfqApplication)
{	
  return sfqApplication.Users.Login("ADMIN", "ADMIN");
}

VB.NET
This example simply logs the user in as ADMIN.

Please note that the method in this script must be named Application_BeforeLogin.

public shared function Application_BeforeLogin(sfqApplication as SFQApplication) as Boolean

  return sfqApplication.Users.Login("ADMIN", "ADMIN")

End Function

See also

Scripts

© Stonefield Software Inc., 2023 • Updated: 02/21/18
Comment or report problem with topic