This repository has been archived by the owner on Nov 19, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #609 from duckduckgo/cmpn-mail
Allow non-account email for /wear updates
- Loading branch information
Showing
8 changed files
with
172 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,9 +8,10 @@ use DDGC::Config; | |
use Try::Tiny; | ||
use DateTime; | ||
use DateTime::Duration; | ||
use Email::Valid; | ||
use Lingua::Identify qw(:language_identification); | ||
|
||
sub base :Chained('/') :PathPart('campaign') :CaptureArgs(0) { | ||
sub base :Chained('/base') :PathPart('campaign') :CaptureArgs(0) { | ||
my ( $self, $c ) = @_; | ||
if (!$c->user) { | ||
$c->response->status(403); | ||
|
@@ -19,7 +20,7 @@ sub base :Chained('/') :PathPart('campaign') :CaptureArgs(0) { | |
return $c->detach; | ||
} | ||
elsif (!$c->req->param('campaign_name')) { | ||
$c->response->status(500); | ||
$c->response->status(403); | ||
$c->stash->{x} = { | ||
ok => 0, no_campaign => 1, | ||
errstr => "No campaign info supplied!" | ||
|
@@ -49,7 +50,7 @@ sub base :Chained('/') :PathPart('campaign') :CaptureArgs(0) { | |
|
||
sub respond : Chained('base') : PathPart('respond') : Args(0) { | ||
my ( $self, $c ) = @_; | ||
#$c->require_action_token; | ||
$c->require_action_token; | ||
|
||
my $to = $c->d->config->share_email // '[email protected]'; | ||
my $from = '[email protected]'; | ||
|
@@ -80,7 +81,7 @@ sub respond : Chained('base') : PathPart('respond') : Args(0) { | |
} | ||
|
||
if ($short_response) { | ||
$c->response->status(500); | ||
$c->response->status(403); | ||
$c->stash->{x} = { | ||
ok => 0, fields_empty => 1, | ||
errstr => "Your responses are too short. Please add more explanation.", | ||
|
@@ -89,6 +90,51 @@ sub respond : Chained('base') : PathPart('respond') : Args(0) { | |
return $c->detach; | ||
} | ||
|
||
if ($c->req->param('question4')) { | ||
$c->stash->{campaign_email} = Email::Valid->address($c->req->param('question4')); | ||
if (!$c->stash->{campaign_email}) { | ||
$c->response->status(403); | ||
$c->stash->{x} = { | ||
ok => 0, invalid_email => 1, | ||
errstr => "This email address appears to be invalid.", | ||
}; | ||
$c->forward( $c->view('JSON') ); | ||
return $c->detach; | ||
} | ||
|
||
if (lc($c->stash->{campaign_email}) eq lc($c->user->email)) { | ||
$c->stash->{campaign_email_is_account_email} = 1; | ||
} | ||
else { | ||
my $data = $c->user->data || {}; | ||
$data->{wear_email_verify_token} = $c->d->uid; | ||
$c->user->update({ data => $data }); | ||
$c->stash->{wear_email_verify_link} = | ||
$c->chained_uri('My','wear_email_verify',$c->user->lowercase_username,$data->{wear_email_verify_token}); | ||
my $error = 0; | ||
try { | ||
$c->d->postman->template_mail( | ||
1, $c->stash->{campaign_email}, $from, | ||
'[DuckDuckGo Community] Thank you for participating in Share it + Wear it', | ||
'wearemail',$c->stash); | ||
} | ||
catch { | ||
$error = 1; | ||
}; | ||
|
||
if ($error) { | ||
$c->response->status(500); | ||
$c->stash->{x} = { | ||
ok => 0, mailer_error => 1, | ||
errstr => "Sorry, there was a problem submitting your response. Please try again later." | ||
}; | ||
$c->forward( $c->view('JSON') ); | ||
return $c->detach; | ||
} | ||
|
||
} | ||
} | ||
|
||
my $subject_extra = ''; | ||
if ($campaign_name eq 'share') { | ||
($language ne "en" || $confidence < 0.57) && ($subject_extra = '** POSSIBLE SPAM ** '); | ||
|
@@ -123,7 +169,11 @@ BAD_RESPONSE_LINK | |
return $c->detach; | ||
} | ||
|
||
$c->user->set_responded_campaign($campaign_name); | ||
my $response = $c->user->set_responded_campaign($campaign_name); | ||
$response->update( ($c->stash->{campaign_email_is_account_email}) ? | ||
{ campaign_email_is_account_email => 1 } : | ||
{ campaign_email => $c->stash->{campaign_email} } | ||
); | ||
|
||
my $return_on; | ||
my $coupon; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
-- Convert schema 'DDGC::DBOld v1.x' to 'DDGC::DB v1.x':; | ||
|
||
BEGIN; | ||
|
||
ALTER TABLE user_campaign_notice ADD COLUMN campaign_email_is_account_email bigint DEFAULT 0 NOT NULL; | ||
|
||
ALTER TABLE user_campaign_notice ADD COLUMN campaign_email text; | ||
|
||
ALTER TABLE user_campaign_notice ADD COLUMN campaign_email_verified smallint DEFAULT 0 NOT NULL; | ||
|
||
COMMIT; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
<: include "email/heading.tx" { title => "Verify your email address" } :> | ||
<tr> | ||
<td width="10"></td> | ||
<td align="center" colspan="2"> | ||
<table cellpadding="0" cellspacing="5" border="0" bgcolor="#fff" <: style("msg_content") :>> | ||
<tr> | ||
<td colspan="2" valign="middle"> | ||
<h4 <: style("default") :>>Please click on the following link to verify your email address</h4> | ||
<p <: style("default") :>><a href="<: $wear_email_verify_link :>">Yes, I signed up for Share it + Wear it with this address</a></p> | ||
<p <: style("sub_text") :>>Regards, <br/><i <: style("signoff") :>>The DuckDuckGo Community team.</i></p> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
<td width="10"></td> | ||
</tr> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<: if $invalid_token { :> | ||
<div class="notice error"> | ||
<i class="icn icon-warning-sign"></i> | ||
This token is invalid. | ||
</div> | ||
<: } else { :> | ||
<div class="notice success"> | ||
<i class="icn icon-ok"></i> | ||
You have successfully confirmed your email. Thank you. | ||
</div> | ||
<: } :> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters