-
Notifications
You must be signed in to change notification settings - Fork 0
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 #17 from dwyl/send-email-issue#41
Send Email
- Loading branch information
Showing
13 changed files
with
86 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
# AuthMvp | ||
# Auth MVP | ||
|
||
[![Build Status](https://img.shields.io/travis/dwyl/auth-mvp/master.svg?style=flat-square)](https://travis-ci.org/dwyl/auth-mvp) | ||
[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/auth-mvp/master.svg?style=flat-square)](http://codecov.io/github/dwyl/auth-mvp?branch=master) | ||
|
||
DWYL Authentication service | ||
|
||
## API | ||
|
||
- `/auth/urls`: returns list of oauth applications' url. | ||
|
||
## Sending Emails From Auth App Requires | ||
|
||
The only requirement that you need to fulfil | ||
in order to enable sending emails | ||
is having the `EMAIL_APP_URL` set in your `.env` | ||
and the `SECRET_KEY_BASE` environment variable needs to be the _same_ | ||
as the `dwylmail` Heroku app. | ||
|
||
Visit: https://dashboard.heroku.com/apps/dwylmail/settings | ||
and copy the `SECRET_KEY_BASE` from Config Vars. |
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
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,34 @@ | ||
defmodule AuthMvp.Email do | ||
|
||
@doc """ | ||
`sendemail/1` sends an email using AWS SES. | ||
see: https://github.com/dwyl/email#sending-email | ||
params is a map that *must* contain the keys: email, name and template. | ||
## Examples | ||
iex> sendemail(%{"email" => "[email protected]", "name" => "Al", "template" => "hi"}) | ||
%{ | ||
"aud" => "Joken", | ||
"email" => "[email protected]", | ||
"exp" => 1616864371, | ||
"iat" => 1585327371, | ||
"id" => 33, | ||
"iss" => "Joken", | ||
"jti" => "2o03dm2ktf6f1j74es0001e3", | ||
"name" => "Al", | ||
"nbf" => 1585327371, | ||
"status" => "Pending", | ||
"template" => "hi" | ||
} | ||
""" | ||
|
||
def sendemail(params) do | ||
url = System.get_env("EMAIL_APP_URL") <> "/api/send" | ||
jwt = AuthMvp.Token.generate_and_sign!(params) | ||
headers = ["Authorization": "#{jwt}"] | ||
options = [ssl: [{:versions, [:'tlsv1.2']}], recv_timeout: 10000] | ||
{:ok, response} = HTTPoison.post(url, "_nobody", headers, options) | ||
Jason.decode!(response.body) | ||
end | ||
end |
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,17 @@ | ||
defmodule AuthMvp.EmailTest do | ||
use ExUnit.Case | ||
|
||
describe "AuthMvp.Email" do | ||
test "sendemail/1 an email" do | ||
params = %{ | ||
"email" => "[email protected]", | ||
"name" => "Super Successful", | ||
"template" => "welcome" | ||
} | ||
# IO.inspect(params, label: "params") | ||
res = AuthMvp.Email.sendemail(params) | ||
assert Map.get(params, "email") == Map.get(res, "email") | ||
assert Map.get(res, "id") > 0 | ||
end | ||
end | ||
end |
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