aboutsummaryrefslogtreecommitdiffstats
path: root/AdminPanel/Users
diff options
context:
space:
mode:
authorMatteo Pasotti <matteo.pasotti@gmail.com>2013-12-11 00:35:19 +0100
committerMatteo Pasotti <matteo.pasotti@gmail.com>2013-12-11 00:35:19 +0100
commit9289a168a6d993769364cf7e2345e390e7da2824 (patch)
treefb4f5e8c03721333461ba12635b2ad3c4fb9939b /AdminPanel/Users
parent52222a2ca1394794c39a2ffe3a3a01885294ba5b (diff)
parentfe52154a0eb1dde68f2d5f19aa8deb154740c326 (diff)
downloadcolin-keep-9289a168a6d993769364cf7e2345e390e7da2824.tar
colin-keep-9289a168a6d993769364cf7e2345e390e7da2824.tar.gz
colin-keep-9289a168a6d993769364cf7e2345e390e7da2824.tar.bz2
colin-keep-9289a168a6d993769364cf7e2345e390e7da2824.tar.xz
colin-keep-9289a168a6d993769364cf7e2345e390e7da2824.zip
Merge branch 'master' of ssh://git.mageia.org/software/adminpanel
Diffstat (limited to 'AdminPanel/Users')
-rw-r--r--AdminPanel/Users/GUsers.pm144
-rw-r--r--AdminPanel/Users/users.pm19
2 files changed, 131 insertions, 32 deletions
diff --git a/AdminPanel/Users/GUsers.pm b/AdminPanel/Users/GUsers.pm
index 388b922..92c477a 100644
--- a/AdminPanel/Users/GUsers.pm
+++ b/AdminPanel/Users/GUsers.pm
@@ -35,6 +35,7 @@ use run_program;
## USER is from userdrake
use USER;
use utf8;
+use log;
use Glib;
use yui;
@@ -47,6 +48,95 @@ our @EXPORT = qw(addUserDialog
);
+sub labeledFrameBox()
+{
+ my ($parent, $label) = @_;
+
+ my $factory = yui::YUI::widgetFactory;
+
+ my $frame = $factory->createFrame($parent, $label);
+ $frame->setWeight( $yui::YD_HORIZ, 1);
+
+ $frame = $factory->createHVCenter( $frame );
+ $frame = $factory->createVBox( $frame );
+ return $frame;
+}
+
+######################################
+##
+## ChooseGroup
+##
+## creates a popup dialog to ask if
+## adding user to existing group or
+## to 'users' group.
+##
+## returns 0 or 1 (choice done)
+## -1 cancel, or exit
+##
+sub ChooseGroup() {
+ my $choice = -1;
+
+ ## push application title
+ my $appTitle = yui::YUI::app()->applicationTitle();
+ ## set new title to get it in dialog
+ yui::YUI::app()->setApplicationTitle(N("Choose group"));
+
+ my $factory = yui::YUI::widgetFactory;
+
+ my $dlg = $factory->createPopupDialog();
+ my $layout = $factory->createVBox($dlg);
+
+
+ my $frame = $factory->createFrame($layout, N("A group with this name already exists. What would you like to do?"));
+ $frame->setWeight( $yui::YD_HORIZ, 1);
+ $frame = $factory->createHVCenter( $frame );
+ $frame = $factory->createVBox( $frame );
+
+ my $rbg = $factory->createRadioButtonGroup( $frame );
+ $frame = $factory->createVBox( $rbg );
+ my $align = $factory->createLeft($frame);
+
+ my $rb1 = $factory->createRadioButton( $align, N("Add to the existing group"), 1);
+ $rb1->setNotify(1);
+ $rbg->addRadioButton( $rb1 );
+ $align = $factory->createLeft($frame);
+ my $rb2 = $factory->createRadioButton( $align, N("Add to the 'users' group"), 0);
+ $rb2->setNotify(1);
+ $rbg->addRadioButton( $rb2 );
+
+ my $hbox = $factory->createHBox($layout);
+ $align = $factory->createRight($hbox);
+ my $cancelButton = $factory->createPushButton($align, N("Cancel"));
+ my $okButton = $factory->createPushButton($hbox, N("Ok"));
+ while(1) {
+ my $event = $dlg->waitForEvent();
+ my $eventType = $event->eventType();
+
+ #event type checking
+ if ($eventType == $yui::YEvent::CancelEvent) {
+ last;
+ }
+ elsif ($eventType == $yui::YEvent::WidgetEvent) {
+ # widget selected
+ my $widget = $event->widget();
+ if ($widget == $cancelButton) {
+ last;
+ }
+ if ($widget == $okButton) {
+ $choice = $rb1->value() ? 0 : 1 ;
+ last;
+ }
+ }
+ }
+
+ destroy $dlg;
+
+ #restore old application title
+ yui::YUI::app()->setApplicationTitle($appTitle);
+
+ return $choice;
+}
+
sub addUserDialog {
my $GetValue = -65533; ## Used by USER (for getting values? TODO need explanations, where?)
my $dontcreatehomedir = 0; my $is_system = 0;
@@ -129,15 +219,8 @@ sub addUserDialog {
$align = $factory->createLeft($hbox);
my $uidManually = $factory->createCheckBox($align, N("Specify user ID manually"), 0);
$align = $factory->createRight($hbox);
- my $UID = 0;
- if ($optional->hasSlider()) {
- $UID = $optional->createSlider($align, N("UID"), 500, 65000, 500);
- }
- else {
- # UID must checked in ncurses, value is entered by keyboard without
- # range restriction
- $UID = $factory->createInputField($align, N("UID"), 0);
- }
+
+ my $UID = $factory->createIntField($align, N("UID"), 1, 65000, 500);
$UID->setEnabled($uidManually->value());
$uidManually->setNotify(1);
@@ -215,12 +298,10 @@ sub addUserDialog {
my $uid = 0;
if ($continue && $uidManually->value()) {
if (($uid = $UID->value()) < 500) {
- $errorString = N("User Uid is < 500");
- $continue = 0;
-# TODO uidchoice
-# my $uidchoice = GimmeChoice(N("User Uid is < 500"),
-# N("Creating a user with a UID less than 500 is not recommended.\n Are you sure you want to do this?\n\n"));
-# $uidchoice and $userEnt->Uid($u{uid});
+ $errorString = "";
+ my $uidchoice = AdminPanel::Shared::ask_YesOrNo(N("User Uid is < 500"),
+ N("Creating a user with a UID less than 500 is not recommended.\nAre you sure you want to do this?\n\n"));
+ $continue = $uidchoice and $userEnt->Uid($uid);
} else {
$userEnt and $userEnt->Uid($uid);
}
@@ -231,23 +312,24 @@ sub addUserDialog {
#Check if group exist
my $gr = $ctx->LookupGroupByName($username);
if ($gr) {
-# TODO ChooseGroup
-# my $groupchoice = ChooseGroup();
-# if ($groupchoice == 0 && !$error) {
-# #You choose to put it in the existing group
-# $u{gid} = $gr->Gid($GetValue);
-# } elsif ($groupchoice == 1) {
-# # Put it in 'users' group
-# log::explanations(N("Putting %s to 'users' group",
-# $u{username}));
-# $u{gid} = Add2UsersGroup($u{username});
-# }
- $errorString = "TODO " . N("Choose group");
- $continue = 0;
+ my $groupchoice = ChooseGroup();
+ if ($groupchoice == 0 ) {
+ #You choose to put it in the existing group
+ $gid = $gr->Gid($GetValue);
+ } elsif ($groupchoice == 1) {
+ # Put it in 'users' group
+ log::explanations(N("Putting %s to 'users' group",
+ $username));
+ $gid = AdminPanel::Users::user::Add2UsersGroup($username);
+ }
+ else {
+ $errorString = "";
+ $continue = 0;
+ }
} else {
#it's a new group: Add it
my $newgroup = $ctx->InitGroup($username,$is_system);
-# log::explanations(N("Creating new group: %s", $u{username}));
+ log::explanations(N("Creating new group: %s", $username));
$gid = $newgroup->Gid($GetValue);
$ctx->GroupAdd($newgroup);
}
@@ -260,12 +342,12 @@ sub addUserDialog {
if (!$continue) {
#---rasie error
- AdminPanel::Shared::msgBox($errorString);
+ AdminPanel::Shared::msgBox($errorString) if ($errorString);
}
else {
## OK let's create the user
print N("Adding user: ") . $username . " \n";
-# log::explanations(N("Adding user: %s", $u{username}));
+ log::explanations(N("Adding user: %s"), $username);
my $loginshell = $loginShell->value();
my $fullname = $fullName->value();
$userEnt->Gecos($fullname); $userEnt->LoginShell($loginshell);
diff --git a/AdminPanel/Users/users.pm b/AdminPanel/Users/users.pm
index 1b876a3..a94aa05 100644
--- a/AdminPanel/Users/users.pm
+++ b/AdminPanel/Users/users.pm
@@ -20,6 +20,7 @@ our @EXPORT = qw(
valid_username
valid_groupname
GetFaceIcon
+ Add2UsersGroup
);
sub facesdir() {
@@ -101,8 +102,24 @@ sub GetFaceIcon {
return $current_icon;
}
+##################################################
+## Add2UsersGroup
+## params
+##
+## 'name' username
+## 'ctx' USER::ADMIN object
+##
+## return
+## gid group id
+##
+sub Add2UsersGroup {
+ my ($name, $ctx) = @_;
+ my $GetValue = -65533; ## Used by USER (for getting values? TODO need explanations, where?)
-
+ my $usersgroup = $ctx->LookupGroupByName('users');
+ $usersgroup->MemberName($name, 1);
+ return $usersgroup->Gid($GetValue);
+}
1;