Newer Older
153 lines | 4.424kb
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') {
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
8
  
9
    # Parameters
10
    my $id = param('id');
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
11
    my $name = param('name');
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
12
    my $email = param('email');
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
13
    my $password = param('password');
14
    my $password2 = param('password2');
15
    
16
    # Validator
17
    my $vc = app->vc;
18
    
19
    # Validation result
20
    my $validation = $vc->validation;
21
    
22
    # "id" check
23
    if (!(defined $id && length $id)) {
add user update page
Yuki Kimoto authored on 2016-04-07
24
      $validation->add_failed(id => 'User id is empty.');
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
25
    }
26
    elsif (!$vc->check($id, 'user_name')) {
add user update page
Yuki Kimoto authored on 2016-04-07
27
      $validation->add_failed(id => 'User id contain invalid character.');
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
28
    }
29
    elsif (length $id > 20) {
add user update page
Yuki Kimoto authored on 2016-04-07
30
      $validation->add_failed(id => 'User id is too long.');
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
31
    }
32
    else {
33
      my $row = app->dbi->model('user')->select(where => {id => $id})->one;
34
      if ($row) {
add user update page
Yuki Kimoto authored on 2016-04-07
35
        $validation->add_failed(id => "User id $id already exists");
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
36
      }
37
    }
added user management featur...
Yuki Kimoto authored on 2013-02-13
38
    
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
39
    # "name" check
40
    $name //= '';
41
    
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
42
    # "email" check
43
    if (!(defined $email && length $email)) {
44
      $validation->add_failed(email => "Mail must be not empty");
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
45
    }
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
46
    elsif ($email !~ /\@/) {
47
      $validation->add_failed(email => "Invalid mail address");
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
48
    }
49
    else {
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
50
      my $row = app->dbi->model('user')->select(where => {email => $email})->one;
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
51
      if ($row) {
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
52
        $validation->add_failed(email => "Mail $email already exists");
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
53
      }
54
    }
55
    
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
56
    # "password" check
57
    $password2 ||= '';
58
    if (!(defined $password && length $password)) {
59
      $validation->add_failed(password => 'Password is empty.');
60
    }
61
    elsif (!$vc->check($password, 'ascii_graphic')) {
62
      $validation->add_failed(password => 'Password contain invalid character.');
63
    }
64
    elsif ($password ne $password2) {
65
      $validation->add_failed(password => "Two password don't match");
66
    }
added user management featur...
Yuki Kimoto authored on 2013-02-13
67
    
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
68
    if ($validation->is_valid) {
added user management featur...
Yuki Kimoto authored on 2013-02-13
69
      
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
70
      # Encrypt password
71
      my ($password_encrypted, $salt) = $api->encrypt_password($password);
72
      my $params = {};
improved password encrypt sy...
Yuki Kimoto authored on 2013-04-09
73
      $params->{password} = $password_encrypted;
74
      $params->{salt} = $salt;
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
75
      $params->{name} = $name;
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
76
      $params->{email} = $email;
improved password encrypt sy...
Yuki Kimoto authored on 2013-04-09
77
      
78
      # Create user
revert encoding support
Yuki Kimoto authored on 2013-11-22
79
      eval { app->manager->create_user($id, $params) };
improve error message
Yuki Kimoto authored on 2014-02-13
80
      if (my $e = $@) {
81
        app->log->error(url_for . ": $e");
added create user directory ...
Yuki Kimoto authored on 2013-04-01
82
        $errors = ['Internal Error'];
83
      }
84
      else {
85
        $self->flash(success => 1);
86
        $self->flash(id => $id);
87
        $self->redirect_to('current');
88
      }
added user management featur...
Yuki Kimoto authored on 2013-02-13
89
    }
cleanup create user validati...
Yuki Kimoto authored on 2016-02-09
90
    else { $errors = $validation->messages }
added user management featur...
Yuki Kimoto authored on 2013-02-13
91
  }
92
%>
93

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

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

            
cleanup many pages
Yuki Kimoto authored on 2013-03-31
98
  <div class="container">
99
    % my $id = '';
100
    % if (flash('success')) {
101
      <div class="alert alert-success">
102
        <button type="button" class="close" data-dismiss="alert">&times;</button>
103
        Success: User <b><%= flash('id') %></b> is created.
104
      </div>
105
    % }
added create user directory ...
Yuki Kimoto authored on 2013-04-01
106
    
107
    % if ($errors) {
added branch deleting featur...
Yuki Kimoto authored on 2013-05-05
108
      <div class="alert alert-error">
added create user directory ...
Yuki Kimoto authored on 2013-04-01
109
        <button type="button" class="close" data-dismiss="alert">&times;</button>
110
        % for my $error (@$errors) {
111
          <p><%= $error %></p>
112
        % }
113
      </div>
114
    % }
115
    
improve admin page design
Yuki Kimoto authored on 2016-01-23
116
    <div class="topic1" style="text-align:center">Create User</div>
117
    <form class="user-form" action="<%= url_for->query(op => 'create') %>" method="post">
118
      <div class="user-form-container">
119
        <div>
add name and mail column to ...
Yuki Kimoto authored on 2016-04-06
120
          <div>ID</div>
121
          <div>
122
            <%= text_field 'id', placeholder => 'ID' %>
123
          </div>
124
        </div>
125
        <div>
126
          <div>Name</div>
127
          <div>
128
            <%= text_field 'name', placeholder => 'Name' %>
129
          </div>
130
        </div>
131
        <div>
132
          <div>Mail</div>
improve admin page design
Yuki Kimoto authored on 2016-01-23
133
          <div>
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
134
            <%= text_field 'email', placeholder => 'Mail' %>
added user management featur...
Yuki Kimoto authored on 2013-02-13
135
          </div>
improved create user page de...
Yuki Kimoto authored on 2013-03-31
136
        </div>
improve admin page design
Yuki Kimoto authored on 2016-01-23
137
        <div>
138
          <div>Password</div>
139
          <div>
improved create user page de...
Yuki Kimoto authored on 2013-03-31
140
            <%= password_field 'password', id => 'input-password', placeholder => 'Password' %>
141
            <%= password_field 'password2', id => 'input-password', placeholder => 'Password Again' %>
142
          </div>
143
        </div>
improve admin page design
Yuki Kimoto authored on 2016-01-23
144
        <div>
145
          <div>
rename btn-success to btn-gr...
Yuki Kimoto authored on 2016-11-30
146
            <button type="submit" class="btn btn-green" style="margin-top:20px">Create User</button>
added user management featur...
Yuki Kimoto authored on 2013-02-13
147
          </div>
148
        </div>
improve admin page design
Yuki Kimoto authored on 2016-01-23
149
      </div>
150
    </form>
151
    <div style="text-align:center;margin:20px 0"><big><a href="<%= url_for('/_admin/users') %>">Users</a></big></div>
added user management featur...
Yuki Kimoto authored on 2013-02-13
152
  </div>
cleanup many pages
Yuki Kimoto authored on 2013-03-31
153
  %= include '/include/footer';