<% # API my $api = gitprep_api; my $admin_user = app->manager->admin_user; if (defined $admin_user && $admin_user ne '') { $self->redirect_to('/'); return; } # Operator my $op = param('op') || ''; my $errors; if ($op eq 'create') { # Check existence admin user my $admin_user = app->manager->admin_user; if (defined $admin_user) { $errors = ['Admin user already exists.'] } else { # Validation my $params = $api->params; my $rule = [ password => [ ['not_blank' => 'Password is empty.'], ['ascii' => 'Password contains invalid character.'], [{'length' => {max => 20}} => 'Password is too long.'] ], {password_check => [qw/password password2/]} => {copy => 0} => [ ['duplication' => "Two password don't match."] ] ]; my $vresult = $self->app->vc->validate($params, $rule); if ($vresult->is_ok) { # Valida parameters my $params = $vresult->data; my $user = 'admin'; $params->{admin} = 1; my ($password_encryped, $salt) = $api->encrypt_password($params->{password}); $params->{password} = $password_encryped; $params->{salt} = $salt; # Create admin user $self->app->dbi->model('user')->insert($params, id => $user); # Redirect $self->flash(admin_user_created => 1); $self->redirect_to('/_login'); return; } else { $errors = $vresult->messages } } } %> % layout 'common', title => 'Start page'; %= include '/include/header';
% if ($errors) {
% for my $error (@$errors) {
<%= $error %>
% }
% }

Create Admin User

admin
<%= password_field 'password', id => 'input-password', placeholder => 'Password' %> <%= password_field 'password2', id => 'input-password', placeholder => 'Password Again' %>
%= include '/include/footer';