init III
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Console::Command::Admin::CustomerUser::Add;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::System::CustomerUser',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Add a customer user.');
|
||||
$Self->AddOption(
|
||||
Name => 'user-name',
|
||||
Description => "User name for the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'first-name',
|
||||
Description => "First name of the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'last-name',
|
||||
Description => "Last name of the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'email-address',
|
||||
Description => "Email address of the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'customer-id',
|
||||
Description => "Customer ID for the new customer user.",
|
||||
Required => 1,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddOption(
|
||||
Name => 'password',
|
||||
Description => "Password for the new customer user. If left empty, a password will be generated automatically.",
|
||||
Required => 0,
|
||||
HasValue => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Print("<yellow>Adding a new customer user...</yellow>\n");
|
||||
|
||||
# add customer user
|
||||
if (
|
||||
!$Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserAdd(
|
||||
Source => 'CustomerUser',
|
||||
UserLogin => $Self->GetOption('user-name'),
|
||||
UserFirstname => $Self->GetOption('first-name'),
|
||||
UserLastname => $Self->GetOption('last-name'),
|
||||
UserCustomerID => $Self->GetOption('customer-id'),
|
||||
UserPassword => $Self->GetOption('password'),
|
||||
UserEmail => $Self->GetOption('email-address'),
|
||||
UserID => 1,
|
||||
ChangeUserID => 1,
|
||||
ValidID => 1,
|
||||
)
|
||||
)
|
||||
{
|
||||
$Self->PrintError("Can't add customer user.");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Done.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -0,0 +1,79 @@
|
||||
# --
|
||||
# Copyright (C) 2001-2019 OTRS AG, https://otrs.com/
|
||||
# --
|
||||
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
|
||||
# the enclosed file COPYING for license information (GPL). If you
|
||||
# did not receive this file, see https://www.gnu.org/licenses/gpl-3.0.txt.
|
||||
# --
|
||||
|
||||
package Kernel::System::Console::Command::Admin::CustomerUser::SetPassword;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use parent qw(Kernel::System::Console::BaseCommand);
|
||||
|
||||
our @ObjectDependencies = (
|
||||
'Kernel::Config',
|
||||
'Kernel::System::CustomerUser',
|
||||
);
|
||||
|
||||
sub Configure {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
$Self->Description('Update the password for a customer user.');
|
||||
$Self->AddArgument(
|
||||
Name => 'user',
|
||||
Description => "Specify the user login of the agent/customer to be updated.",
|
||||
Required => 1,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
$Self->AddArgument(
|
||||
Name => 'password',
|
||||
Description => "Set a new password for the user (a password will be generated otherwise).",
|
||||
Required => 0,
|
||||
ValueRegex => qr/.*/smx,
|
||||
);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
sub Run {
|
||||
my ( $Self, %Param ) = @_;
|
||||
|
||||
my $Login = $Self->GetArgument('user');
|
||||
|
||||
$Self->Print("<yellow>Setting password for user $Login...</yellow>\n");
|
||||
|
||||
my $CustomerUserObject = $Kernel::OM->Get('Kernel::System::CustomerUser');
|
||||
my %CustomerUserList = $CustomerUserObject->CustomerSearch(
|
||||
UserLogin => $Login,
|
||||
);
|
||||
|
||||
if ( !scalar %CustomerUserList ) {
|
||||
$Self->PrintError("No customer user found with login '$Login'!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
# if no password has been provided, generate one
|
||||
my $Password = $Self->GetArgument('password');
|
||||
if ( !$Password ) {
|
||||
$Password = $CustomerUserObject->GenerateRandomPassword( Size => 12 );
|
||||
$Self->Print("<yellow>Generated password '$Password'.</yellow>\n");
|
||||
}
|
||||
|
||||
my $Result = $CustomerUserObject->SetPassword(
|
||||
UserLogin => $Login,
|
||||
PW => $Password,
|
||||
);
|
||||
|
||||
if ( !$Result ) {
|
||||
$Self->PrintError("Failed to set password!\n");
|
||||
return $Self->ExitCodeError();
|
||||
}
|
||||
|
||||
$Self->Print("<green>Successfully set password for customer user '$Login'.</green>\n");
|
||||
return $Self->ExitCodeOk();
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user