From 7e0647746057224c2654362b79a3dbb889a96cc0 Mon Sep 17 00:00:00 2001 From: ziggi Date: Fri, 12 Jan 2018 21:39:05 +0200 Subject: [PATCH] Added gecos field to user profile --- maacom.pl | 12 ++++++++---- schema.sql | 2 ++ templs/alias-add-form.html.ep | 8 ++++---- templs/alias-rename-form.html.ep | 2 +- templs/domain-add-form.html.ep | 2 +- templs/domain-rename-form.html.ep | 2 +- templs/forwarded-add-form.html.ep | 2 +- templs/forwarded-update-form.html.ep | 2 +- templs/trusted-add-form.html.ep | 2 +- templs/trusted-update-form.html.ep | 2 +- templs/unwanted-add-form.html.ep | 2 +- templs/unwanted-update-form.html.ep | 2 +- templs/user-add-form.html.ep | 13 +++++++++---- templs/user-add-handler.html.ep | 3 ++- templs/user-list.html.ep | 6 ++++++ templs/user-rename-form.html.ep | 2 +- templs/user-update-form.html.ep | 6 +++++- templs/user-update-handler.html.ep | 3 ++- 18 files changed, 48 insertions(+), 25 deletions(-) diff --git a/maacom.pl b/maacom.pl index 35b7a39..fe04270 100755 --- a/maacom.pl +++ b/maacom.pl @@ -434,6 +434,7 @@ sub user_profile { return undef unless $id; $self->db->exec1("select u.id as id, u.name as name, + u.gecos as gecos, u.name || '\@' || d.name as address, u.domain_id as domain_id, d.name as domain_name, @@ -451,6 +452,7 @@ sub user_list { my $and = "and u.domain_id = $domain_id" if $domain_id; $self->db->exec("select u.id as id, u.name as name, + u.gecos as gecos, u.name || '\@' || d.name as address, u.domain_id as domain_id, d.name as domain_name, @@ -471,20 +473,20 @@ sub user_nextid { } sub user_add { - my ($self, $name, $password, $domain_id, $quota) = @_; + my ($self, $name, $gecos, $password, $domain_id, $quota) = @_; return undef unless $name; return undef unless $password; return undef unless $domain_id; $quota ||= 1024*10; - + $gecos ||= ''; return undef if $self->user_exist($name, $domain_id); return undef unless $self->domain_profile($domain_id); my $next_id = $self->user_nextid; my $salt = substr(sha512_base64(sprintf("%X", rand(2**31-1))), 4, 16); my $hash = crypt($password,'$6$'.$salt.'$'); - $self->db->do("insert into users (id, name, password, domain_id, hash, quota) - values ($next_id, '$name', '$password', $domain_id, '$hash', $quota)"); + $self->db->do("insert into users (id, name, gecos, password, domain_id, hash, quota) + values ($next_id, '$name', '$gecos', '$password', $domain_id, '$hash', $quota)"); $self->user_exist($name, $domain_id); } @@ -494,6 +496,7 @@ sub user_update { return undef unless $prof; my $name = $args{name} || $prof->{name}; + my $gecos = $args{gecos} || $prof->{gecos}; my $password = $args{password} || $prof->{password}; my $hash = $prof->{hash}; if ($args{password}) { @@ -507,6 +510,7 @@ sub user_update { $size ||= 0; $self->db->do("update users set name = '$name', + gecos = '$gecos', password = '$password', size = $size, quota = $quota, diff --git a/schema.sql b/schema.sql index d5c2452..19cde93 100644 --- a/schema.sql +++ b/schema.sql @@ -5,9 +5,11 @@ CREATE TABLE domains ( size int DEFAULT 0, quota int DEFAULT 1048576 ); +DROP TABLE IF EXISTS users; CREATE TABLE users ( id int unique NOT NULL PRIMARY KEY, name text, + gecos text, domain_id int, password text, hash text, diff --git a/templs/alias-add-form.html.ep b/templs/alias-add-form.html.ep index 2696502..b962cdb 100644 --- a/templs/alias-add-form.html.ep +++ b/templs/alias-add-form.html.ep @@ -21,11 +21,11 @@
Add alias to domain <%= $domain_name %>
@@ -47,7 +47,7 @@
Add alias
diff --git a/templs/alias-rename-form.html.ep b/templs/alias-rename-form.html.ep index 059ddfc..587630c 100644 --- a/templs/alias-rename-form.html.ep +++ b/templs/alias-rename-form.html.ep @@ -26,7 +26,7 @@
Edit alias <%= $address %>
diff --git a/templs/domain-add-form.html.ep b/templs/domain-add-form.html.ep index 09939a2..87d0e5b 100644 --- a/templs/domain-add-form.html.ep +++ b/templs/domain-add-form.html.ep @@ -16,7 +16,7 @@
Add domain
diff --git a/templs/domain-rename-form.html.ep b/templs/domain-rename-form.html.ep index c4034ba..c4ed467 100644 --- a/templs/domain-rename-form.html.ep +++ b/templs/domain-rename-form.html.ep @@ -22,7 +22,7 @@
Edit domain
diff --git a/templs/forwarded-add-form.html.ep b/templs/forwarded-add-form.html.ep index 5c41a8e..b443344 100644 --- a/templs/forwarded-add-form.html.ep +++ b/templs/forwarded-add-form.html.ep @@ -15,7 +15,7 @@
Add forwardeded domain
diff --git a/templs/forwarded-update-form.html.ep b/templs/forwarded-update-form.html.ep index ef97fbd..880d28d 100644 --- a/templs/forwarded-update-form.html.ep +++ b/templs/forwarded-update-form.html.ep @@ -22,7 +22,7 @@
Edit domain
diff --git a/templs/trusted-add-form.html.ep b/templs/trusted-add-form.html.ep index 7335f5d..cb3ff7a 100644 --- a/templs/trusted-add-form.html.ep +++ b/templs/trusted-add-form.html.ep @@ -15,7 +15,7 @@
Add trusted host
diff --git a/templs/trusted-update-form.html.ep b/templs/trusted-update-form.html.ep index dcb9409..054d75f 100644 --- a/templs/trusted-update-form.html.ep +++ b/templs/trusted-update-form.html.ep @@ -22,7 +22,7 @@
Edit host
diff --git a/templs/unwanted-add-form.html.ep b/templs/unwanted-add-form.html.ep index e7dbd3b..86c3ddb 100644 --- a/templs/unwanted-add-form.html.ep +++ b/templs/unwanted-add-form.html.ep @@ -15,7 +15,7 @@
Add unwanted host
diff --git a/templs/unwanted-update-form.html.ep b/templs/unwanted-update-form.html.ep index bcff529..115b3f9 100644 --- a/templs/unwanted-update-form.html.ep +++ b/templs/unwanted-update-form.html.ep @@ -22,7 +22,7 @@
Edit host
diff --git a/templs/user-add-form.html.ep b/templs/user-add-form.html.ep index 37d050b..15bf61d 100644 --- a/templs/user-add-form.html.ep +++ b/templs/user-add-form.html.ep @@ -22,11 +22,16 @@
Add user to domain <%= $domain_name %>
+ + + @@ -54,11 +59,11 @@
Add user
diff --git a/templs/user-add-handler.html.ep b/templs/user-add-handler.html.ep index 6718bcb..bea46f0 100644 --- a/templs/user-add-handler.html.ep +++ b/templs/user-add-handler.html.ep @@ -10,6 +10,7 @@ % my $user_name = $c->req->param('user_name'); % my $domain_id = $c->req->param('domain_id'); +% my $gecos = $c->req->param('gecos'); % my $password = $c->req->param('password'); % my $quota = $c->req->param('quota'); @@ -21,7 +22,7 @@ % } % unless ($cid) { - % my $id = $u->user_add($user_name, $password, $domain_id, $quota); + % my $id = $u->user_add($user_name, $gecos, $password, $domain_id, $quota); % if ($id) {
User <%= $user_name %> has been added.
% } diff --git a/templs/user-list.html.ep b/templs/user-list.html.ep index f58ae90..67b9c73 100644 --- a/templs/user-list.html.ep +++ b/templs/user-list.html.ep @@ -27,6 +27,7 @@ # address + @@ -40,6 +41,7 @@ % foreach my $row (@$list) { % $n += 1; % my $address = $row->{address}; + % my $gecos = $row->{gecos}; % my $user_id = $row->{id}; % my $domain_id = $row->{domain_id}; % my $size = $row->{size} || 0; @@ -47,6 +49,7 @@ <%= $n %> <%= $address %> + <%= $gecos %> <%= $size %> <%= $quota %> @@ -74,6 +77,7 @@ # address + @@ -88,6 +92,7 @@ % foreach my $row (@$list) { % $n += 1; % my $address = $row->{address}; + % my $gecos = $row->{gecos}; % my $user_id = $row->{id}; % my $domain_id = $row->{domain_id}; % my $size = $row->{size} || 0; @@ -95,6 +100,7 @@ <%= $n %> <%= $address %> + <%= $gecos %> <%= $size %> <%= $quota %> diff --git a/templs/user-rename-form.html.ep b/templs/user-rename-form.html.ep index 28b052c..5e239e7 100644 --- a/templs/user-rename-form.html.ep +++ b/templs/user-rename-form.html.ep @@ -26,7 +26,7 @@
Rename user <%= $address %>
diff --git a/templs/user-update-form.html.ep b/templs/user-update-form.html.ep index 724c9ff..f0a244f 100644 --- a/templs/user-update-form.html.ep +++ b/templs/user-update-form.html.ep @@ -13,6 +13,7 @@ % if ($profile) { % my $user_name = $profile->{name}; + % my $gecos = $profile->{gecos}; % my $domain_name = $profile->{domain_name}; % my $domain_id = $profile->{domain_id}; % my $password = $profile->{password}; @@ -26,8 +27,11 @@
Edit user <%= $address %>
+