Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class control to close my form... 1

Status
Not open for further replies.

EzLogic

Programmer
Aug 21, 2001
1,230
US
I created a nice security module class (visually), which i just drop it on a form that needs to be authenticated.

in the Init() of the Class, i get the form name, and call a Authenticate() method (of the class).

Basically, in the init() of the class..

LOCAL lcFormName
lcFormName = UPPER(JUSTSTEM(SYS(1271,this.Parent)))
This.FormName = lcFormName

IF NOT This.Authenticate()
MESSAGEBOX("Access denied." + CHR(13) + CHR(13)+;
"You do not have permission to access the specified form."+CHR(13)+;
"Please contact your system administrator for support.",16,"Access denied")
ENDIF

However, after the messagebox(), i want to close the form.

i tried:
This.Parent.Release() && that didn't work.

how can i close the form if Authenticate() is not valid? without messing with the form's Init() or other methods of the form?

all i want to do is drop the class on the form, and now, it will authenticate?

my Forms are all sub-classed.. i thought, of dropping the authenticate class on the main class of my form, and in the main class form's init() i do that, and i return .f. in there..

then, i would have to do the following in everyform i have something in the init()

Subclassed form's init()
DODEFAULT() && i will have to do that if i have code in the init(), right?


Ali Koumaiha
TeknoPCS Inc.
Dearborn heights, MI 48127
 
I put this code in my main class form's init()

loAuth = This.Authenticate1
IF NOT loAuth.Authenticate()
MESSAGEBOX("Access denied." + CHR(13) + CHR(13)+;
"You do not have permission to access the specified form."+CHR(13)+;
"Please contact your system administrator for support.",16,"Access denied")
thisform.Release()
NODEFAULT
RETURN .f.
ELSE
RETURN .t.
ENDIF


*********************
My Subclassed form's init() (called ARInfo.scx)

DODEFAULT() && to execute the main class' init()
&& i have few other codes that pertain to this form (ARInfo.scx)



Ali Koumaiha
TeknoPCS Inc.
Dearborn heights, MI 48127
 
You're too lat and too early in the init of a class dropped on a form. Form initialisation takes place with form.load, form.init, form.show, form.activate. And class init is after form.load and before form init.

The ideal place to prevent a form from coming up is in it's load event. This your code would rather go into a form base class than in a seperate class you drop on forms. In this event no control has initialised, no data is accessed and loaded, etc. A much better situation to stop users which should not have access to a form and it's content.

The second best place to stop a form from being displayed is it's init. So what you could do in the init of your class is set a form property and let form init return .F., if that form property is set to not show the form, eg create a form property lAuthenticated, which defaults to eg goApp.lAuthenticated, the same property/meaning on a global application object set at a first login to the application itself.

As authentication is rather a central thing, why put it on a form or into a class designed to be dropped on a form at all? You could do the authentication process once at application start, let users have a security level that is determined by this one time login, which decides what menu items or toolbar buttons get active for them, which would even prevent them from starting a form at all. Or let them have several application roles associated to their login that enable certain modules of your app.

If you think about more protection, eg after some time of being inactive, the simplest is of course to have a screen saver timeout locking the computer.

Bye, Olaf.
 
Thanks Olaf..

in the main class of the form, i did the authentication instead of dropping a separate class on it.

added a property frmAuthenticated and i set to .t./.f. based on the authentication process.

in the subclass form:


DODEFAULT()
IF NOT thisform.frmAuthenticated
RETURN .f.
ENDIF



Ali Koumaiha
TeknoPCS Inc.
Dearborn heights, MI 48127
 
Hi Ali,

fine - how about DODEFAULT() and then RETURN thisform.frmAuthenticated as a simplyfication?

In fact, if you put the code into the Load event of your main form class, you could simply return the success of the authentication from there instead of a form property, as the form will only go on, if that's true anyway you don't really need to store it then.

Then it would even just be RETURN DODEFAULT() from subclasses or no code at all to simply inherit the Load event of the main class including it's return value.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top