@@ -12,12 +12,15 @@ defmodule Pow.Ecto.Schema.Changeset do
12
12
13
13
* `:password_min_length` - minimum password length, defaults to 8
14
14
* `:password_max_length` - maximum password length, defaults to 4096
15
- * `:password_hash_verify` - the password hash and verify functions to use,
16
- defaults to:
15
+ * `:password_hash_verify` - the password hash and verify anonymous
16
+ functions or MFAs, defaults to:
17
17
18
18
{&Pow.Ecto.Schema.Password.pbkdf2_hash/1,
19
19
&Pow.Ecto.Schema.Password.pbkdf2_verify/2}
20
- * `:email_validator` - the email validation function, defaults to:
20
+
21
+ It may be anonymous functions of MFAs.
22
+ * `:email_validator` - the email validation anonymous function or
23
+ MFA, defaults to:
21
24
22
25
23
26
&Pow.Ecto.Schema.Changeset.validate_email/1
@@ -169,7 +172,7 @@ defmodule Pow.Ecto.Schema.Changeset do
169
172
validator = get_email_validator ( config )
170
173
171
174
Changeset . validate_change ( changeset , :email , { :email_format , validator } , fn :email , email ->
172
- case validator . ( email ) do
175
+ case apply_function_or_mfa ( validator , [ email ] ) do
173
176
:ok -> [ ]
174
177
:error -> [ email: { "has invalid format" , validation: :email_format } ]
175
178
{ :error , reason } -> [ email: { "has invalid format" , validation: :email_format , reason: reason } ]
@@ -215,16 +218,12 @@ defmodule Pow.Ecto.Schema.Changeset do
215
218
"""
216
219
@ spec verify_password ( Ecto.Schema . t ( ) , binary ( ) , Config . t ( ) ) :: boolean ( )
217
220
def verify_password ( % { password_hash: nil } , _password , config ) do
218
- config
219
- |> get_password_hash_function ( )
220
- |> apply ( [ "" ] )
221
+ apply_password_hash_function ( config , [ "" ] )
221
222
222
223
false
223
224
end
224
225
def verify_password ( % { password_hash: password_hash } , password , config ) do
225
- config
226
- |> get_password_verify_function ( )
227
- |> apply ( [ password , password_hash ] )
226
+ apply_password_verify_function ( config , [ password , password_hash ] )
228
227
end
229
228
230
229
defp maybe_require_password ( % { data: % { password_hash: nil } } = changeset ) do
@@ -259,21 +258,26 @@ defmodule Pow.Ecto.Schema.Changeset do
259
258
defp maybe_validate_password_hash ( changeset ) , do: changeset
260
259
261
260
defp hash_password ( password , config ) do
262
- config
263
- |> get_password_hash_function ( )
264
- |> apply ( [ password ] )
261
+ apply_password_hash_function ( config , [ password ] )
265
262
end
266
263
267
- defp get_password_hash_function ( config ) do
264
+ defp apply_password_hash_function ( config , args ) do
268
265
{ password_hash_function , _ } = get_password_hash_functions ( config )
269
266
270
- password_hash_function
267
+ apply_function_or_mfa ( password_hash_function , args )
268
+ end
269
+
270
+ defp apply_function_or_mfa ( fun_or_mfa , apply_args ) do
271
+ case fun_or_mfa do
272
+ fun when is_function ( fun ) -> apply ( fun , apply_args )
273
+ { mod , fun , args } when is_list ( args ) -> apply ( mod , fun , args ++ apply_args )
274
+ end
271
275
end
272
276
273
- defp get_password_verify_function ( config ) do
277
+ defp apply_password_verify_function ( config , args ) do
274
278
{ _ , password_verify_function } = get_password_hash_functions ( config )
275
279
276
- password_verify_function
280
+ apply_function_or_mfa ( password_verify_function , args )
277
281
end
278
282
279
283
defp get_password_hash_functions ( config ) do
0 commit comments