[vhffs-dev] [873] moved "suing" code to su.pl instead of panel.pl

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 873
Author:   gradator
Date:     2007-09-08 00:26:51 +0000 (Sat, 08 Sep 2007)

Log Message:
-----------
moved "suing" code to su.pl instead of panel.pl

Modified Paths:
--------------
    trunk/vhffs-panel/admin/su.pl
    trunk/vhffs-panel/panel.pl
    trunk/vhffs-panel/templates/admin/misc/su.tmpl


Modified: trunk/vhffs-panel/admin/su.pl
===================================================================
--- trunk/vhffs-panel/admin/su.pl	2007-09-08 00:07:13 UTC (rev 872)
+++ trunk/vhffs-panel/admin/su.pl	2007-09-08 00:26:51 UTC (rev 873)
@@ -52,33 +52,53 @@
 exit 0 unless $session;
 
 my $vhffs = $panel->{'vhffs'};
-my $maintemplate = $panel->{'template'};
-my $user = $panel->{'user'};
-#my $group = $panel->{'group'};
-my $projectname = $session->param("project");
 my $cgi = $panel->{'cgi'};
-my $servername = $cgi->param("name");
-my $template;
+my $templatedir = $panel->{templatedir};
 
-my $templatesdir = $vhffs->get_config->get_templatedir;
+my $username = $cgi->param('user');
 
-if( $user->is_admin != 1 )
+if( $panel->{user}->is_admin != 1 )
 {
 	
-	$template = new HTML::Template( filename => $templatesdir."/panel/misc/simplemsg.tmpl" );
-	my $message = gettext( "You are not allowed to see it");
-	$template->param( MESSAGE => $message );
+	my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
+	$template->param( MESSAGE =>  gettext( 'You\'re not an administrator' ) );
+	$panel->build( $template );
 }
 else
 {
-	$template = new HTML::Template( filename => $templatesdir."/panel/admin/misc/su.tmpl" );
+	unless( defined $username )  {
+		my $template = new HTML::Template( filename => $templatedir."/panel/admin/misc/su.tmpl" );
+		$template->param( TITLE => gettext("Change user-id") );	
+		$template->param( TEXT => gettext("Username") );
+		$template->param( TEXT_SUBMIT => gettext("Su !") );
+		$panel->build( $template );
+	}
+	else
+	{
+		my $message = '';
 
-	$template->param( TITLE => gettext("Change user-id") );
+		my $user = Vhffs::User::get_by_username( $vhffs , $username );
+		if( defined $user )
+		{
+			$session->clear('username');
+			$session->clear('uid');
+			$session->param('username', $user->get_username);
+			$session->param('uid', $user->get_uid);
+			$session->flush();
 
-	$template->param( TEXT => gettext("Username") );
-	$template->param( TEXT_SUBMIT => gettext("Su !") );
+			$panel = new Vhffs::Panel::Main();
+			$session = $panel->get_session;
+			$message = gettext( sprintf( 'Su successful with name %s' , $user->get_username) );
+		}
+		else
+		{
+			$message = sprintf( gettext( 'User %s does not exist' ) , $username  );
+		}
+
+		my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
+		$template->param( MESSAGE => $message );
+		$panel->build( $template );
+	}
 }
 
-$panel->build( $template );
 $panel->display;
-

Modified: trunk/vhffs-panel/panel.pl
===================================================================
--- trunk/vhffs-panel/panel.pl	2007-09-08 00:07:13 UTC (rev 872)
+++ trunk/vhffs-panel/panel.pl	2007-09-08 00:26:51 UTC (rev 873)
@@ -39,8 +39,6 @@
 use strict;
 
 use lib '%VHFFS_LIB_DIR%';
-use Vhffs::User;
-use Vhffs::Main;
 use Vhffs::Panel::Main;
 use Vhffs::Panel::Menu;
 
@@ -49,50 +47,5 @@
 my $session = $panel->get_session;
 exit 0 unless $session;
 
-my $vhffs = $panel->{'vhffs'};
-my $user = $panel->{'user'};
-my $cgi = $panel->{'cgi'};
-my $templatedir = $panel->{'templatedir'};
-
-my $su_user = $cgi->param('su_user');
-
-#We try to know if an admin want to su
-if( defined $su_user )
-{
-	my $message = "";
-
-	if( $user->is_admin == 1 )
-	{
-		my $user_bis = Vhffs::User::get_by_username( $vhffs , $su_user );
-		if( defined( $user_bis ) ) 
-		{
-			$user = $user_bis;
-			$session->clear("username");
-			$session->clear("uid");
-			$session->param("username", $user_bis->get_username);
-			$session->param("uid", $user_bis->get_uid);
-			$session->flush();
-			$panel = new Vhffs::Panel::Main();
-			$session = $panel->get_session;
-			$message = gettext( sprintf( "Su successful with name %s " , $su_user) );
-		}
-		else
-		{
-			$message = sprintf( gettext( "User %s does not exists" ) , $su_user  );
-		}
-	}
-	else
-	{
-		$message = gettext( "You're not an administrator" );
-	}
-
-	my $template = new HTML::Template( filename => $templatedir."/panel/misc/simplemsg.tmpl" );
-	$template->param( MESSAGE => $message );
-	$panel->build( $template );
-}
-else
-{
-	$panel->build( $panel->welcome );
-}
-
+$panel->build( $panel->welcome );
 $panel->display;

Modified: trunk/vhffs-panel/templates/admin/misc/su.tmpl
===================================================================
--- trunk/vhffs-panel/templates/admin/misc/su.tmpl	2007-09-08 00:07:13 UTC (rev 872)
+++ trunk/vhffs-panel/templates/admin/misc/su.tmpl	2007-09-08 00:26:51 UTC (rev 873)
@@ -1,11 +1,11 @@
 <h1><TMPL_VAR NAME="TITLE"></h1>
 
-<form method="post" action="/panel.pl">
+<form method="post" action="/admin/su.pl">
 	<p>
 		<label for="TEXT">
 			<TMPL_VAR NAME="TEXT">
 		</label>
-		<input type="text" name="su_user" id="su_user" />
+		<input type="text" name="user" id="user" />
 	</p>
 	<p class="button" id="buttonSend">
 		<input type="submit" value="<TMPL_VAR NAME="TEXT_SUBMIT">" />


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/