<% my $api = gitprep_api; my $op = param('op') || ''; my $errors; if ($op eq 'create') { # Validation my $params = $api->params; my $vc = $self->app->vc; my $rule = [ id => [ ['not_blank' => 'User name is empty.'], [user_name => 'User name contain invalid character.'], [{'length' => {max => 20}} => 'User name is too long.'] ], password => [ ['not_blank' => 'Password is empty.'], ['ascii' => 'Password contain invalid character.'], [{'length' => {max => 20}} => 'Password is too long.'] ], {password_check => [qw/password password2/]} => {copy => 0} => [ ['duplication' => "Two password don't match"] ] ]; my $vresult = $vc->validate($params, $rule); if ($vresult->is_ok) { # Valid parameters my $params = $vresult->data; my $id = delete $params->{id}; my ($password_encrypted, $salt) = $api->encrypt_password($params->{password}); $params->{password} = $password_encrypted; $params->{salt} = $salt; # Create user eval { app->manager->create_user($id, $params) }; if ($@) { app->log->error($@); $errors = ['Internal Error']; } else { $self->flash(success => 1); $self->flash(id => $id); $self->redirect_to('current'); } } else { $errors = $vresult->messages } } %> % layout 'common', title => 'Create User'; %= include '/include/header';
% my $id = ''; % if (flash('success')) {
Success: User <%= flash('id') %> is created.
% } % if ($errors) {
% for my $error (@$errors) {

<%= $error %>

% }
% }

Create User

<%= text_field id => $id, placeholder => 'User', id =>'user-name'%>
<%= password_field 'password', id => 'input-password', placeholder => 'Password' %> <%= password_field 'password2', id => 'input-password', placeholder => 'Password Again' %>
Users
%= include '/include/footer';