Skip to content

Commit e2219b8

Browse files
committed
fix: plugin_info spec, reset token hours validation, dialyzer warnings
1 parent 23d30b1 commit e2219b8

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/nova_auth_rate_limit.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ post_request(Req, _State, PluginState, _) ->
9696
-spec plugin_info() -> map().
9797
plugin_info() ->
9898
#{
99-
name => <<"nova_auth_rate_limit">>,
99+
title => <<"nova_auth_rate_limit">>,
100100
version => <<"0.2.0">>,
101-
description => <<"Rate limiting plugin for Nova (powered by Seki)">>
101+
description => <<"Rate limiting plugin for Nova (powered by Seki)">>,
102+
authors => [<<"Nova Framework">>],
103+
url => <<"https://github.com/novaframework/nova_auth">>
102104
}.
103105

104106
%%----------------------------------------------------------------------

src/nova_auth_reset.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ reset_password(AuthMod, Token, NewParams) ->
4242
Cfg = nova_auth:config(AuthMod),
4343
#{repo := Repo, token_schema := TokenSchema, user_schema := UserSchema} = Cfg,
4444
ResetHours = maps:get(reset_validity_hours, Cfg),
45-
ValidityDays = ResetHours / 24,
4645
try
4746
HashedToken = nova_auth_token:hash(Token),
4847
Q = kura_query:where(
@@ -51,7 +50,7 @@ reset_password(AuthMod, Token, NewParams) ->
5150
),
5251
case kura_repo_worker:all(Repo, Q) of
5352
{ok, [TokenRecord]} ->
54-
case nova_auth_token:valid(maps:get(inserted_at, TokenRecord), ValidityDays) of
53+
case token_valid_hours(maps:get(inserted_at, TokenRecord), ResetHours) of
5554
true ->
5655
UserId = maps:get(user_id, TokenRecord),
5756
case kura_repo_worker:get(Repo, UserSchema, UserId) of
@@ -88,3 +87,8 @@ apply_password_changeset(UserSchema, User, Params) ->
8887
true -> UserSchema:password_changeset(User, Params);
8988
false -> kura_changeset:cast(UserSchema, User, Params, [password, password_confirmation])
9089
end.
90+
91+
token_valid_hours(InsertedAt, ValidityHours) ->
92+
Now = calendar:datetime_to_gregorian_seconds(calendar:universal_time()),
93+
TokenTime = calendar:datetime_to_gregorian_seconds(InsertedAt),
94+
(Now - TokenTime) < (ValidityHours * 60 * 60).

0 commit comments

Comments
 (0)