Recording user registration and last connection dates.

This commit is contained in:
Philippe PITTOLI 2020-03-23 06:54:45 +01:00
parent bd68148924
commit 189e22902e
2 changed files with 23 additions and 7 deletions

View File

@ -60,8 +60,12 @@ class AuthD::Service
return Response::Error.new "invalid credentials" return Response::Error.new "invalid credentials"
end end
user.date_last_connection = Time.local
token = user.to_token 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 Response::Token.new token.to_s @jwt_key
when Request::AddUser when Request::AddUser
# No verification of the users' informations when an admin adds it. # No verification of the users' informations when an admin adds it.
@ -90,6 +94,9 @@ class AuthD::Service
user.profile = profile user.profile = profile
end end
# We consider adding the user as a registration
user.date_registration = Time.local
@users << user @users << user
Response::UserAdded.new user.to_public Response::UserAdded.new user.to_public
@ -129,6 +136,11 @@ class AuthD::Service
return Response::Error.new "invalid credentials" return Response::Error.new "invalid credentials"
end 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 Response::User.new user.to_public
when Request::GetUser when Request::GetUser
uid_or_login = request.user uid_or_login = request.user
@ -209,8 +221,7 @@ class AuthD::Service
user.profile = profile user.profile = profile
end end
user.date_registration = Time.local
@users << user
# Once the user is created and stored, we try to contact him # Once the user is created and stored, we try to contact him
unless Process.run("activation-mailer", [ unless Process.run("activation-mailer", [
@ -223,6 +234,9 @@ class AuthD::Service
return Response::Error.new "cannot contact the user (but still registered)" return Response::Error.new "cannot contact the user (but still registered)"
end end
# add the user only if we were able to send the confirmation mail
@users << user
Response::UserAdded.new user.to_public Response::UserAdded.new user.to_public
when Request::UpdatePassword when Request::UpdatePassword
user = @users_per_login.get? request.login user = @users_per_login.get? request.login

View File

@ -43,6 +43,8 @@ class AuthD::User
# service => resource => permission level # service => resource => permission level
property permissions : Hash(String, Hash(String, PermissionLevel)) property permissions : Hash(String, Hash(String, PermissionLevel))
property configuration : Hash(String, Hash(String, JSON::Any)) property configuration : Hash(String, Hash(String, JSON::Any))
property date_last_connection : Time? = nil
property date_registration : Time? = nil
def to_token def to_token
Token.new @login, @uid Token.new @login, @uid