... | ... |
@@ -21,18 +21,18 @@ |
21 | 21 |
|
22 | 22 |
# "id" check |
23 | 23 |
if (!(defined $id && length $id)) { |
24 |
- $validation->add_failed(id => 'User name is empty.'); |
|
24 |
+ $validation->add_failed(id => 'User id is empty.'); |
|
25 | 25 |
} |
26 | 26 |
elsif (!$vc->check($id, 'user_name')) { |
27 |
- $validation->add_failed(id => 'User name contain invalid character.'); |
|
27 |
+ $validation->add_failed(id => 'User id contain invalid character.'); |
|
28 | 28 |
} |
29 | 29 |
elsif (length $id > 20) { |
30 |
- $validation->add_failed(id => 'User name is too long.'); |
|
30 |
+ $validation->add_failed(id => 'User id is too long.'); |
|
31 | 31 |
} |
32 | 32 |
else { |
33 | 33 |
my $row = app->dbi->model('user')->select(where => {id => $id})->one; |
34 | 34 |
if ($row) { |
35 |
- $validation->add_failed(id => "User $id already exists"); |
|
35 |
+ $validation->add_failed(id => "User id $id already exists"); |
|
36 | 36 |
} |
37 | 37 |
} |
38 | 38 |
|
... | ... |
@@ -49,7 +49,7 @@ |
49 | 49 |
else { |
50 | 50 |
my $row = app->dbi->model('user')->select(where => {mail => $mail})->one; |
51 | 51 |
if ($row) { |
52 |
- $validation->add_failed(id => "Mail $mail already exists"); |
|
52 |
+ $validation->add_failed(mail => "Mail $mail already exists"); |
|
53 | 53 |
} |
54 | 54 |
} |
55 | 55 |
|
... | ... |
@@ -0,0 +1,136 @@ |
1 |
+<% |
|
2 |
+ my $api = gitprep_api; |
|
3 |
+ |
|
4 |
+ my $op = param('op') || ''; |
|
5 |
+ my $user_id = param('id'); |
|
6 |
+ |
|
7 |
+ my $errors; |
|
8 |
+ if ($op eq 'update') { |
|
9 |
+ |
|
10 |
+ # Parameters |
|
11 |
+ my $id = param('id'); |
|
12 |
+ my $name = param('name'); |
|
13 |
+ my $mail = param('mail'); |
|
14 |
+ |
|
15 |
+ # Validator |
|
16 |
+ my $vc = app->vc; |
|
17 |
+ |
|
18 |
+ # Validation result |
|
19 |
+ my $validation = $vc->validation; |
|
20 |
+ |
|
21 |
+ # "id" check |
|
22 |
+ if (!(defined $id && length $id)) { |
|
23 |
+ $validation->add_failed(id => 'User id is empty.'); |
|
24 |
+ } |
|
25 |
+ |
|
26 |
+ # "name" check |
|
27 |
+ $name //= ''; |
|
28 |
+ |
|
29 |
+ # "mail" check |
|
30 |
+ if (!(defined $mail && length $mail)) { |
|
31 |
+ $validation->add_failed(mail => "Mail must be not empty"); |
|
32 |
+ } |
|
33 |
+ elsif ($mail !~ /\@/) { |
|
34 |
+ $validation->add_failed(mail => "Invalid mail address"); |
|
35 |
+ } |
|
36 |
+ else { |
|
37 |
+ my $where = app->dbi->where; |
|
38 |
+ my $clause = [ |
|
39 |
+ 'and', |
|
40 |
+ ':mail{=}', |
|
41 |
+ ':id{<>}' |
|
42 |
+ ]; |
|
43 |
+ my $param = { |
|
44 |
+ mail => $mail, |
|
45 |
+ id => $user_id |
|
46 |
+ }; |
|
47 |
+ $where->clause($clause); |
|
48 |
+ $where->param($param); |
|
49 |
+ |
|
50 |
+ my $row = app->dbi->model('user')->select(where => $where)->one; |
|
51 |
+ if ($row) { |
|
52 |
+ $validation->add_failed(mail => "Mail $mail already exists"); |
|
53 |
+ } |
|
54 |
+ } |
|
55 |
+ |
|
56 |
+ if ($validation->is_valid) { |
|
57 |
+ |
|
58 |
+ # Encrypt password |
|
59 |
+ my $params = {}; |
|
60 |
+ $params->{name} = $name; |
|
61 |
+ $params->{mail} = $mail; |
|
62 |
+ |
|
63 |
+ # Update user |
|
64 |
+ eval { app->dbi->model('user')->update($params, where => {id => $id}) }; |
|
65 |
+ if (my $e = $@) { |
|
66 |
+ app->log->error(url_for . ": $e"); |
|
67 |
+ $errors = ['Internal Error']; |
|
68 |
+ } |
|
69 |
+ else { |
|
70 |
+ $self->flash(success => 1); |
|
71 |
+ $self->flash(id => $id); |
|
72 |
+ $self->redirect_to(url_for->query(id => $id)); |
|
73 |
+ } |
|
74 |
+ } |
|
75 |
+ else { $errors = $validation->messages } |
|
76 |
+ } |
|
77 |
+ |
|
78 |
+ my $user = app->dbi->model('user')->select( |
|
79 |
+ where => {id => $user_id, admin => 0} |
|
80 |
+ )->one; |
|
81 |
+%> |
|
82 |
+ |
|
83 |
+% layout 'common', title => 'Update User'; |
|
84 |
+ |
|
85 |
+ %= include '/include/header'; |
|
86 |
+ |
|
87 |
+ <div class="container"> |
|
88 |
+ % my $id = ''; |
|
89 |
+ % if (flash('success')) { |
|
90 |
+ <div class="alert alert-success"> |
|
91 |
+ <button type="button" class="close" data-dismiss="alert">×</button> |
|
92 |
+ Success: User <b><%= flash('id') %></b> is updated. |
|
93 |
+ </div> |
|
94 |
+ % } |
|
95 |
+ |
|
96 |
+ % if ($errors) { |
|
97 |
+ <div class="alert alert-error"> |
|
98 |
+ <button type="button" class="close" data-dismiss="alert">×</button> |
|
99 |
+ % for my $error (@$errors) { |
|
100 |
+ <p><%= $error %></p> |
|
101 |
+ % } |
|
102 |
+ </div> |
|
103 |
+ % } |
|
104 |
+ |
|
105 |
+ <div class="topic1" style="text-align:center">Update User</div> |
|
106 |
+ <form class="user-form" action="<%= url_for->query(id => $user_id) %>" method="post"> |
|
107 |
+ %= hidden_field op => 'update'; |
|
108 |
+ <div class="user-form-container"> |
|
109 |
+ <div> |
|
110 |
+ <div><b>ID</b></div> |
|
111 |
+ <div> |
|
112 |
+ <%= $user->{id} %> |
|
113 |
+ </div> |
|
114 |
+ </div> |
|
115 |
+ <div> |
|
116 |
+ <div><b>Name</b></div> |
|
117 |
+ <div> |
|
118 |
+ <%= text_field 'name' => $user->{name}, placeholder => 'Name' %> |
|
119 |
+ </div> |
|
120 |
+ </div> |
|
121 |
+ <div> |
|
122 |
+ <div><b>Mail</b></div> |
|
123 |
+ <div> |
|
124 |
+ <%= text_field 'mail' => $user->{mail}, placeholder => 'Mail' %> |
|
125 |
+ </div> |
|
126 |
+ </div> |
|
127 |
+ <div> |
|
128 |
+ <div> |
|
129 |
+ <button type="submit" class="btn btn-success" style="margin-top:20px">Update User</button> |
|
130 |
+ </div> |
|
131 |
+ </div> |
|
132 |
+ </div> |
|
133 |
+ </form> |
|
134 |
+ <div style="text-align:center;margin:20px 0"><big><a href="<%= url_for('/_admin/users') %>">Users</a></big></div> |
|
135 |
+ </div> |
|
136 |
+ %= include '/include/footer'; |
... | ... |
@@ -114,10 +114,11 @@ |
114 | 114 |
<%= $user->{mail} %> |
115 | 115 |
</td> |
116 | 116 |
<td> |
117 |
- <a class="btn btn-mini" href="<%= url_for('/reset-password')->query(user => $uid) %>">Reset Password</a> |
|
117 |
+ <a class="btn btn-small" href="<%= url_for('/_admin/user/update')->query(id => $uid) %>">Settings</a> |
|
118 |
+ <a class="btn btn-small" href="<%= url_for('/reset-password')->query(user => $uid) %>">Reset Password</a> |
|
118 | 119 |
<form action="<%= url_for->query(op => 'delete') %>" method="post"> |
119 | 120 |
%= hidden_field user => $uid; |
120 |
- <input type="submit" class="btn btn-mini delete-btn" user="<%= $uid %>" value="Delete"> |
|
121 |
+ <input type="submit" class="btn btn-small delete-btn" style="color:red" user="<%= $uid %>" value="Delete"> |
|
121 | 122 |
</form> |
122 | 123 |
</td> |
123 | 124 |
</tr> |
... | ... |
@@ -104,15 +104,15 @@ note 'Admin pages'; |
104 | 104 |
|
105 | 105 |
# User name is empty |
106 | 106 |
$t->post_ok('/_admin/user/create?op=create', form => {id => ''}); |
107 |
- $t->content_like(qr/User name is empty/); |
|
107 |
+ $t->content_like(qr/User id is empty/); |
|
108 | 108 |
|
109 | 109 |
# User name contain invalid character |
110 | 110 |
$t->post_ok('/_admin/user/create?op=create', form => {id => '&'}); |
111 |
- $t->content_like(qr/User name contain invalid character/); |
|
111 |
+ $t->content_like(qr/User id contain invalid character/); |
|
112 | 112 |
|
113 | 113 |
# User name is too long |
114 | 114 |
$t->post_ok('/_admin/user/create?op=create', form => {id => 'a' x 21}); |
115 |
- $t->content_like(qr/User name is too long/); |
|
115 |
+ $t->content_like(qr/User id is too long/); |
|
116 | 116 |
|
117 | 117 |
# Password is empty |
118 | 118 |
$t->post_ok('/_admin/user/create?op=create', form => {id => 'a', password => ''}); |