NAME
Sybase::Login - A highly configurable Login widget for Sybperl and Perl/Tk
Change History
1.0 - Initial Implementation
1.1 - Componentized for perl5.0021bh, handlers fixed
1.2 - Set up for general distribution, added Version and VERSION. Changed funky menu generation to Optionmenus.
1.3 - Added presentDBMenu and presentSrvMenu options.
1.4 - OK, so I had troubles with PAUSE on 1.3
Todo: - Subclass Optionmenu to dynamically set up the Server selections on post (or Buttondown?)
DESCRIPTION
Login is a Widget that presents a dialog box to the user so that the user may enter his or her login name and password, as well as select the appropriate database and server.
USAGE
One uses Login by creating a new Login widget, adding at least one Database via the addDatabase method, configuring via the configure method, and then getting a valid login via the getVerification method.
Sample Program
-
#!/usr/local/bin/perl -w use Tk; use Sybase::DBlib; use Sybase::Login; use strict; my($main) = MainWindow->new; my($Login) = $main->Login; $Login->addDatabase('DB', 'SYBSRV1','SYB11'); $Login->addDatabase('DBBACK', 'SYBSRV1','SYB11'); $Login->configure(-User => $ENV{USER}, -ULabel => 'User Name:', -Title => 'Please Login'); my($msg) = $main->Message(-text => 'Ready to go')->pack; $main->Button(-text => 'kick me!', -command => sub { my($pwd, $usr, $db, $srv, $mDB); if ($Login->getVerification(-Force => 1)) { $pwd = $Login->cget(-Password); $usr = $Login->cget(-User); $db = $Login->cget(-Database); $srv = $Login->cget(-Server); print "Results good:\n\tUser:\t\t$usr\n"; print "\tPassword:\t$pwd\n\tDatabase:\t$db\n"; print "\tServer:\t\t$srv\n"; print "Verifying Login...\n"; $mDB = Sybase::DBlib->dblogin("$usr","$pwd", "$srv"); $mDB->dbuse($db); $mDB->dbclose; print "Login worked!!!\n"; } else { print "Login cancelled at User request.\n"; } })->pack; $main->Button(-text => 'exit', -command => sub {$main->destroy;})->pack; MainLoop; print "And I'm on my way home!\n"; exit;
Operation
The user is presented with a dialog box. The focus is on the username entry if no user name has been configured; otherwise, it is on the password entry. If multiple databases have been configured, the user may select the appropriate database from the menu button. If multiple servers have been configured for the selected database, the user may select the appropriate server from the menu button.
When the user has finished entering information, she may press the OK button to attempt to login, or the cancel button to abort the process. If the user presses the OK button, and the login succeeds, control returns to the caller. If the login fails, an error dialog box is displayed, and the user may press retry, or may press cancel, in which case control returns to the caller exactly as if the user had pressed cancel at the main login screen.
When control returns to the caller, the return value will be 1 if the login was successful, or 0 if not.
Notes
A caller may define a message or error handler either before or after calling any of the methods of this object. getCurrentVerification will restore the handlers extant when invoked.
Methods
getCurrentVerification
$Login->getCurrentVerification;
(No parameters)
return 1 if the current configuration will result in a valid login, 0 otherwise. No GUI is ever displayed.
getVerification
$Login->getVerification(-Force = ?);>
If the current configuration is NOT valid, activate the login frame. This will return 1 with a valid configuration, or 0 if the user hit cancel. If the -Force parameter is passed as 't', 'y', or 1, the login frame will be activated even if the current configuration is valid.
addDatabase
$Login->addDatabase(Database, Server List);
adds a database/server set. The first parameter is the name of the database, the second is a list of Associated Servers. See the code above for examples.
Note that the first server in the list is the default server for that database. Further note that adding a database a second time simply alters the servers.
clearDatabase
$Login->clearDatabase([Database[, Database,...]]);
Clears the given Database entries, or all databases if if none are specified.
Version
$Login->Version
(No parameters)
Returns the current version of Login
Configuration Items
Any of the following configuration items may be set via the configure method, or retrieved via the cget method.
-User
Set or get the username. The default is blank.
-Password
Set or get the password. The default is blank.
-Title
Set or get the Title of the Login Widget. The default is 'Database Login'
-Database
Set or get the default Database. The default is blank. The call will silently fail if the database is not configured via the AddDatabase method. If the configured server is not a valid server for the given database, the server will be set to the default server for the database.
-Server
Set or get the default Server. The default is blank. The call will silently fail if the server is not a valid server for the currently configured database.
-OKText
Set or get the text for the OK button. The default is OK.
-CancelText
Set or get the text for the Cancel button. The default is Cancel.
-ULabel
Set or get the label for the User name entry. The default is 'User:'.
-PLabel
Set or get the label for the Password entry. The default is 'Password:'.
-DLabel
Set or get the label for the Database Menu Button. The default is 'Database:'.
-SLabel
Set or get the label for the Server Menu Button. The default is 'Server:'.
-Labelfont
Set or get the font used for the labels. The default is '-Adobe-Courier-Bold-R-Normal--*-120-*'.
-EDlgTitle
Set or get the Title for the Error Dialog. The default is 'Database Login Error!'.
-EDlgText
Set or get the text displayed in the Error Dialog. The default is 'Unable to login to $db at $srv'. $db will be interpreted as the Database name, $srv will be interpreted as the Server name, $usr will be interpreted as the User name, and $pwd will be interpreted as the password.
-EDlgRetry
Set or get the text for the Retry button in the Error Dialog. The default is 'Retry'.
-EDlgCancel
Set or get the text for the Cancel button in the Error Dialog. The default is 'Cancel'.
-presentDBMenu
If set False, do not display the database menu. The database will be as configured, or default. Default is True.
-presentSrvMenu
If set False, do not display the server menu. The Server will be as configured, or default for the database. Default is True.
Author
Brent B. Powers, B2Pi
Currently on-site at Merrill Lynch, powers@ml.com
This code may be distributed under the same conditions as perl itself.
8 POD Errors
The following errors were encountered while parsing the POD:
- Around line 61:
You forgot a '=back' before '=head2'
- Around line 117:
'=item' outside of any '=over'
- Around line 119:
You forgot a '=back' before '=head2'
- Around line 145:
=back without =over
- Around line 153:
You forgot a '=back' before '=head2'
- Around line 199:
=back without =over
- Around line 210:
You forgot a '=back' before '=head2'
- Around line 371:
=back without =over