Newer Older
104 lines | 3.332kb
added user management featur...
Yuki Kimoto authored on 2013-02-13
1
<%
cleanup many pages
Yuki Kimoto authored on 2013-03-31
2
  my $api = gitprep_api;
added user management featur...
Yuki Kimoto authored on 2013-02-13
3
  
4
  my $op = param('op') || '';
5
  
6
  my $errors;
7
  if ($op eq 'create') {
8
    
added user delete feature
Yuki Kimoto authored on 2013-04-09
9
    # Validation
improved password encrypt sy...
Yuki Kimoto authored on 2013-04-09
10
    my $params = $api->params;
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
11
    my $vc = $self->app->vc;
added user management featur...
Yuki Kimoto authored on 2013-02-13
12
    my $rule = [
13
      id => [
added user delete feature
Yuki Kimoto authored on 2013-04-09
14
        ['not_blank' => 'User name is empty.'],
added admin user tests
Yuki Kimoto authored on 2013-05-17
15
        [user_name => 'User name contain invalid character.'],
added user delete feature
Yuki Kimoto authored on 2013-04-09
16
        [{'length' => {max => 20}} => 'User name is too long.']
added user management featur...
Yuki Kimoto authored on 2013-02-13
17
      ],
18
      password => [
added admin user tests
Yuki Kimoto authored on 2013-05-17
19
        ['not_blank' => 'Password is empty.'],
added user management featur...
Yuki Kimoto authored on 2013-02-13
20
        ['ascii' => 'Password contain invalid character.'],
21
        [{'length' => {max => 20}} => 'Password is too long.']
22
      ],
23
      {password_check => [qw/password password2/]}
24
        => {copy => 0}
25
        => [
26
          ['duplication' => "Two password don't match"]
27
        ]
28
    ];
rename validator to vc to up...
Yuki Kimoto authored on 2013-12-02
29
    my $vresult = $vc->validate($params, $rule);
added user management featur...
Yuki Kimoto authored on 2013-02-13
30
    
31
    if ($vresult->is_ok) {
32
      
improved password encrypt sy...
Yuki Kimoto authored on 2013-04-09
33
      # Valid parameters
34
      my $params = $vresult->data;
35
      my $id = delete $params->{id};
36
      my ($password_encrypted, $salt)
37
        = $api->encrypt_password($params->{password});
38
      $params->{password} = $password_encrypted;
39
      $params->{salt} = $salt;
40
      
41
      # Create user
revert encoding support
Yuki Kimoto authored on 2013-11-22
42
      eval { app->manager->create_user($id, $params) };
added create user directory ...
Yuki Kimoto authored on 2013-04-01
43
      if ($@) {
44
        app->log->error($@);
45
        $errors = ['Internal Error'];
46
      }
47
      else {
48
        $self->flash(success => 1);
49
        $self->flash(id => $id);
50
        $self->redirect_to('current');
51
      }
added user management featur...
Yuki Kimoto authored on 2013-02-13
52
    }
improved password encrypt sy...
Yuki Kimoto authored on 2013-04-09
53
    else { $errors = $vresult->messages }
added user management featur...
Yuki Kimoto authored on 2013-02-13
54
  }
55
%>
56

            
add title
Yuki Kimoto authored on 2013-06-12
57
% layout 'common', title => 'Create User';
added user management featur...
Yuki Kimoto authored on 2013-02-13
58

            
improved create user page de...
Yuki Kimoto authored on 2013-03-31
59
  %= include '/include/header';
added user management featur...
Yuki Kimoto authored on 2013-02-13
60

            
cleanup many pages
Yuki Kimoto authored on 2013-03-31
61
  <div class="container">
62
    % my $id = '';
63
    % if (flash('success')) {
64
      <div class="alert alert-success">
65
        <button type="button" class="close" data-dismiss="alert">&times;</button>
66
        Success: User <b><%= flash('id') %></b> is created.
67
      </div>
68
    % }
added create user directory ...
Yuki Kimoto authored on 2013-04-01
69
    
70
    % if ($errors) {
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
71
      <div class="alert alert-error">
added create user directory ...
Yuki Kimoto authored on 2013-04-01
72
        <button type="button" class="close" data-dismiss="alert">&times;</button>
73
        % for my $error (@$errors) {
74
          <p><%= $error %></p>
75
        % }
76
      </div>
77
    % }
78
    
improved create user page de...
Yuki Kimoto authored on 2013-03-31
79
    <div class="text-center"><h3>Create User</h3></div>
cleanup
Yuki Kimoto authored on 2013-05-13
80
    <div class="well" style="background:white;padding-top:15px;padding-left:60px;width:300px;margin-left:auto;margin-right:auto">
cleanup many pages
Yuki Kimoto authored on 2013-03-31
81
      <form action="<%= url_for->query(op => 'create') %>" method="post">
improved create user page de...
Yuki Kimoto authored on 2013-03-31
82
        <div class="control-group">
83
          <label class="control-label" for="user-name">User name</label>
84
          <div class="controls">
85
            <%= text_field id => $id, placeholder => 'User', id =>'user-name'%>
added user management featur...
Yuki Kimoto authored on 2013-02-13
86
          </div>
improved create user page de...
Yuki Kimoto authored on 2013-03-31
87
        </div>
88
        <div class="control-group">
89
          <label class="control-label" for="input-password">Password</label>
90
          <div class="controls">
91
            <%= password_field 'password', id => 'input-password', placeholder => 'Password' %>
92
            <%= password_field 'password2', id => 'input-password', placeholder => 'Password Again' %>
93
          </div>
94
        </div>
95
        <div class="control-group">
96
          <div class="controls">
97
            <button type="submit" class="btn">Create User</button>
added user management featur...
Yuki Kimoto authored on 2013-02-13
98
          </div>
99
        </div>
improved create user page de...
Yuki Kimoto authored on 2013-03-31
100
      </form>
101
    </div>
added tests and move delete ...
Yuki Kimoto authored on 2013-05-18
102
    <div class="text-center" style="margin-bottom:20px"><big><a href="<%= url_for('/_admin/users') %>">Users</a></big></div>
added user management featur...
Yuki Kimoto authored on 2013-02-13
103
  </div>
cleanup many pages
Yuki Kimoto authored on 2013-03-31
104
  %= include '/include/footer';