Current section

68 Versions

Jump to

Compare versions

14 files changed
+88 additions
-54 deletions
  @@ -1,11 +1,14 @@
1 1 # Changelog
2 2
3 - ## v0.20.0
3 + ## v1.0.0
4 4
5 5 * Enhancements
6 6 * Added a mix generator to generate an OpenmaizeEcto module.
7 7 * This module implements the Openmaize.Database behaviour.
8 8 * Changes
9 + * Moved the Config.db_module functionality to using keyword arguments
10 + * This affects the Openmaize.Login, Openmaize.OnetimePass,
11 + Openmaize.ConfirmEmail and Openmaize.ResetPassword plugs.
9 12 * Removed the Openmaize.DB module.
10 13 * Added the Openmaize.Database behaviour.
  @@ -56,4 +56,4 @@
56 56 {<<"name">>,<<"not_qwerty123">>},
57 57 {<<"optional">>,true},
58 58 {<<"requirement">>,<<"~> 1.2">>}]]}.
59 - {<<"version">>,<<"1.0.0-beta.1">>}.
59 + {<<"version">>,<<"1.0.0-beta.2">>}.
  @@ -26,10 +26,13 @@ defmodule Mix.Tasks.Openmaize.Gen.Ectodb do
26 26 paths, user details, roles, etc., will most likely need to be
27 27 changed.
28 28
29 - In the config file, set the `db_module` value:
29 + When using the Openmaize.Login, Openmaize.ConfirmEmail,
30 + Openmaize.ResetPassword, and Openmaize.OnetimePass plugs, add
31 + `db_module: #{mod_name}.OpenmaizeEcto` to the optional arguments,
32 + like the example below:
30 33
31 - config :openmaize,
32 - db_module: #{mod_name}.OpenmaizeEcto
34 + plug Openmaize.Login, [db_module: ${mod_name}.OpenmaizeEcto,
35 + unique_id: :email] when action in [:login_user]
33 36
34 37 See the documentation for Openmaize.Config and OpenmaizeJWT.Config
35 38 for further details on how to configure Openmaize.
  @@ -7,7 +7,6 @@ defmodule Openmaize.Config do
7 7
8 8 | name | type | default |
9 9 | :----------------- | :----------- | ---------------: |
10 - | db_module | module | N/A |
11 10 | crypto_mod | module | Comeonin.Bcrypt |
12 11 | hash_name | atom | :password_hash |
13 12 | password_strength | keyword list | [] |
  @@ -19,20 +18,12 @@ defmodule Openmaize.Config do
19 18 like the following example.
20 19
21 20 config :openmaize,
22 - db_module: Coolapp.OpenmaizeEcto,
23 21 crypto_mod: Comeonin.Bcrypt,
24 22 hash_name: :encrypted_password,
25 23 password_strength: [min_length: 12]
26 24
27 25 """
28 26
29 - @doc """
30 - The name of the database module.
31 - """
32 - def db_module do
33 - Application.get_env(:openmaize, :db_module)
34 - end
35 -
36 27 @doc """
37 28 The password hashing and checking algorithm. Bcrypt is the default.
  @@ -17,17 +17,21 @@ defmodule Openmaize.Confirm.Base do
17 17
18 18 @doc false
19 19 def init(opts) do
20 - {Keyword.get(opts, :key_expires_after, 120),
20 + {Keyword.get(opts, :db_module),
21 + Keyword.get(opts, :key_expires_after, 120),
21 22 Keyword.get(opts, :unique_id, :email),
22 23 Keyword.get(opts, :mail_function)}
23 24 end
24 25
25 26 @doc false
27 + def call(_, {nil, _, _, _}) do
28 + raise ArgumentError, "You need to set the db_module value for Openmaize.ConfirmEmail"
29 + end
26 30 def call(%Plug.Conn{params: %{"key" => key} = user_params} = conn, opts)
27 31 when byte_size(key) == 32 do
28 32 check_user_key(conn, user_params, key, :nopassword, opts)
29 33 end
30 - def call(conn, {_, _, _}), do: invalid_link_error(conn)
34 + def call(conn, _opts), do: invalid_link_error(conn)
31 35
32 36 defoverridable [init: 1, call: 2]
33 37 end
  @@ -35,7 +39,6 @@ defmodule Openmaize.Confirm.Base do
35 39
36 40 import Plug.Conn
37 41 import Comeonin.Tools
38 - alias Openmaize.Config
39 42
40 43 @doc """
41 44 Check the user key and, if necessary, the user password.
  @@ -45,13 +48,13 @@ defmodule Openmaize.Confirm.Base do
45 48 an `openmaize_error` message will be added to the conn.
46 49 """
47 50 def check_user_key(conn, user_params, key, password,
48 - {key_expiry, uniq, mail_func}) do
51 + {db_module, key_expiry, uniq, mail_func}) do
49 52 case Map.get(user_params, to_string(uniq)) do
50 53 nil -> finalize(nil, conn, nil, mail_func)
51 54 user_id ->
52 55 user_id
53 - |> Config.db_module.find_user(uniq)
54 - |> check_key(key, key_expiry * 60, password)
56 + |> db_module.find_user(uniq)
57 + |> check_key(db_module, key, key_expiry * 60, password)
55 58 |> finalize(conn, user_id, mail_func)
56 59 end
57 60 end
  @@ -63,16 +66,16 @@ defmodule Openmaize.Confirm.Base do
63 66 put_private(conn, :openmaize_error, "Invalid link")
64 67 end
65 68
66 - defp check_key(nil, _, _, _), do: false
67 - defp check_key(user, key, valid_secs, :nopassword) do
68 - Config.db_module.check_time(user.confirmation_sent_at, valid_secs) and
69 + defp check_key(_, nil, _, _, _), do: false
70 + defp check_key(user, db_module, key, valid_secs, :nopassword) do
71 + db_module.check_time(user.confirmation_sent_at, valid_secs) and
69 72 secure_check(user.confirmation_token, key) and
70 - Config.db_module.user_confirmed(user)
73 + db_module.user_confirmed(user)
71 74 end
72 - defp check_key(user, key, valid_secs, password) do
73 - Config.db_module.check_time(user.reset_sent_at, valid_secs) and
75 + defp check_key(user, db_module, key, valid_secs, password) do
76 + db_module.check_time(user.reset_sent_at, valid_secs) and
74 77 secure_check(user.reset_token, key) and
75 - Config.db_module.password_reset(user, password)
78 + db_module.password_reset(user, password)
76 79 end
77 80
78 81 defp finalize({:ok, user}, conn, _, mail_func) do
Loading more files…