Added quota to form

This commit is contained in:
ziggi
2017-12-14 23:36:44 +02:00
parent 86f031a9b9
commit b5caee2df4
4 changed files with 16 additions and 8 deletions

View File

@@ -467,10 +467,11 @@ sub user_nextid {
} }
sub user_add { sub user_add {
my ($self, $name, $password, $domain_id) = @_; my ($self, $name, $password, $domain_id, $quota) = @_;
return undef unless $name; return undef unless $name;
return undef unless $password; return undef unless $password;
return undef unless $domain_id; return undef unless $domain_id;
$quota ||= 1024*1024*1024*10;
return undef if $self->user_exist($name, $domain_id); return undef if $self->user_exist($name, $domain_id);
return undef unless $self->domain_profile($domain_id); return undef unless $self->domain_profile($domain_id);
@@ -478,8 +479,8 @@ sub user_add {
my $salt = substr(sha512_base64(sprintf("%X", rand(2**31-1))), 4, 16); my $salt = substr(sha512_base64(sprintf("%X", rand(2**31-1))), 4, 16);
my $hash = crypt($password,'$6$'.$salt.'$'); my $hash = crypt($password,'$6$'.$salt.'$');
$self->db->do("insert into users (id, name, password, domain_id, hash) $self->db->do("insert into users (id, name, password, domain_id, hash, $quota)
values ($next_id, '$name', '$password', $domain_id, '$hash')"); values ($next_id, '$name', '$password', $domain_id, '$hash', $quota)");
$self->user_exist($name, $domain_id); $self->user_exist($name, $domain_id);
} }
@@ -1340,9 +1341,7 @@ $app->log(Mojo::Log->new(
my $user = $app->config('user'); my $user = $app->config('user');
my $group = $app->config('group'); my $group = $app->config('group');
my $d = Daemon->new($user, $group); my $d = Daemon->new($user, $group);
$d->fork; #$d->fork;
$app->hook(before_dispatch => sub { $app->hook(before_dispatch => sub {
my $c = shift; my $c = shift;

View File

@@ -12,7 +12,7 @@ CREATE TABLE users (
password text, password text,
hash text, hash text,
size int DEFAULT 0, size int DEFAULT 0,
quota int DEFAULT 0 quota int DEFAULT 10737418240
); );
CREATE TABLE aliases ( CREATE TABLE aliases (
id int unique NOT NULL PRIMARY KEY, id int unique NOT NULL PRIMARY KEY,

View File

@@ -13,6 +13,7 @@
% if ($domain_id) { % if ($domain_id) {
% my $profile = $u->domain_profile($domain_id); % my $profile = $u->domain_profile($domain_id);
% my $domain_name = $profile->{name}; % my $domain_name = $profile->{name};
% my $quota = 1024*1024*1024*10;
<div class="grid-container"> <div class="grid-container">
<div class="grid-x grid-padding-x"> <div class="grid-x grid-padding-x">
<div class="medium-6 medium-centered cell"> <div class="medium-6 medium-centered cell">
@@ -28,6 +29,12 @@
<input type="text" name="password" placeholder="xxxxxxxxx" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{5,42}"/> <input type="text" name="password" placeholder="xxxxxxxxx" required pattern="[_.-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]{5,42}"/>
<span class="form-error">Mandatory, 6 or more letter</span> <span class="form-error">Mandatory, 6 or more letter</span>
</label> </label>
<label>Quota
<input type="number" name="quota" value="<%= $quota %>" required pattern="[0-9]{1,15}"/>
<span class="form-error">Mandatory, one or more ciphers</span>
</label>
<div class="text-center"> <div class="text-center">
<button type="submit" class="button">Accept</button> <button type="submit" class="button">Accept</button>
<a class="button" href="/user/list?domain_id=<%= $domain_id %>">Escape</a> <a class="button" href="/user/list?domain_id=<%= $domain_id %>">Escape</a>

View File

@@ -11,6 +11,8 @@
% my $user_name = $c->req->param('user_name'); % my $user_name = $c->req->param('user_name');
% my $domain_id = $c->req->param('domain_id'); % my $domain_id = $c->req->param('domain_id');
% my $password = $c->req->param('password'); % my $password = $c->req->param('password');
% my $quota = $c->req->param('quota');
% my $cid = $u->user_exist($user_name, $domain_id); % my $cid = $u->user_exist($user_name, $domain_id);
@@ -19,7 +21,7 @@
% } % }
% unless ($cid) { % unless ($cid) {
% my $id = $u->user_add($user_name, $password, $domain_id); % my $id = $u->user_add($user_name, $password, $domain_id, $quota);
% if ($id) { % if ($id) {
<div class="callout success">User <%= $user_name %> has been added.</div> <div class="callout success">User <%= $user_name %> has been added.</div>
% } % }