Packages

A modular first authentication base

Current section

Files

Jump to
gauth src gauth@user@creation@middleware.erl
Raw

src/gauth@user@creation@middleware.erl

-module(gauth@user@creation@middleware).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([logging/1, trim_name/1, within_length/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-file("src\\gauth\\user\\creation\\middleware.gleam", 20).
?DOC(" Logs to stdout when a user is about to be created\n").
-spec logging(binary()) -> {ok, binary()} |
{error, gauth@user@creation:user_creation_error()}.
logging(Name) ->
gleam_stdlib:println(<<"Creating user with name: "/utf8, Name/binary>>),
{ok, Name}.
-file("src\\gauth\\user\\creation\\middleware.gleam", 26).
?DOC(" Runs string.trim on the provided name\n").
-spec trim_name(binary()) -> {ok, binary()} |
{error, gauth@user@creation:user_creation_error()}.
trim_name(Name) ->
{ok,
begin
_pipe = Name,
gleam@string:trim(_pipe)
end}.
-file("src\\gauth\\user\\creation\\middleware.gleam", 31).
?DOC(" Returns a middleware that ensures the provided name is within the required bounds. If it is not then it will return an InvalidName error\n").
-spec within_length(integer(), integer()) -> fun((binary()) -> {ok, binary()} |
{error, gauth@user@creation:user_creation_error()}).
within_length(Min, Max) ->
fun(Name) -> case string:length(Name) of
Len when Len < Min ->
{error,
{invalid_name,
Name,
<<"Name is too short, must be atleast "/utf8,
(erlang:integer_to_binary(Min))/binary>>}};
Len@1 when Len@1 > Max ->
{error,
{invalid_name,
Name,
<<"Name is too long, must be atmost "/utf8,
(erlang:integer_to_binary(Max))/binary>>}};
_ ->
{ok, Name}
end end.