Packages
openmaize
2.4.0
3.0.1
retired
3.0.0
2.9.0
2.8.0
2.7.0
2.6.0
2.5.1
2.5.0
2.4.0
2.3.2
2.3.1
2.3.0
2.2.0
2.1.5
2.1.4
2.1.3
2.1.2
2.1.1
2.1.0
2.0.2
2.0.1
2.0.0
1.0.1
1.0.0
1.0.0-beta.5
1.0.0-beta.4
1.0.0-beta.3
1.0.0-beta.2
1.0.0-beta.1
1.0.0-beta.0
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.17.2
0.17.1
0.17.0
0.16.2
0.16.1
0.16.0
0.15.1
0.15.0
0.14.0
0.13.0
0.12.0
0.11.1
0.11.0
0.10.2
0.10.1
0.10.0
0.8.1
0.8.0
0.7.5
0.7.4
0.7.2
0.7.1
0.7.0
0.6.7
0.6.6
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.1
0.4.0
Authentication library for Elixir using Plug
Current section
Files
Jump to
Current section
Files
lib/mix/tasks/openmaize.gen.phoenixauth.ex
defmodule Mix.Tasks.Openmaize.Gen.Phoenixauth do
use Mix.Task
import Openmaize.Utils
@moduledoc """
Create modules for authorization and, optionally, email confirmation.
## Options
There are two options:
* confirm - add functions for email confirmation and password resets
* the default is false
* api - create files to authenticate an api instead of a html application
* the default is false
## Examples
In the root directory of your project, run the following command (add `--confirm`
if you want to create functions for email confirmation):
mix openmaize.gen.phoenixauth
If you want to create files for an api, run the following command:
mix openmaize.gen.phoenixauth --api
"""
@doc false
def run(args) do
switches = [confirm: :boolean, api: :boolean]
{opts, _argv, _} = OptionParser.parse(args, switches: switches)
srcdir = Path.join [Application.app_dir(:openmaize, "priv"),
"templates", "phoenixauth"]
confirm = if opts[:api], do: false, else: opts[:confirm]
files = [
{:eex, "session_controller.ex", "web/controllers/session_controller.ex"},
{:eex, "session_controller_test.exs", "test/controllers/session_controller_test.exs"},
{:eex, "session_view.ex", "web/views/session_view.ex"},
{:eex, "user_controller.ex", "web/controllers/user_controller.ex"},
{:eex, "user_controller_test.exs", "test/controllers/user_controller_test.exs"},
{:eex, "user_view.ex", "web/views/user_view.ex"},
{:eex, "test_helpers.ex", "test/support/test_helpers.ex"},
{:eex, "user_migration.exs", "priv/repo/migrations/#{timestamp()}_create_user.exs"},
{:eex, "user_model.ex", "web/models/user.ex"},
{:eex, "user_model_test.exs", "test/models/user.exs"},
{:eex, "router.ex", "web/router.ex"}
#] ++ html_or_api(opts[:api]) ++ get_confirm(opts[:confirm], opts[:api])
] ++ html_or_api(opts[:api]) ++ get_confirm(confirm, opts[:api])
Mix.Openmaize.copy_files(srcdir, files,
#base: base_module(), confirm: opts[:confirm], api: opts[:api])
base: base_module(), confirm: confirm, api: opts[:api])
Mix.shell.info """
Please check the generated files. You might need to uncomment certain
lines and / or change certain details, such as paths or user details.
Before you use Openmaize, you need to configure Openmaize.
See the documentation for Openmaize.Config for details.
"""
end
defp html_or_api(true) do
[{:eex, "auth_view.ex", "web/views/auth_view.ex"},
{:eex, "auth.ex", "web/controllers/auth.ex"},
{:eex, "changeset_view.ex", "web/views/changeset_view.ex"}]
end
defp html_or_api(_) do
[{:eex, "authorize.ex", "web/controllers/authorize.ex"},
{:text, "app.html.eex", "web/templates/layout/app.html.eex"},
{:text, "index.html.eex", "web/templates/page/index.html.eex"},
{:text, "session_new.html.eex", "web/templates/session/new.html.eex"},
{:text, "user_edit.html.eex", "web/templates/user/edit.html.eex"},
{:text, "user_form.html.eex", "web/templates/user/form.html.eex"},
{:text, "user_index.html.eex", "web/templates/user/index.html.eex"},
{:text, "user_new.html.eex", "web/templates/user/new.html.eex"},
{:text, "user_show.html.eex", "web/templates/user/show.html.eex"}]
end
defp get_confirm(true, true) do
[{:eex, "mailer.ex", "lib/#{base_name()}/mailer.ex"},
{:eex, "password_reset_controller.ex", "web/controllers/password_reset_controller.ex"},
{:eex, "password_reset_controller_test.exs", "test/controllers/password_reset_controller_test.exs"},
{:eex, "password_reset_view.ex", "web/views/password_reset_view.ex"}]
end
defp get_confirm(true, _) do
[{:text, "password_reset_new.html.eex", "web/templates/password_reset/new.html.eex"},
{:text, "password_reset_edit.html.eex", "web/templates/password_reset/edit.html.eex"}] ++
get_confirm(true, true)
end
defp get_confirm(_, _), do: []
defp timestamp do
{{y, m, d}, {hh, mm, ss}} = :calendar.universal_time()
"#{y}#{pad(m)}#{pad(d)}#{pad(hh)}#{pad(mm)}#{pad(ss)}"
end
defp pad(i) when i < 10, do: << ?0, ?0 + i >>
defp pad(i), do: to_string(i)
end