-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Unsubscribe from emails * Unsubscribe from emails * Rephrase message
- Loading branch information
Showing
10 changed files
with
204 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Server.Database.UnsubscribeTokens where | ||
|
||
import Droplet.Language | ||
import Prelude | ||
import Prim hiding (Constraint) | ||
import Data.Tuple.Nested (type (/\)) | ||
|
||
import Server.Database.Users (UsersTable) | ||
import Type.Proxy (Proxy(..)) | ||
|
||
type UnsubscribeTokens = | ||
( id ∷ Column Int (PrimaryKey /\ Identity) | ||
, contents ∷ String | ||
, unsubscriber ∷ Column Int (Constraint "unsubcribe_tokens_user" (ForeignKey "id" UsersTable)) | ||
) | ||
|
||
unsubscribeTokens ∷ Table "unsubscribe_tokens" UnsubscribeTokens | ||
unsubscribeTokens = Table | ||
|
||
_unsubscriber ∷ Proxy "unsubscriber" | ||
_unsubscriber = Proxy |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
module Server.Unsubscribe.Action where | ||
|
||
import Debug | ||
import Prelude | ||
import Shared.Im.Types | ||
import Shared.Privilege | ||
|
||
import Data.Array as DA | ||
import Data.Array.NonEmpty as DAN | ||
import Data.Either (Either(..)) | ||
import Data.Maybe (Maybe(..)) | ||
import Data.Maybe as DM | ||
import Data.Nullable as DN | ||
import Data.Set (Set) | ||
import Data.Set as DST | ||
import Data.String as DS | ||
import Data.Tuple (Tuple(..)) | ||
import Droplet.Driver (Pool) | ||
import Run.Except as RE | ||
import Server.AccountValidation as SA | ||
import Server.Effect (BaseEffect, Configuration, ServerEffect) | ||
import Server.Email as SE | ||
import Server.File as SF | ||
import Environment (production) | ||
import Server.Im.Database as SID | ||
import Server.Im.Database.Flat (FlatContactHistoryMessage, fromFlatContact, fromFlatMessage) | ||
import Server.Im.Database.Flat as SIF | ||
import Server.Im.Types (Payload) | ||
import Server.Sanitize as SS | ||
import Server.ThreeK as ST | ||
import Server.Wheel as SW | ||
import Shared.Markdown (Token(..)) | ||
import Shared.Markdown as SM | ||
import Shared.Resource (Media(..), ResourceType(..)) | ||
import Shared.Resource as SP | ||
import Shared.ResponseError (ResponseError(..)) | ||
import Server.Unsubscribe.Database as SUD | ||
|
||
unsubscribe ∷ String → ServerEffect Boolean | ||
unsubscribe token = do | ||
maybeId ← SUD.fetchUnsubscriber token | ||
case maybeId of | ||
Nothing → pure false | ||
Just id → do | ||
SUD.unsubscribe id | ||
pure true |
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,22 @@ | ||
module Server.Unsubscribe.Database where | ||
|
||
import Droplet.Language | ||
import Prelude hiding (not, join) | ||
import Server.Database.UnsubscribeTokens | ||
import Server.Database.Users | ||
|
||
import Data.Maybe (Maybe) | ||
import Server.Database as SD | ||
import Server.Database.Fields (_contents, _id) | ||
import Server.Effect (ServerEffect) | ||
import Shared.User (ReceiveEmail(..)) | ||
|
||
fetchUnsubscriber ∷ String → ServerEffect (Maybe Int) | ||
fetchUnsubscriber token = do | ||
row ← SD.single $ select _unsubscriber # from unsubscribeTokens # wher (_contents .=. token) | ||
pure $ map _.unsubscriber row | ||
|
||
unsubscribe ∷ Int → ServerEffect Unit | ||
unsubscribe id = do | ||
SD.execute $ update users # set (_receiveEmail .=. NoEmails) # wher (_id .=. id) | ||
SD.execute $ delete # from unsubscribeTokens # wher (_unsubscriber .=. id) |
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,15 @@ | ||
module Server.Unsubscribe.Handler where | ||
|
||
import Prelude | ||
import Server.Effect (ServerEffect) | ||
|
||
import Server.NotFound.Template as SUN | ||
import Server.Response as SR | ||
import Server.Unsubscribe.Action as SUA | ||
import Server.Unsubscribe.Template as SUT | ||
import Shared.Html (Html) | ||
|
||
unsubscribe ∷ { query ∷ { emailId ∷ String } } → ServerEffect Html | ||
unsubscribe { query: { emailId } } = do | ||
unsubbed ← SUA.unsubscribe emailId | ||
SR.serveTemplate $ if unsubbed then SUT.template else SUN.template |
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,25 @@ | ||
module Server.Unsubscribe.Template where | ||
|
||
import Prelude | ||
|
||
import Effect (Effect) | ||
import Flame.Html.Attribute as HA | ||
import Flame.Html.Element as HE | ||
import Flame.Renderer.String as FRS | ||
import Server.Template (externalDefaultParameters) | ||
import Server.Template as ST | ||
|
||
template ∷ Effect String | ||
template = do | ||
contents ← ST.template externalDefaultParameters | ||
{ content = externalDefaultParameters.content <> content | ||
, title = "MeroChat - Unsubscribe from Emails" | ||
} | ||
FRS.render contents | ||
where | ||
content = | ||
[ HE.div (HA.class' "green-area green-box") | ||
[ HE.h2 (HA.class' "ext-heading") "Email unsubscribed" | ||
, HE.p_ "You have been unsubscribed. If you wish to subscribe again, log in and modify your emails settings" | ||
] | ||
] |
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