Commit dd1ffa2b authored by Mayel's avatar Mayel

Merge branch 'develop' into feature/transactional-email

parents 6c47223e 589cb055
......@@ -45,7 +45,7 @@ RUN npm run-script deploy
##################3
FROM deps-getter as builder
ENV HOME=/opt/app/ TERM=xterm MIX_ENV=prod
ENV HOME=/opt/app/ TERM=xterm MIX_ENV=prod APPSIGNAL_BUILD_FOR_MUSL=1
WORKDIR $HOME
......
......@@ -36,6 +36,7 @@ make dev
#### Other useful makefile tasks
- `make dev-build` - rebuild the dev docker image
- `make dev-rebuild` - `dev-build`, but without caches
- `make dev-db` - rebuild the development database
- `make dev-test-db` - rebuild the test database
- `make dev-test` - run the tests
......
.PHONY: help dev-build dev-deps dev-db dev-test-db dev-test dev-setup dev
.PHONY: help dev-exports dev-build dev-deps dev-db dev-test-db dev-test dev-setup dev
APP_NAME ?= `grep 'app:' mix.exs | sed -e 's/\[//g' -e 's/ //g' -e 's/app://' -e 's/[:,]//g'`
APP_VSN ?= `grep 'version:' mix.exs | cut -d '"' -f2`
......@@ -64,32 +64,49 @@ push_stable: ## Tag stable, latest and version tags to the last build and push
@echo docker push moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
@docker push moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
dev-exports:
awk '{print "export " $$0}' config/docker.dev.env
dev-build:
docker-compose -f docker-compose.dev.yml build web
docker-compose -p moodlenet_dev -f docker-compose.dev.yml build web
dev-rebuild:
docker-compose -p moodlenet_dev -f docker-compose.dev.yml build --no-cache web
dev-deps:
docker-compose -f docker-compose.dev.yml run web mix local.hex --force
docker-compose -f docker-compose.dev.yml run web mix local.rebar --force
docker-compose -f docker-compose.dev.yml run web mix deps.get
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix local.hex --force
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix local.rebar --force
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix deps.get
dev-db-up:
docker-compose -p moodlenet_dev -f docker-compose.dev.yml up db
dev-db:
docker-compose -f docker-compose.dev.yml run web mix ecto.reset
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix ecto.reset
dev-test-db:
docker-compose -f docker-compose.dev.yml -e MIX_ENV=test run web mix ecto.reset
docker-compose -p moodlenet_dev -f docker-compose.dev.yml -e MIX_ENV=test run web mix ecto.reset
dev-test:
docker-compose -f docker-compose.dev.yml run web mix test
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run web mix test
dev-setup: dev-deps dev-db
dev:
docker-compose -f docker-compose.dev.yml run --service-ports web
docker-compose -p moodlenet_dev -f docker-compose.dev.yml run --service-ports web
manual-deps:
mix local.hex --force
mix local.rebar --force
mix deps.get
manual-db:
mix ecto.reset
run: ## Run the app in Docker
docker run\
--env-file config/docker.env \
--expose 4000 -p 4000:4000 \
--link postgres \
--link db \
--rm -it moodlenet/moodlenet:$(APP_VSN)-$(APP_BUILD)
......@@ -82,4 +82,7 @@ config :moodle_net, MoodleNet.Repo,
hostname: System.get_env("DATABASE_HOST") || "localhost",
pool_size: 10
config :moodle_net, :ap_base_url, "http://dev.localhost:4000/activity_pub"
config :moodle_net, :ap_base_url,
(System.get_env("AP_BASE_URL") || "http://dev.localhost:4000/activity_pub")
config :moodle_net, :frontend_base_url,
(System.get_env("FRONTEND_BASE_URL") || "http://localhost:3000/")
......@@ -4,10 +4,13 @@ DATABASE_HOST=db
DATABASE_USER=postgres
DATABASE_PASS=postgres
DATABASE_NAME=moodle_net_dev
POSTGRES_DB=moodle_net_dev
PORT=4000
LANG=en_US.UTF-8
REPLACE_OS_VARS=true
ERLANG_COOKIE=moodle_net_cookie
AP_BASE_URL=http://localhost:4000/activity_pub
FRONTEND_BASE_URL=http://localhost:3000/
MAIL_DOMAIN=mailg.moodle.net
MAIL_KEY=123
\ No newline at end of file
MAIL_KEY=123
APPSIGNAL_BUILD_FOR_MUSL=1
HOSTNAME=localhost
SECRET_KEY_BASE="U1QXlca4ZEZKb1o3HL/aUlznI1qstCNAQ6yme/lFbFIs0Iqiq/annZ+Ty8JyUCDc"
DATABASE_HOST=postgres
DATABASE_HOST=db
DATABASE_USER=postgres
DATABASE_PASS=postgres
DATABASE_NAME=moodle_net_prod
POSTGRES_DB=moodle_net_prod
PORT=4000
LANG=en_US.UTF-8
REPLACE_OS_VARS=true
ERLANG_COOKIE=moodle_net_cookie
AP_BASE_URL=http://localhost:4000/activity_pub
FRONTEND_BASE_URL=http://localhost:1234/
MAIL_DOMAIN=mailg.moodle.net
#MAIL_KEY=123
\ No newline at end of file
MAIL_KEY=123
\ No newline at end of file
......@@ -29,3 +29,5 @@ config :moodle_net, MoodleNet.Mailer,
adapter: Bamboo.TestAdapter
config :moodle_net, :ap_base_url, "http://test.localhost:4001/activity_pub"
config :moodle_net, :frontend_base_url,
(System.get_env("FRONTEND_BASE_URL") || "http://localhost:3000/")
......@@ -5,6 +5,7 @@
defmodule MoodleNet.Accounts.User do
use Ecto.Schema
alias Ecto.Changeset
schema "accounts_users" do
field(:email, :string)
......@@ -20,39 +21,39 @@ defmodule MoodleNet.Accounts.User do
actor_id = ActivityPub.Entity.local_id(actor)
%__MODULE__{}
|> Ecto.Changeset.cast(attrs, [:email])
|> Ecto.Changeset.validate_format(:email, ~r/.+\@.+\..+/)
# |> Ecto.Changeset.put_assoc(:primary_actor, actor)
|> Ecto.Changeset.change(actor: actor, actor_id: actor_id)
|> Ecto.Changeset.validate_required([:actor_id, :email])
|> Ecto.Changeset.unique_constraint(:email)
|> Changeset.cast(attrs, [:email])
|> Changeset.validate_format(:email, ~r/.+\@.+\..+/)
# |> Changeset.put_assoc(:primary_actor, actor)
|> Changeset.change(actor: actor, actor_id: actor_id)
|> Changeset.validate_required([:actor_id, :email])
|> Changeset.unique_constraint(:email)
|> lower_case_email()
|> whitelist_email()
end
defp lower_case_email(%Ecto.Changeset{valid?: false} = ch), do: ch
defp lower_case_email(%Changeset{valid?: false} = ch), do: ch
defp lower_case_email(%Ecto.Changeset{} = ch) do
{_, email} = Ecto.Changeset.fetch_field(ch, :email)
Ecto.Changeset.change(ch, email: String.downcase(email))
defp lower_case_email(%Changeset{} = ch) do
{_, email} = Changeset.fetch_field(ch, :email)
Changeset.change(ch, email: String.downcase(email))
end
defp whitelist_email(%Ecto.Changeset{valid?: false} = ch), do: ch
defp whitelist_email(%Changeset{valid?: false} = ch), do: ch
defp whitelist_email(%Ecto.Changeset{} = ch) do
{_, email} = Ecto.Changeset.fetch_field(ch, :email)
defp whitelist_email(%Changeset{} = ch) do
{_, email} = Changeset.fetch_field(ch, :email)
if MoodleNet.Accounts.is_email_in_whitelist?(email) do
ch
else
Ecto.Changeset.add_error(ch, :email, "You cannot register with this email address",
Changeset.add_error(ch, :email, "You cannot register with this email address",
validation: "inclusion"
)
end
end
def confirm_email_changeset(%__MODULE__{} = user) do
Ecto.Changeset.change(user, confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second))
Changeset.change(user, confirmed_at: DateTime.utc_now() |> DateTime.truncate(:second))
end
def name(%__MODULE__{} = user) do
......
......@@ -8,7 +8,7 @@ defmodule MoodleNet.Email do
use Bamboo.Phoenix, view: MoodleNetWeb.EmailView
def welcome(user, token) do
url = email_confirmation_url(token)
url = email_confirmation_url(user.id, token)
base_email(user)
|> subject(gettext("Welcome to MoodleNet"))
|> render(:welcome, user: user, url: url)
......@@ -37,15 +37,14 @@ defmodule MoodleNet.Email do
|> put_layout({MoodleNetWeb.LayoutView, :email})
end
defp email_confirmation_url(token) do
MoodleNetWeb.Endpoint.struct_url()
|> Map.put(:path, "/email_confirmation?token=#{token}")
|> URI.to_string()
end
defp email_confirmation_url(id, token),
do: frontend_url("/confirm-email/#{token}")
defp reset_password_url(token), do: frontend_url("reset/#{token}")
defp reset_password_url(token) do
MoodleNetWeb.Endpoint.struct_url()
|> Map.put(:path, "/reset_password?token=#{token}")
|> URI.to_string()
# Note that the base url is expected to end with a slash (/)
defp frontend_url(path) do
Application.fetch_env!(:moodle_net, :frontend_base_url) <> path
end
end
......@@ -5,7 +5,7 @@ defmodule MoodleNet.Mixfile do
def project do
[
app: :moodle_net,
version: "0.9.4-dev.2", # current MoodleNet Server version
version: "0.9.4-dev.4", # current MoodleNet Server version
elixir: "~> 1.7", # required version of Elixir
elixirc_paths: elixirc_paths(Mix.env()),
compilers: [:phoenix, :gettext] ++ Mix.compilers(),
......@@ -26,7 +26,9 @@ defmodule MoodleNet.Mixfile do
# Configuration for the OTP application.
# Type `mix help compile.app` for more information.
def application do
[mod: {MoodleNet.Application, []}, extra_applications: [:logger, :runtime_tools, :comeonin]]
[mod: {MoodleNet.Application, []},
extra_applications: [:logger, :runtime_tools, :comeonin]
]
end
# Specifies which paths to compile per environment.
......
......@@ -14,7 +14,9 @@ config :moodle_net, MoodleNet.Repo,
hostname: env.("DATABASE_HOST"),
pool_size: 15
port = String.to_integer(env.("PORT") || "8080")
port = String.to_integer(System.get_env("PORT") || "8080")
config :moodle_net, MoodleNetWeb.Endpoint,
http: [port: port],
url: [host: env.("HOSTNAME"), port: port],
......@@ -23,6 +25,8 @@ config :moodle_net, MoodleNetWeb.Endpoint,
config :moodle_net, :ap_base_url, env.("AP_BASE_URL")
config :moodle_net, :frontend_base_url, env.("FRONTEND_BASE_URL")
config :moodle_net, MoodleNet.Mailer,
domain: env.("MAIL_DOMAIN"),
api_key: env.("MAIL_KEY")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment