can download plant phenotype data in the same way as plot phenotype data
[sgn.git] / lib / SGN / Controller / Contact.pm
blob3256aec02bfc7eeb536c19fef851b613bb76dbd3
1 package SGN::Controller::Contact;
3 use Moose;
4 use namespace::autoclean;
5 use CXGN::People;
6 use Captcha::reCAPTCHA;
8 BEGIN { extends 'Catalyst::Controller' }
10 =head1 NAME
12 SGN::Controller::Contact - controller for contact page
14 =cut
16 #Creates a blank form
17 sub form :Path('/contact/form') :Args(0) {
18 my ($self, $c) = @_;
19 my ($username, $useremail) = _load_user($c);
22 $c->stash->{website_name} = $c->config->{project_name};
23 $c->stash->{contact_form_human_question} = $c->config->{contact_form_human_question};
24 $c->stash->{contact_form_human_answer_correct} = 1; # do not show warning on initial screen
25 $c->stash->{captcha_public_key} = $c->config->{captcha_public_key};
26 $c->stash->{email_address_to_display} = $useremail;
27 $c->stash->{name} = $username;
28 $c->stash->{email_address_to_display} = $c->config->{feedback_email};
30 $c->stash->{template} = '/help/contact.mas';
32 # _build_form_page($self, $c, undef, undef, undef, undef, 1, undef, undef); #, $username, $useremail, $c->config->{contact_form_human_question}, $answer, $check, $c->req->param("subject"), $c->req->param("body") );
35 #Loads the user if he has an account
36 sub _load_user {
37 my ($c) = @_;
38 my $dbh = $c->dbc->dbh;
39 my $user = $c->user_exists ? $c->user->get_object : CXGN::People::Person->new( $dbh, undef );
41 my $username = join ' ', grep defined, $user->get_first_name, $user->get_last_name;
42 my $useremail = $user->get_private_email;
44 return ($username, $useremail);
47 sub submit :Path('/contact/submit') :Args(0) {
48 my ($self, $c) = @_;
49 my ($name, $email, $subject, $body, $challenge, $response, $contact_form_human_answer) =
50 map { $c->request->param($_) } qw/name email subject body recaptcha_challenge_field recaptcha_response_field contact_form_human_answer /;
52 my $captcha = Captcha::reCAPTCHA->new;
54 my $result = $captcha->check_answer(
55 $c->config->{captcha_private_key}, $c->request->address(),
56 $challenge, $response
59 my $project = $c->config->{project_name};
61 if ($contact_form_human_answer eq $c->config->{contact_form_human_answer} and $name and $email and $subject and $body and ($result->{is_valid} || $ENV{SGN_TEST_MODE})) {
63 my $host = $c->request->hostname();
64 my $client_ip = $c->request->address();
66 $body .= <<END_HEREDOC;
68 This message sent from $project contact form
70 From:
71 $name <$email>
73 (email sent from host $host, client ip $client_ip)
75 Subject:
76 $subject
78 Body:
79 $body
83 END_HEREDOC
85 # add the client IP address so we can block abusers
89 $c->stash->{email} = {
90 to => $c->config->{contact_form_email},
91 from => $c->config->{contact_form_email},
92 subject => "[".$c->config->{name}."][contact] $subject",
93 body => $body,
96 $c->forward('View::Email');
98 $c->stash->{message} = "Thank you. Your message has been sent.";
99 $c->stash->{template} = "/generic_message.mas";
100 } else {
101 my %info_fields = (
102 name => $name,
103 email => $email,
104 subject => $subject,
105 body => $body
107 foreach my $category (keys %info_fields) {
108 $c->stash->{filled}->{$category} = $info_fields{$category};
111 $c->stash->{name} = $name;
112 $c->stash->{email} = $email;
113 $c->stash->{subject} = $subject;
114 $c->stash->{body} = $body;
115 $c->stash->{email_address_to_display} = $c->config->{feedback_email};
116 $c->stash->{website_name} = $c->config->{project_name};
117 $c->stash->{captcha_public_key} = $c->config->{captcha_public_key};
118 $c->stash->{contact_form_human_question} = $c->config->{contact_form_human_question};
119 $c->stash->{contact_form_human_answer} = $contact_form_human_answer;
120 $c->stash->{template} = '/help/contact.mas';
122 #_build_form_page($self, $c, $name, $email, $c->config->{contact_form_human_question}, $contact_form_human_answer, 0, $subject, $body);
126 __PACKAGE__->meta->make_immutable;