diff --git a/Project.toml b/Project.toml index 04751e6..ac13d86 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GenieAuthentication" uuid = "e115e502-7e3a-11e9-29b2-aba8be6c6778" authors = ["Adrian Salceanu "] -version = "0.5" +version = "0.6" [deps] Genie = "c43c736e-a2d1-11e8-161f-af95117fbd1e" @@ -10,5 +10,5 @@ SearchLight = "340e8cb6-72eb-11e8-37ce-c97ebeb32050" [compat] Genie = "1" -SearchLight = "0.20" -julia = "1" +SearchLight = "0.21" +julia = "1" \ No newline at end of file diff --git a/files/app/resources/authentication/AuthenticationController.jl b/files/app/resources/authentication/AuthenticationController.jl index 948b9fc..b187b16 100644 --- a/files/app/resources/authentication/AuthenticationController.jl +++ b/files/app/resources/authentication/AuthenticationController.jl @@ -38,19 +38,21 @@ end function register() try - 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))) + user = User(username = Genie.Router.@params(:username), + password = Genie.Router.@params(:password) |> Users.hash_password, + name = Genie.Router.@params(:name), + email = Genie.Router.@params(:email)) |> SearchLight.save! GenieAuthentication.authenticate(user.id, Genie.Sessions.session(Genie.Router.@params)) "Registration successful" catch ex + @error ex + if hasfield(typeof(ex), :msg) Genie.Flash.flash(ex.msg) else - rethrow(ex) + Genie.Flash.flash(string(ex)) end Genie.Renderer.redirect(:show_register) diff --git a/files/app/resources/users/Users.jl b/files/app/resources/users/Users.jl index efbe3dd..6a41921 100644 --- a/files/app/resources/users/Users.jl +++ b/files/app/resources/users/Users.jl @@ -12,18 +12,17 @@ Base.@kwdef mutable struct User <: AbstractModel password::String = "" name::String = "" email::String = "" - - ### VALIDATION - # validator::ModelValidator = ModelValidator([ - # ValidationRule(:username, UsersValidator.not_empty), - # ValidationRule(:username, UsersValidator.unique), - # ValidationRule(:password, UsersValidator.not_empty), - # ValidationRule(:email, UsersValidator.not_empty), - # ValidationRule(:email, UsersValidator.unique), - # ValidationRule(:name, UsersValidator.not_empty) - # ]) end +Validation.validator(u::Type{User}) = ModelValidator([ + ValidationRule(:username, UsersValidator.not_empty), + ValidationRule(:username, UsersValidator.unique), + ValidationRule(:password, UsersValidator.not_empty), + ValidationRule(:email, UsersValidator.not_empty), + ValidationRule(:email, UsersValidator.unique), + ValidationRule(:name, UsersValidator.not_empty) +]) + function hash_password(password::String) sha256(password) |> bytes2hex end