Simplification is done. Still some minor inconsistencies to fix.
This commit is contained in:
parent
af22ea8d18
commit
b98399e030
@ -6,6 +6,10 @@ class AuthD::Request
|
|||||||
end
|
end
|
||||||
|
|
||||||
def handle(authd : AuthD::Service, fd : Int32)
|
def handle(authd : AuthD::Service, fd : Int32)
|
||||||
|
logged_user = authd.get_logged_user? fd
|
||||||
|
return Response::Error.new "you must be logged" if logged_user.nil?
|
||||||
|
return Response::Error.new "unauthorized (not admin)" unless logged_user.admin
|
||||||
|
|
||||||
pattern = Regex.new @user, Regex::Options::IGNORE_CASE
|
pattern = Regex.new @user, Regex::Options::IGNORE_CASE
|
||||||
|
|
||||||
matching_users = Array(AuthD::User::Public).new
|
matching_users = Array(AuthD::User::Public).new
|
||||||
|
@ -1,23 +1,20 @@
|
|||||||
class AuthD::Request
|
class AuthD::Request
|
||||||
IPC::JSON.message ValidateUser, 2 do
|
IPC::JSON.message ValidateUser, 2 do
|
||||||
property login : String
|
property user : UserID
|
||||||
property activation_key : String
|
property activation_key : String
|
||||||
|
|
||||||
def initialize(@login, @activation_key)
|
def initialize(@user, @activation_key)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle(authd : AuthD::Service, fd : Int32)
|
def handle(authd : AuthD::Service, fd : Int32)
|
||||||
user = authd.users_per_login.get? @login
|
user = authd.user? @user
|
||||||
|
return Response::Error.new "user not found" if user.nil?
|
||||||
if user.nil?
|
|
||||||
return Response::Error.new "user not found"
|
|
||||||
end
|
|
||||||
|
|
||||||
if user.contact.activation_key.nil?
|
if user.contact.activation_key.nil?
|
||||||
return Response::Error.new "user already validated"
|
return Response::Error.new "user already validated"
|
||||||
end
|
end
|
||||||
|
|
||||||
# remove the user contact activation key: the email is validated
|
# Remove the user contact activation key: the email is validated.
|
||||||
if user.contact.activation_key == @activation_key
|
if user.contact.activation_key == @activation_key
|
||||||
user.contact.activation_key = nil
|
user.contact.activation_key = nil
|
||||||
else
|
else
|
||||||
@ -32,22 +29,14 @@ class AuthD::Request
|
|||||||
AuthD.requests << ValidateUser
|
AuthD.requests << ValidateUser
|
||||||
|
|
||||||
IPC::JSON.message GetUser, 3 do
|
IPC::JSON.message GetUser, 3 do
|
||||||
property user : Int32 | String
|
property user : UserID
|
||||||
|
|
||||||
def initialize(@user)
|
def initialize(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle(authd : AuthD::Service, fd : Int32)
|
def handle(authd : AuthD::Service, fd : Int32)
|
||||||
uid_or_login = @user
|
user = authd.user? @user
|
||||||
user = if uid_or_login.is_a? Int32
|
return Response::Error.new "user not found" if user.nil?
|
||||||
authd.users_per_uid.get? uid_or_login.to_s
|
|
||||||
else
|
|
||||||
authd.users_per_login.get? uid_or_login
|
|
||||||
end
|
|
||||||
|
|
||||||
if user.nil?
|
|
||||||
return Response::Error.new "user not found"
|
|
||||||
end
|
|
||||||
|
|
||||||
Response::User.new user.to_public
|
Response::User.new user.to_public
|
||||||
end
|
end
|
||||||
@ -63,10 +52,7 @@ class AuthD::Request
|
|||||||
|
|
||||||
def handle(authd : AuthD::Service, fd : Int32)
|
def handle(authd : AuthD::Service, fd : Int32)
|
||||||
user = authd.users_per_login.get? @login
|
user = authd.users_per_login.get? @login
|
||||||
|
return Response::Error.new "invalid credentials" unless user
|
||||||
unless user
|
|
||||||
return Response::Error.new "invalid credentials"
|
|
||||||
end
|
|
||||||
|
|
||||||
if authd.hash_password(@password) != user.password_hash
|
if authd.hash_password(@password) != user.password_hash
|
||||||
return Response::Error.new "invalid credentials"
|
return Response::Error.new "invalid credentials"
|
||||||
@ -74,7 +60,7 @@ class AuthD::Request
|
|||||||
|
|
||||||
user.date_last_connection = Time.local
|
user.date_last_connection = Time.local
|
||||||
|
|
||||||
# change the date of the last connection
|
# Change the date of the last connection.
|
||||||
authd.users_per_uid.update user.uid.to_s, user
|
authd.users_per_uid.update user.uid.to_s, user
|
||||||
|
|
||||||
Response::User.new user.to_public
|
Response::User.new user.to_public
|
||||||
|
Loading…
Reference in New Issue
Block a user