3 FS::msg_template::http example server.
7 This is an incredibly crude Mojo web service for demonstrating how to talk
8 to the HTTP customer messaging interface in Freeside.
10 It implements an endpoint for the "password reset" messaging case which
11 creates a simple password reset message using some template variables,
12 and a "send" endpoint that just delivers the message by sendmail. The
13 configuration to use this as your password reset handler would be:
15 prepare_url = 'http://localhost:3000/prepare/password_reset'
16 send_url = 'http://localhost:3000/send'
17 No username, no password, no additional content.
21 use Mojolicious::Lite;
22 use Mojo::JSON qw(decode_json encode_json);
24 use Email::Simple::Creator;
25 use Email::Sender::Simple qw(sendmail);
27 post '/prepare/password_reset' => sub {
30 my $json_data = $self->req->body;
31 #print STDERR $json_data;
32 my $input = decode_json($json_data);
33 if ( $input->{username} ) {
35 'to' => $input->{invoicing_email},
36 'subject' => "Password reset for $input->{username}",
38 To complete your $input->{company_name} password reset, please go to
39 $input->{selfservice_server_base_url}/selfservice.cgi?action=process_forgot_password;session_id=$input->{session_id}
41 This link will expire in 24 hours.",
44 return $self->render( json => $output );
48 return $self->render( text => 'Username required', status => 500 );
56 my $json_data = $self->req->body;
57 my $input = decode_json($json_data);
58 my $email = Email::Simple->create(
60 From => $ENV{USER}.'@localhost',
62 Subject => $input->{subject},
64 body => $input->{body},
67 eval { sendmail($email) };
69 return $self->render( text => $@->message, status => 500 );
71 return $self->render( text => '' );