<% my $api = gitprep_api; my $op = param('op') || ''; my $errors; if ($op eq 'create') { # Parameters my $id = param('id'); my $name = param('name'); my $email = param('email'); my $password = param('password'); my $password2 = param('password2'); # Validator my $vc = app->vc; # Validation result my $validation = $vc->validation; # "id" check if (!(defined $id && length $id)) { $validation->add_failed(id => 'User id is empty.'); } elsif (!$vc->check($id, 'user_name')) { $validation->add_failed(id => 'User id contain invalid character.'); } elsif (length $id > 20) { $validation->add_failed(id => 'User id is too long.'); } else { my $row = app->dbi->model('user')->select(where => {id => $id})->one; if ($row) { $validation->add_failed(id => "User id $id already exists"); } } # "name" check $name //= ''; # "email" check if (!(defined $email && length $email)) { $validation->add_failed(email => "Mail must be not empty"); } elsif ($email !~ /\@/) { $validation->add_failed(email => "Invalid mail address"); } else { my $row = app->dbi->model('user')->select(where => {email => $email})->one; if ($row) { $validation->add_failed(email => "Mail $email already exists"); } } # "password" check $password2 ||= ''; if (!(defined $password && length $password)) { $validation->add_failed(password => 'Password is empty.'); } elsif (!$vc->check($password, 'ascii_graphic')) { $validation->add_failed(password => 'Password contain invalid character.'); } elsif ($password ne $password2) { $validation->add_failed(password => "Two password don't match"); } if ($validation->is_valid) { # Encrypt password my ($password_encrypted, $salt) = $api->encrypt_password($password); my $params = {}; $params->{password} = $password_encrypted; $params->{salt} = $salt; $params->{name} = $name; $params->{email} = $email; # Create user eval { app->manager->create_user($id, $params) }; if (my $e = $@) { app->log->error(url_for . ": $e"); $errors = ['Internal Error']; } else { $self->flash(success => 1); $self->flash(id => $id); $self->redirect_to('current'); } } else { $errors = $validation->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
ID
<%= text_field 'id', placeholder => 'ID' %>
Name
<%= text_field 'name', placeholder => 'Name' %>
Mail
<%= text_field 'email', placeholder => 'Mail' %>
Password
<%= password_field 'password', id => 'input-password', placeholder => 'Password' %> <%= password_field 'password2', id => 'input-password', placeholder => 'Password Again' %>
Users
%= include '/include/footer';