From 867ec2dfcfd9eefeb8c726c38ebdd8557d0e2efa Mon Sep 17 00:00:00 2001 From: Adrian Date: Sun, 26 Jan 2020 09:47:40 +0100 Subject: [PATCH] v0.3 --- Manifest.toml | 151 ++++++++++-------- Project.toml | 2 +- .../AuthenticationController.jl | 38 ++--- files/plugins/genie_authentication.jl | 16 +- src/GenieAuthentication.jl | 47 +++--- 5 files changed, 141 insertions(+), 113 deletions(-) diff --git a/Manifest.toml b/Manifest.toml index eaa1b4a..75f2905 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1,10 +1,10 @@ # This file is machine-generated - editing it directly is not advised [[AbstractTrees]] -deps = ["Markdown", "Test"] -git-tree-sha1 = "6621d9645702c1c4e6970cc6a3eae440c768000b" +deps = ["Markdown"] +git-tree-sha1 = "940760b82db1f7090f7d16fe6e4b121cc181db45" uuid = "1520ce14-60c1-5f80-bbc7-55ef81b5835c" -version = "0.2.1" +version = "0.3.1" [[ArgParse]] deps = ["Compat", "Test", "TextWrap"] @@ -28,15 +28,15 @@ uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232" version = "0.5.8" [[CEnum]] -git-tree-sha1 = "5a2679abe17f5e70d90753940dcb7f15e61369d4" +git-tree-sha1 = "62847acab40e6855a9b5905ccb99c2b5cf6b3ebb" uuid = "fa961155-64e5-5f13-b03f-caf6b980ea82" -version = "0.1.2" +version = "0.2.0" [[CategoricalArrays]] -deps = ["Compat", "DataAPI", "Future", "JSON", "Missings", "Printf", "Reexport", "Unicode"] -git-tree-sha1 = "45101c4d0df3946acb6e9bfcfd3a8c32abbd421b" +deps = ["Compat", "DataAPI", "Future", "JSON", "Missings", "Printf", "Reexport", "Statistics", "Unicode"] +git-tree-sha1 = "23d7324164c89638c18f6d7f90d972fa9c4fa9fb" uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597" -version = "0.7.1" +version = "0.7.7" [[CodeTracking]] deps = ["InteractiveUtils", "UUIDs"] @@ -57,10 +57,9 @@ uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" version = "2.2.0" [[Crayons]] -deps = ["Test"] -git-tree-sha1 = "f621b8ef51fd2004c7cf157ea47f027fdeac5523" +git-tree-sha1 = "cb7a62895da739fe5bb43f1a26d4292baf4b3dc0" uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" -version = "4.0.0" +version = "4.0.1" [[DataAPI]] git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252" @@ -68,10 +67,10 @@ uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" version = "1.1.0" [[DataFrames]] -deps = ["CategoricalArrays", "Compat", "DataAPI", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] -git-tree-sha1 = "271528230c65a4517522e2968c3deed76b92b998" +deps = ["CategoricalArrays", "Compat", "DataAPI", "Future", "InvertedIndices", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "TableTraits", "Tables", "Unicode"] +git-tree-sha1 = "00136fcd39d503e66ab1b2eab800c47deaf7ca04" uuid = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" -version = "0.19.4" +version = "0.20.0" [[DataStreams]] deps = ["Missings", "WeakRefStrings"] @@ -81,9 +80,9 @@ version = "0.4.2" [[DataStructures]] deps = ["InteractiveUtils", "OrderedCollections"] -git-tree-sha1 = "1fe8fad5fc84686dcbc674aa255bc867a64f8132" +git-tree-sha1 = "b7720de347734f4716d1815b00ce5664ed6bbfd4" uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" -version = "0.17.5" +version = "0.17.9" [[DataValueInterfaces]] git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6" @@ -121,10 +120,10 @@ uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" version = "0.8.1" [[EzXML]] -deps = ["BinaryProvider", "Libdl", "Printf"] -git-tree-sha1 = "aed48d722e528bc634bd36a7d0e090fa2952a3c0" +deps = ["Printf", "XML2_jll"] +git-tree-sha1 = "0fa3b52a04a4e210aeb1626def9c90df3ae65268" uuid = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615" -version = "0.9.4" +version = "1.1.0" [[FilePaths]] deps = ["FilePathsBase", "MacroTools", "Reexport", "URIParser"] @@ -147,11 +146,9 @@ uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820" [[Genie]] deps = ["ArgParse", "Dates", "Distributed", "FilePaths", "Gumbo", "HTTP", "HttpCommon", "JSON", "Logging", "LoggingExtras", "Markdown", "MbedTLS", "Millboard", "Nettle", "OrderedCollections", "Pkg", "REPL", "Reexport", "Revise", "SHA", "Serialization", "Sockets", "URIParser", "Unicode"] -git-tree-sha1 = "8abc9770c390db4d1ea61231bd251bc5440e75ec" -repo-rev = "master" -repo-url = "https://github.com/GenieFramework/Genie.jl" +git-tree-sha1 = "fd68a6630a43f7f669e3c7b10331613a6b768fe5" uuid = "c43c736e-a2d1-11e8-161f-af95117fbd1e" -version = "0.21.0" +version = "0.25.0" [[Gumbo]] deps = ["AbstractTrees", "BinaryProvider", "Libdl", "Test"] @@ -161,9 +158,9 @@ version = "0.5.1" [[HTTP]] deps = ["Base64", "Dates", "IniFile", "MbedTLS", "Sockets"] -git-tree-sha1 = "806f2a5d66d1b78e5349fd463a41f0c10ca5fff3" +git-tree-sha1 = "5c49dab19938b119fe204fd7d7e8e174f4e9c68b" uuid = "cd3eb016-35fb-5094-929b-558a96fad6f3" -version = "0.8.7" +version = "0.8.8" [[HttpCommon]] deps = ["Dates", "Nullables", "Test", "URIParser"] @@ -188,9 +185,9 @@ uuid = "41ab1584-1d38-5bbf-9106-f11c6c58b48f" version = "1.0.0" [[IterTools]] -git-tree-sha1 = "2ebe60d7343962966d1779a74a760f13217a6901" +git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18" uuid = "c8e1da08-722c-5040-9ed9-7db0dc04731e" -version = "1.2.0" +version = "1.3.0" [[IteratorInterfaceExtensions]] git-tree-sha1 = "a3f24677c21f5bbe9d2a714f95dcd58337fb2856" @@ -205,9 +202,9 @@ version = "0.21.0" [[JuliaInterpreter]] deps = ["CodeTracking", "InteractiveUtils", "Random", "UUIDs"] -git-tree-sha1 = "5bb6a8b09d881c1cbe39bd8135667ed5978168e9" +git-tree-sha1 = "a4f675340a109713f74c47a2b499df06f800c8d0" uuid = "aa1ae85d-cabe-5617-a682-6adf51b2e16a" -version = "0.7.4" +version = "0.7.8" [[LayerDicts]] git-tree-sha1 = "6087ad3521d6278ebe5c27ae55e7bbb15ca312cb" @@ -219,13 +216,19 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" [[LibPQ]] deps = ["BinaryProvider", "CEnum", "Dates", "Decimals", "DocStringExtensions", "FileWatching", "IterTools", "LayerDicts", "Libdl", "Memento", "OffsetArrays", "Tables", "TimeZones"] -git-tree-sha1 = "3843a1238b97235567a163bb48f7747a12a8ab12" +git-tree-sha1 = "68277b29fe9f9e2708f0d0969cdfe36daf4445d6" uuid = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1" -version = "0.11.2" +version = "1.0.6" [[Libdl]] uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +[[Libiconv_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "48563fe30f00c9d4a4d61891e71df389bf901142" +uuid = "94ce4f54-9a6c-5748-9c1c-f9c7231a4531" +version = "1.16.0+0" + [[LinearAlgebra]] deps = ["Libdl"] uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" @@ -234,21 +237,21 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" [[LoggingExtras]] -git-tree-sha1 = "5c47830453708ffd09bf83a15e14924daa6570f7" +git-tree-sha1 = "c867b50bfc564f0beded1c566f4fc66cfd8b5418" uuid = "e6f89c97-d47a-5376-807f-9c37f3926c36" -version = "0.3.0" +version = "0.4.0" [[LoweredCodeUtils]] deps = ["JuliaInterpreter"] -git-tree-sha1 = "b995265a1228701da0d7313a097e33bca46c8f90" +git-tree-sha1 = "b416a30717e9109fffd4d9869f2f962b5dca3162" uuid = "6f1432cf-f94c-5a45-995e-cdbf5db27b0b" -version = "0.4.1" +version = "0.4.2" [[MacroTools]] -deps = ["Compat", "DataStructures", "Test"] -git-tree-sha1 = "82921f0e3bde6aebb8e524efc20f4042373c0c06" +deps = ["DataStructures", "Markdown", "Random"] +git-tree-sha1 = "e2fc7a55bb2224e203bbd8b59f72b91323233458" uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" -version = "0.5.2" +version = "0.5.3" [[Markdown]] deps = ["Base64"] @@ -267,9 +270,9 @@ uuid = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9" version = "0.12.1" [[Millboard]] -git-tree-sha1 = "c6d4a61d1b74ba35b1efe5cb025bf852145521e1" +git-tree-sha1 = "e6197b7827b092bbaeeccd7d1b8c7dc9e970308f" uuid = "39ec1447-df44-5f4c-beaa-866f30b4d3b2" -version = "0.2.1" +version = "0.2.4" [[Missings]] deps = ["DataAPI"] @@ -298,15 +301,20 @@ uuid = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9" version = "0.4.0" [[Nullables]] -deps = ["Compat"] -git-tree-sha1 = "ae1a63457e14554df2159b0b028f48536125092d" +git-tree-sha1 = "8f87854cc8f3685a60689d8edecaa29d2251979b" uuid = "4d1e1d77-625e-5b40-9113-a560ec7a8ecd" -version = "0.0.8" +version = "1.0.0" [[OffsetArrays]] -git-tree-sha1 = "1af2f79c7eaac3e019a0de41ef63335ff26a0a57" +git-tree-sha1 = "87d0a91efe29352d5caaa271ae3927083c096e33" uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" -version = "0.11.1" +version = "0.11.4" + +[[OpenSpecFun_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "65f672edebf3f4e613ddf37db9dcbd7a407e5e90" +uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" +version = "0.5.3+1" [[OrderedCollections]] deps = ["Random", "Serialization", "Test"] @@ -316,18 +324,19 @@ version = "1.1.0" [[Parsers]] deps = ["Dates", "Test"] -git-tree-sha1 = "c56ecb484f286639f161e712b8311f5ab77e8d32" +git-tree-sha1 = "0139ba59ce9bc680e2925aec5b7db79065d60556" uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" -version = "0.3.8" +version = "0.3.10" [[Pkg]] -deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"] +deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Test", "UUIDs"] uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" [[PooledArrays]] -git-tree-sha1 = "6e8c38927cb6e9ae144f7277c753714861b27d14" +deps = ["DataAPI"] +git-tree-sha1 = "b1333d4eced1826e15adbdf01a4ecaccca9d353c" uuid = "2dfb63ee-cc39-5dd5-95bd-886bf059d720" -version = "0.5.2" +version = "0.5.3" [[Printf]] deps = ["Unicode"] @@ -349,26 +358,24 @@ version = "0.2.0" [[Revise]] deps = ["CodeTracking", "Distributed", "FileWatching", "JuliaInterpreter", "LibGit2", "LoweredCodeUtils", "OrderedCollections", "Pkg", "REPL", "UUIDs", "Unicode"] -git-tree-sha1 = "0d9092e63eb112b1ada52fc57abebf0c6cc83f42" +git-tree-sha1 = "2ecbd19f31a934b035bfc38036d5f7ac575d0878" uuid = "295af30f-e4ad-537b-8983-00126c2a3abe" -version = "2.3.0" +version = "2.5.0" [[SHA]] uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" [[SQLite]] deps = ["BinaryProvider", "DataFrames", "Dates", "Libdl", "Random", "Serialization", "Tables", "Test", "WeakRefStrings"] -git-tree-sha1 = "0b4a56ae5df77c6b725cd22e4734ea137f883c7a" +git-tree-sha1 = "5c53dd3d239c327812cba66b110c4789e87942c8" uuid = "0aa819cd-b072-5ff4-a722-6bc24af294d9" -version = "0.8.2" +version = "0.9.0" [[SearchLight]] deps = ["Crayons", "DataFrames", "DataStreams", "Dates", "Distributed", "JSON", "LibPQ", "Logging", "MbedTLS", "Millboard", "MySQL", "OrderedCollections", "Reexport", "Revise", "SHA", "SQLite", "Unicode", "YAML"] -git-tree-sha1 = "bf36be596c68cb04bd4aefd71ac72fec93d78909" -repo-rev = "master" -repo-url = "https://github.com/GenieFramework/SearchLight.jl" +git-tree-sha1 = "34c16c6189783bca22fcff0aa61f869e9d370555" uuid = "340e8cb6-72eb-11e8-37ce-c97ebeb32050" -version = "0.15.0" +version = "0.16.1" [[Serialization]] uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" @@ -391,10 +398,10 @@ deps = ["LinearAlgebra", "Random"] uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" [[SpecialFunctions]] -deps = ["BinDeps", "BinaryProvider", "Libdl"] -git-tree-sha1 = "3bdd374b6fd78faf0119b8c5d538788dbf910c6e" +deps = ["OpenSpecFun_jll"] +git-tree-sha1 = "e19b98acb182567bcb7b75bb5d9eedf3a3b5ec6c" uuid = "276daf66-3868-5448-9aa4-cd146d93841b" -version = "0.8.0" +version = "0.10.0" [[Statistics]] deps = ["LinearAlgebra", "SparseArrays"] @@ -430,9 +437,9 @@ version = "0.3.0" [[TimeZones]] deps = ["Dates", "EzXML", "Mocking", "Printf", "Serialization", "Unicode"] -git-tree-sha1 = "0271dc890dd1447da1568510937bd5b3a6b51b58" +git-tree-sha1 = "24a7474411886cede89529f9b848989b783d954e" uuid = "f269a46b-ccf7-5d73-abea-4c690281aa53" -version = "0.9.2" +version = "0.10.5" [[URIParser]] deps = ["Test", "Unicode"] @@ -448,13 +455,25 @@ uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" [[WeakRefStrings]] -deps = ["Random", "Test"] -git-tree-sha1 = "9a0bb82eede528debe631b642eeb48a631a69bc2" +deps = ["DataAPI", "Random", "Test"] +git-tree-sha1 = "28807f85197eaad3cbd2330386fac1dcb9e7e11d" uuid = "ea10d353-3f73-51f8-a26c-33c1cb351aa5" -version = "0.6.1" +version = "0.6.2" + +[[XML2_jll]] +deps = ["Libdl", "Libiconv_jll", "Pkg", "Zlib_jll"] +git-tree-sha1 = "ed5603a695aefe3e9e404fc7b052e02cc72cfab6" +uuid = "02c8fc9c-b97f-50b9-bbe4-9be30ff0a78a" +version = "2.9.9+1" [[YAML]] deps = ["Codecs", "Compat"] git-tree-sha1 = "3bde77cee95cce0c0b9b18813d85e18e8ed4f415" uuid = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6" version = "0.3.2" + +[[Zlib_jll]] +deps = ["Libdl", "Pkg"] +git-tree-sha1 = "5618a43055eb09377edca21d19d0e99bce24a9c3" +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.11+7" diff --git a/Project.toml b/Project.toml index 157a01f..75fe0a6 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GenieAuthentication" uuid = "e115e502-7e3a-11e9-29b2-aba8be6c6778" authors = ["Adrian Salceanu "] -version = "0.2.2" +version = "0.3.0" [deps] Genie = "c43c736e-a2d1-11e8-161f-af95117fbd1e" diff --git a/files/app/resources/authentication/AuthenticationController.jl b/files/app/resources/authentication/AuthenticationController.jl index 11f65af..1ff9d9c 100644 --- a/files/app/resources/authentication/AuthenticationController.jl +++ b/files/app/resources/authentication/AuthenticationController.jl @@ -1,12 +1,11 @@ module AuthenticationController -using Genie, Genie.Renderer, Genie.Router, Genie.Sessions, Genie.Flash +using Genie, Genie.Renderer, Genie.Renderer.Html, Genie.Router using ViewHelper using SearchLight using GenieAuthentication using Users - -Genie.config.session_auto_start = true +using Logging function show_login() html(:authentication, :login, context = @__MODULE__) @@ -14,42 +13,43 @@ end function login() try - user = SearchLight.findone(User, username = @params(:username), password = Users.hash_password(@params(:password))) - GenieAuthentication.authenticate(user.id, Sessions.session(@params)) + user = SearchLight.findone(User, username = Genie.Router.@params(:username), password = Users.hash_password(Genie.Router.@params(:password))) + GenieAuthentication.authenticate(user.id, Genie.Sessions.session(Genie.Router.@params)) - redirect(:get_home) + Genie.Renderer.redirect(:get_home) catch ex - flash("Authentication failed") + Genie.Flash.flash("Authentication failed") - redirect(:show_login) + Genie.Renderer.redirect(:show_login) end end function logout() - GenieAuthentication.deauthenticate(Sessions.session(@params)) + GenieAuthentication.deauthenticate(Genie.Sessions.session(Genie.Router.@params)) - flash("Good bye! ") + Genie.Flash.flash("Good bye! ") - redirect(:show_login) + Genie.Renderer.redirect(:show_login) end function show_register() - html(:authentication, :register, context = @__MODULE__) + Genie.Renderer.Html.html(:authentication, :register, context = @__MODULE__) end function register() try - user = SearchLight.save!!(User( username = @params(:username), - password = @params(:password) |> Users.hash_password, - name = @params(:name), - email = @params(:email))) + user = SearchLight.save!!(User( username = Genie.Router.@params(:username), + password = Genie.Router.@params(:password) |> Users.hash_password, + name = Genie.Router.@params(:name), + email = Genie.Router.@params(:email))) + + GenieAuthentication.authenticate(user.id, Genie.Sessions.session(Genie.Router.@params)) - GenieAuthentication.authenticate(user.id, Sessions.session(@params)) "Registration successful" catch ex - flash(ex.msg) + Genie.Flash.flash(ex.msg) - redirect(:show_register) + Genie.Renderer.redirect(:show_register) end end diff --git a/files/plugins/genie_authentication.jl b/files/plugins/genie_authentication.jl index 72fd81e..47ca633 100644 --- a/files/plugins/genie_authentication.jl +++ b/files/plugins/genie_authentication.jl @@ -1,9 +1,17 @@ -using Genie, Genie.Router, AuthenticationController +using Genie + +Genie.Sessions.init() + +using Genie.Router +import AuthenticationController route("/login", AuthenticationController.show_login, named = :show_login) route("/login", AuthenticationController.login, method = POST, named = :login) route("/logout", AuthenticationController.logout, named = :logout) -route("/register", AuthenticationController.show_register, named = :show_register) -route("/register", AuthenticationController.register, method = POST, named = :register) -Genie.config.session_auto_start = true \ No newline at end of file +#===# + +# UNCOMMENT TO ENABLE REGISTRATION ROUTES + +# route("/register", AuthenticationController.show_register, named = :show_register) +# route("/register", AuthenticationController.register, method = POST, named = :register) \ No newline at end of file diff --git a/src/GenieAuthentication.jl b/src/GenieAuthentication.jl index ab07875..aa6dcae 100644 --- a/src/GenieAuthentication.jl +++ b/src/GenieAuthentication.jl @@ -3,9 +3,8 @@ Functionality for authenticating Genie users. """ module GenieAuthentication -using Genie, Genie.Sessions, Genie.Plugins, Genie.Router, SearchLight, Genie.Requests +import Genie, SearchLight -export current_user, current_user!! export authenticate, deauthenticate, is_authenticated, get_authentication, authenticated export login, logout, with_authentication, without_authentication @@ -15,13 +14,13 @@ const USER_ID_KEY = :__auth_user_id """ Stores the user id on the session. """ -function authenticate(user_id::Any, session::Sessions.Session) :: Sessions.Session - Sessions.set!(session, USER_ID_KEY, user_id) +function authenticate(user_id::Any, session::Genie.Sessions.Session) :: Genie.Sessions.Session + Genie.Sessions.set!(session, USER_ID_KEY, user_id) end -function authenticate(user::SearchLight.DbId, session::Sessions.Session) +function authenticate(user::SearchLight.DbId, session::Genie.Sessions.Session) authenticate(Int(user.value), session) end -function authenticate(user_id::Union{String,Symbol,Int,SearchLight.DbId}, params::Dict{Symbol,Any} = payload()) :: Sessions.Session +function authenticate(user_id::Union{String,Symbol,Int,SearchLight.DbId}, params::Dict{Symbol,Any} = Genie.Requests.payload()) :: Genie.Sessions.Session authenticate(user_id, params[:SESSION]) end @@ -32,10 +31,10 @@ end Removes the user id from the session. """ -function deauthenticate(session::Sessions.Session) :: Sessions.Session - Sessions.unset!(session, USER_ID_KEY) +function deauthenticate(session::Genie.Sessions.Session) :: Genie.Sessions.Session + Genie.Sessions.unset!(session, USER_ID_KEY) end -function deauthenticate(params::Dict{Symbol,Any} = payload()) :: Sessions.Session +function deauthenticate(params::Dict{Symbol,Any} = Genie.Requests.payload()) :: Genie.Sessions.Session deauthenticate(params[:SESSION]) end @@ -46,12 +45,13 @@ end Returns `true` if a user id is stored on the session. """ -function is_authenticated(session::Union{Sessions.Session,Nothing}) :: Bool - Sessions.isset(session, USER_ID_KEY) +function is_authenticated(session::Union{Genie.Sessions.Session,Nothing}) :: Bool + Genie.Sessions.isset(session, USER_ID_KEY) end -function is_authenticated(params::Dict{Symbol,Any} = payload()) :: Bool +function is_authenticated(params::Dict{Symbol,Any} = Genie.Requests.payload()) :: Bool is_authenticated(params[:SESSION]) end + const authenticated = is_authenticated @@ -61,12 +61,13 @@ const authenticated = is_authenticated Returns the user id stored on the session, if available. """ -function get_authentication(session::Sessions.Session) :: Union{Nothing,Any} - Sessions.get(session, USER_ID_KEY) +function get_authentication(session::Genie.Sessions.Session) :: Union{Nothing,Any} + Genie.Sessions.get(session, USER_ID_KEY) end -function get_authentication(params::Dict{Symbol,Any} = payload()) :: Union{Nothing,Any} +function get_authentication(params::Dict{Symbol,Any} = Genie.Requests.payload()) :: Union{Nothing,Any} get_authentication(params[:SESSION]) end + const authentication = get_authentication @@ -76,10 +77,10 @@ const authentication = get_authentication Persists on session the id of the user object and returns the session. """ -function login(user, session::Sessions.Session) :: Union{Nothing,Sessions.Session} +function login(user, session::Genie.Sessions.Session) :: Union{Nothing,Genie.Sessions.Session} authenticate(getfield(user, Symbol(user._id)), session) end -function login(user, params::Dict{Symbol,Any} = payload()) :: Union{Nothing,Sessions.Session} +function login(user, params::Dict{Symbol,Any} = Genie.Requests.payload()) :: Union{Nothing,Genie.Sessions.Session} login(user, params[:SESSION]) end @@ -90,10 +91,10 @@ end Deletes the id of the user object from the session, effectively logging the user off. """ -function logout(session::Sessions.Session) :: Sessions.Session +function logout(session::Genie.Sessions.Session) :: Genie.Sessions.Session deauthenticate(session) end -function logout(params::Dict{Symbol,Any} = payload()) :: Sessions.Session +function logout(params::Dict{Symbol,Any} = Genie.Requests.payload()) :: Genie.Sessions.Session logout(params[:SESSION]) end @@ -104,14 +105,14 @@ end Invokes `f` only if a user is currently authenticated on the session, `fallback` is invoked otherwise. """ -function with_authentication(f::Function, fallback::Function, session::Union{Sessions.Session,Nothing}) +function with_authentication(f::Function, fallback::Function, session::Union{Genie.Sessions.Session,Nothing}) if ! is_authenticated(session) fallback() else f() end end -function with_authentication(f::Function, fallback::Function, params::Dict{Symbol,Any} = payload()) +function with_authentication(f::Function, fallback::Function, params::Dict{Symbol,Any} = Genie.Requests.payload()) with_authentication(f, fallback, params[:SESSION]) end @@ -122,10 +123,10 @@ end Invokes `f` if there is no user authenticated on the current session. """ -function without_authentication(f::Function, session::Sessions.Session) +function without_authentication(f::Function, session::Genie.Sessions.Session) ! is_authenticated(session) && f() end -function without_authentication(f::Function, params::Dict{Symbol,Any} = payload()) +function without_authentication(f::Function, params::Dict{Symbol,Any} = Genie.Requests.payload()) without_authentication(f, params[:SESSION]) end