[cgiapp] How to integrate a module?

James.Q.L shijialeee at yahoo.com
Fri Jan 11 19:39:48 EST 2008


sorry, didn't have time to read through your email. 

you should check out the wiki, this page maybe help http://www.cgi-app.org/index.cgi?OrganizeApp
also search the list archive as this is a question asked few times before.

James.

--- adam at spatialsystems.org wrote:

> SUMMARY:
> How should I integrate my OO module with CGI::Applcaiton?
> 
> 
> 
> Details:
> Here is my first OO module ( Tools::User ) that administers users on my system.
> 
> Create a user object populated with user info from DB:
> my $user = Tools::User->new( $user_id );
> 
> Get info for user stored in db:
> my $name = $user->name;
> 
> Store info into object and save to db:
> $user->name( $new_name );
> 
> Check if a user exists:
> Tools::User->exists( $user_id ) or die "User $user_id doesn't exist";
> 
> Create new user and return object for user:
> my $user = Tools::User->insert({ id => 007, name => Bond });
> 
> 
> 
> QUESION:
> How should I integrate this with CGI::Application and CGI::Application::Plugin::Authentication?
> 
> 
> 
> IMPLEMENTATION:
> When a user logs in, Plugin::Authentication stores the User_Id in the session.  I'd like to take
> 
> that User_Id and run it in Tools::User->exists( $user_id ) and if it comes back false, then 
> redirect to a registration page where the user will get created on my system.
> 
> If the user already exists in my DB, then I want to load the info for them from my database and 
> have my user object avail from $self->user in my CGI::Application.
> 
> 
> 
> I'd like functionality similar to:
> 
> 
> package VzTools::CellAvail::WebApp;
> use strict;
> 
> use base qw( CGI::Application);
> 
> use CGI::Application::Plugin::Session;
> use CGI::Application::Plugin::Forward;
> use CGI::Application::Plugin::Authentication;
> use My::ActiveDirectory;
>  
> sub setup {
> 	my $self = shift;
> 
> 	$self->start_mode('login');
> 	$self->mode_param('rm');
> 	$self->run_modes(
> 		'login' 	=> 'show_login',
> 		'main' 		=> 'show_main',
> 		'register'	=> 'show_register',
> 	);
> 
> 	#  setup authentication
> 	$self->authen->config(
> 		DRIVER	=> [ 'Generic', \&login ],
> 		STORE			=> 'Session',
> 		LOGIN_RUNMODE	=> 'login',
> 		POST_LOGIN_RUNMODE => 'main',
> 		LOGOUT_RUNMODE	=> 'login',
> 	);	
> 
> 	$self->authen->protected_runmodes( 'main' );
> 
> 	$self->tmpl_path('templates');
> 
> 	$self->add_callback( 'load_tmpl', \&load_template_callback );
> 
> 	sub login {
> 	
> 		my ( $username, $password ) = @_; 
> 		my $ad_auth = My::ActiveDirectory->new('WIN');
> 	
> 		return 0 if not $ad_auth->login( $username, $password );
> 	
> 		$self->session->param( ad_auth_userinfo => $ad_auth->getUserInfo );
> 
> 		
> 		#########################################################################	
> 		#                                                                 	#
> 		#  if we've never seen the user before, redirect them to register	#
> 		#								#
> 	  	#  if they are already in the DB, then load their data with 		#
> 		#  Tools::User object that will be accessable everywhere via		#
> 		#  $self->user							#
> 		#								#
> 		#########################################################################
> 
> 		Tools::User->exists( %{ $self->session->param('ad_auth_userinfo') }->{user_id} } )
> 			or $self->forward('register');
> 		
> 		return $username;	
> 	
> 	}
> 
>     
> }
> 
> 
> sub show_main {
> 
> 	my $self = shift;
> 
> 	#########################################################################
> 	#								#
> 	#  retrieve user info, update user info, add user via class method	#
> 	#  from Tools::Users						#
> 	#								#
> 	#########################################################################
> 
> 
> 	#  retrieve user info
> 	my $name = $self->users->name
> 
> 
> 	#  update user info
> 	$self->user->name('New_Name');
> 
> 	#  class method to see if user exists
> 	$self->user->exists( $user_id ) or die "user doesn't exist";
> 
> 
> 	#  create new user and get it's object, dont't know if this is necessary for me to do.
> 	my $new_user_object = $self->user->insert({ id => 007, name => Bond });
> 
> }
> 
> #####  CGI::Application community mailing list  ################
> ##                                                            ##
> ##  To unsubscribe, or change your message delivery options,  ##
> ##  visit:  http://lists.openlib.org/mailman/listinfo/cgiapp    ##
> ##                                                            ##
> ##  Web archive:   http://lists.openlib.org/pipermail/cgiapp/   ##
> ##  Wiki:          http://cgiapp.erlbaum.net/                 ##
> ##                                                            ##
> ################################################################
> 
> 



      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 



More information about the cgiapp mailing list