$::auth->set_session_value('admin_password', $::lx_office_conf{authentication}->{admin_password});
$::auth->create_or_refresh_session;
- return if $self->apply_dbupgrade_scripts;
+ my $scripts_applied = $self->apply_dbupgrade_scripts;
- my $group = (SL::DB::Manager::AuthGroup->get_all(limit => 1))[0];
- if (!$group) {
+ if (! SL::DB::Manager::AuthGroup->get_all_count) {
SL::DB::AuthGroup->new(
name => t8('Full Access'),
description => t8('Full access to all functions'),
)->save;
}
- $self->action_login;
+ $self->action_login unless $scripts_applied;
}
#
countrycode => $defaults->language('de'),
numberformat => $defaults->numberformat('1.000,00'),
dateformat => $defaults->dateformat('dd.mm.yy'),
- stylesheet => "kivitendo.css",
+ stylesheet => "design40.css",
menustyle => "neu",
},
));
my $params = delete($::form->{user}) || { };
my $props = delete($params->{config_values}) || { };
my $is_new = !$params->{id};
+ my $check_previously_used = delete($::form->{check_previously_used}) || 0;
+ my $assign_documents = delete($::form->{assign_documents}) || 0;
# Assign empty arrays if the browser doesn't send those controls.
$params->{clients} ||= [];
my @errors = $self->user->validate;
if (@errors) {
- flash('error', @errors);
- $self->edit_user_form(title => $is_new ? t8('Create a new user') : t8('Edit User'));
- return;
+ $self->js->flash('error', $_) foreach @errors;
+ return $self->js->render();
+ }
+
+ # check if given login name was previously used and show a dialog if so
+ if ($is_new && $check_previously_used && $self->check_loginname_previously_used()) {
+ $self->js->run('show_loginname_previously_used_dialog');
+ return $self->js->render();
+ }
+
+ # rename previous usernames in employee table, if not set to assign
+ if ($is_new && !$assign_documents) {
+ my $clients = SL::DB::Manager::AuthClient->get_all_sorted;
+ for my $client (@$clients) {
+ my $now = DateTime->now_local;
+ my $timestamp = $now->format_cldr('yyyyMMddHHmmss');
+
+ my $dbh = $client->dbconnect(AutoCommit => 1);
+ next if !$dbh;
+ $dbh->do(qq|UPDATE employee SET login = ? WHERE login = ?;|,undef,
+ $params->{'login'} . $timestamp, $params->{'login'});
+ $dbh->disconnect;
+ }
}
$self->user->save;
sub init_all_printers { SL::DB::Manager::Printer ->get_all_sorted }
sub init_all_dateformats { [ qw(mm/dd/yy dd/mm/yy dd.mm.yy yyyy-mm-dd) ] }
sub init_all_numberformats { [ '1,000.00', '1000.00', '1.000,00', '1000,00', "1'000.00" ] }
-sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css) ] }
+sub init_all_stylesheets { [ qw(lx-office-erp.css Mobile.css kivitendo.css design40.css) ] }
sub init_all_dbsources { [ sort User->dbsources($::form) ] }
sub init_all_used_dbsources { { map { (join(':', $_->dbhost || 'localhost', $_->dbport || 5432, $_->dbname) => $_->name) } @{ $_[0]->all_clients } } }
sub init_all_accounting_methods { [ { id => 'accrual', name => t8('Accrual accounting') }, { id => 'cash', name => t8('Cash accounting') } ] }
return (%result, error => $::locale->text('The database user \'#1\' does not have superuser privileges.', $result{username}));
}
+sub check_loginname_previously_used() {
+ my ($self) = @_;
+
+ my $clients = SL::DB::Manager::AuthClient->get_all_sorted;
+ for my $client (@$clients) {
+ my $dbh = $client->dbconnect();
+ next if !$dbh;
+ my ($result) = $dbh->selectrow_array(qq|SELECT login FROM employee WHERE login = ?;|,undef,
+ $self->user->{'login'});
+ $dbh->disconnect;
+
+ if ($result) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
1;