added user management featur...
|
1 |
<% |
cleanup many pages
|
2 |
my $api = gitprep_api; |
added user management featur...
|
3 |
|
4 |
my $op = param('op') || ''; |
|
5 |
|
|
6 |
my $errors; |
|
7 |
if ($op eq 'create') { |
|
cleanup create user validati...
|
8 |
|
9 |
# Parameters |
|
10 |
my $id = param('id'); |
|
add name and mail column to ...
|
11 |
my $name = param('name'); |
fix user create and update b...
|
12 |
my $email = param('email'); |
cleanup create user validati...
|
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
|
24 |
$validation->add_failed(id => 'User id is empty.'); |
cleanup create user validati...
|
25 |
} |
26 |
elsif (!$vc->check($id, 'user_name')) { |
|
add user update page
|
27 |
$validation->add_failed(id => 'User id contain invalid character.'); |
cleanup create user validati...
|
28 |
} |
29 |
elsif (length $id > 20) { |
|
add user update page
|
30 |
$validation->add_failed(id => 'User id is too long.'); |
cleanup create user validati...
|
31 |
} |
32 |
else { |
|
33 |
my $row = app->dbi->model('user')->select(where => {id => $id})->one; |
|
34 |
if ($row) { |
|
add user update page
|
35 |
$validation->add_failed(id => "User id $id already exists"); |
cleanup create user validati...
|
36 |
} |
37 |
} |
|
added user management featur...
|
38 |
|
add name and mail column to ...
|
39 |
# "name" check |
40 |
$name //= ''; |
|
41 |
|
|
fix user create and update b...
|
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 ...
|
45 |
} |
fix user create and update b...
|
46 |
elsif ($email !~ /\@/) { |
47 |
$validation->add_failed(email => "Invalid mail address"); |
|
add name and mail column to ...
|
48 |
} |
49 |
else { |
|
fix user create and update b...
|
50 |
my $row = app->dbi->model('user')->select(where => {email => $email})->one; |
add name and mail column to ...
|
51 |
if ($row) { |
fix user create and update b...
|
52 |
$validation->add_failed(email => "Mail $email already exists"); |
add name and mail column to ...
|
53 |
} |
54 |
} |
|
55 |
|
|
cleanup create user validati...
|
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...
|
67 |
|
cleanup create user validati...
|
68 |
if ($validation->is_valid) { |
added user management featur...
|
69 |
|
cleanup create user validati...
|
70 |
# Encrypt password |
71 |
my ($password_encrypted, $salt) = $api->encrypt_password($password); |
|
72 |
my $params = {}; |
|
improved password encrypt sy...
|
73 |
$params->{password} = $password_encrypted; |
74 |
$params->{salt} = $salt; |
|
add name and mail column to ...
|
75 |
$params->{name} = $name; |
fix user create and update b...
|
76 |
$params->{email} = $email; |
improved password encrypt sy...
|
77 |
|
78 |
# Create user |
|
revert encoding support
|
79 |
eval { app->manager->create_user($id, $params) }; |
improve error message
|
80 |
if (my $e = $@) { |
81 |
app->log->error(url_for . ": $e"); |
|
added create user directory ...
|
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...
|
89 |
} |
cleanup create user validati...
|
90 |
else { $errors = $validation->messages } |
added user management featur...
|
91 |
} |
92 |
%> |
|
93 | ||
add title
|
94 |
% layout 'common', title => 'Create User'; |
added user management featur...
|
95 | |
improved create user page de...
|
96 |
%= include '/include/header'; |
added user management featur...
|
97 | |
cleanup many pages
|
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">×</button> |
|
103 |
Success: User <b><%= flash('id') %></b> is created. |
|
104 |
</div> |
|
105 |
% } |
|
added create user directory ...
|
106 |
|
107 |
% if ($errors) { |
|
added branch deleting featur...
|
108 |
<div class="alert alert-error"> |
added create user directory ...
|
109 |
<button type="button" class="close" data-dismiss="alert">×</button> |
110 |
% for my $error (@$errors) { |
|
111 |
<p><%= $error %></p> |
|
112 |
% } |
|
113 |
</div> |
|
114 |
% } |
|
115 |
|
|
improve admin page design
|
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 ...
|
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
|
133 |
<div> |
fix user create and update b...
|
134 |
<%= text_field 'email', placeholder => 'Mail' %> |
added user management featur...
|
135 |
</div> |
improved create user page de...
|
136 |
</div> |
improve admin page design
|
137 |
<div> |
138 |
<div>Password</div> |
|
139 |
<div> |
|
improved create user page de...
|
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
|
144 |
<div> |
145 |
<div> |
|
rename btn-success to btn-gr...
|
146 |
<button type="submit" class="btn btn-green" style="margin-top:20px">Create User</button> |
added user management featur...
|
147 |
</div> |
148 |
</div> |
|
improve admin page design
|
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...
|
152 |
</div> |
cleanup many pages
|
153 |
%= include '/include/footer'; |