source: bearmail/lib/BearMail/Web/Address/Add.pm @ 500

Last change on this file since 500 was 500, checked in by zecrazytux, 10 years ago

Added a lock and enhanced mailmap writing mechanism

File size: 1.7 KB
Line 
1package BearMail::Web::Address::Add;
2
3# Copyright (C) 2009 Bearstech - http://bearstech.com/
4#
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18# Adress creation webui page - part of bearmail
19
20use strict;
21use base 'BearMail::Web';
22
23sub default : StartRunMode {
24    my $self = shift;
25    my $q = $self->query();
26    my $backend = $self->{b};
27
28    $q->param('email') =~ /(.*)@(.*)/; 
29    my $domain = $2;
30
31    my $email = $q->param('email');
32    my $password = $q->param('password');
33    my $target = $q->param('type');
34    if($target eq 'alias') { 
35      $target = $q->param('aliases');
36      $target =~ s/\s//;
37    }
38
39    if(grep(/^$domain$/, $backend->get_domains())) {
40      $backend->add_address($email, $password, $target) 
41        or error($self, "BAD_CONFIGURATION");
42      $backend->commit()
43        or error($self, "COMMIT");
44      return $self->redirect($self->url('address_list?domain='.$domain));
45    } else {
46      error($self, "DOMAIN_DOESNT_EXIST");
47    }
48}
49
50sub error {
51    my ($self, $error) = @_;
52    my $tmpl = $self->load_tmpl('address_new.html');
53    $tmpl->param(CURRENT_IS_ADDRESS_NEW => 1);
54    $tmpl->param("ERROR_$error" => 1);
55    return $tmpl->output;
56}
57
581;
Note: See TracBrowser for help on using the repository browser.