From 189e22902e0df5992ddb590701fe26fc2e247259 Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Mon, 23 Mar 2020 06:54:45 +0100 Subject: [PATCH] Recording user registration and last connection dates. --- src/main.cr | 18 ++++++++++++++++-- src/user.cr | 12 +++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/main.cr b/src/main.cr index 5109c85..ec1645d 100644 --- a/src/main.cr +++ b/src/main.cr @@ -60,8 +60,12 @@ class AuthD::Service return Response::Error.new "invalid credentials" end + user.date_last_connection = Time.local token = user.to_token + # change the date of the last connection + @users_per_uid.update user.uid.to_s, user + Response::Token.new token.to_s @jwt_key when Request::AddUser # No verification of the users' informations when an admin adds it. @@ -90,6 +94,9 @@ class AuthD::Service user.profile = profile end + # We consider adding the user as a registration + user.date_registration = Time.local + @users << user Response::UserAdded.new user.to_public @@ -129,6 +136,11 @@ class AuthD::Service return Response::Error.new "invalid credentials" end + user.date_last_connection = Time.local + + # change the date of the last connection + @users_per_uid.update user.uid.to_s, user + Response::User.new user.to_public when Request::GetUser uid_or_login = request.user @@ -209,8 +221,7 @@ class AuthD::Service user.profile = profile end - - @users << user + user.date_registration = Time.local # Once the user is created and stored, we try to contact him unless Process.run("activation-mailer", [ @@ -223,6 +234,9 @@ class AuthD::Service return Response::Error.new "cannot contact the user (but still registered)" end + # add the user only if we were able to send the confirmation mail + @users << user + Response::UserAdded.new user.to_public when Request::UpdatePassword user = @users_per_login.get? request.login diff --git a/src/user.cr b/src/user.cr index d5aaf10..7188415 100644 --- a/src/user.cr +++ b/src/user.cr @@ -37,12 +37,14 @@ class AuthD::User property profile : JSON::Any? # Private. - property contact : Contact - property password_hash : String - property password_renew_key : String? + property contact : Contact + property password_hash : String + property password_renew_key : String? # service => resource => permission level - property permissions : Hash(String, Hash(String, PermissionLevel)) - property configuration : Hash(String, Hash(String, JSON::Any)) + property permissions : Hash(String, Hash(String, PermissionLevel)) + property configuration : Hash(String, Hash(String, JSON::Any)) + property date_last_connection : Time? = nil + property date_registration : Time? = nil def to_token Token.new @login, @uid