All explicit errors in requests are now dedicated errors.
This commit is contained in:
parent
71cbb1d519
commit
b047a3fd6f
@ -59,7 +59,7 @@ class AuthD::Request
|
||||
def handle(authd : AuthD::Service, fd : Int32)
|
||||
# Check if there already is a registered user.
|
||||
if authd.users.to_a.size > 0
|
||||
return Response::Error.new "already users in the database"
|
||||
return Response::ErrorAlreadyUsersInDB.new
|
||||
end
|
||||
|
||||
password_hash = authd.hash_password @password
|
||||
|
@ -63,7 +63,7 @@ class AuthD::Request
|
||||
if user.password_renew_key == @password_renew_key
|
||||
user.password_hash = authd.hash_password @new_password
|
||||
else
|
||||
return Response::Error.new "renew key not valid"
|
||||
return Response::ErrorInvalidRenewKey.new
|
||||
end
|
||||
|
||||
user.password_renew_key = nil
|
||||
|
@ -22,14 +22,19 @@ class AuthD::Request
|
||||
|
||||
new_profile_entries = user.profile || Hash(String, JSON::Any).new
|
||||
|
||||
invalid_profile_keys = Array(String).new
|
||||
unless logged_user.admin
|
||||
authd.configuration.read_only_profile_keys.each do |key|
|
||||
if @new_profile_entries.has_key? key
|
||||
return Response::Error.new "tried to edit read only key"
|
||||
invalid_profile_keys << key
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if invalid_profile_keys.size > 0
|
||||
return Response::ErrorReadOnlyProfileKeys.new invalid_profile_keys
|
||||
end
|
||||
|
||||
@new_profile_entries.each do |key, value|
|
||||
new_profile_entries[key] = value
|
||||
end
|
||||
|
@ -31,9 +31,7 @@ class AuthD::Request
|
||||
result = grok.parse @email.not_nil!
|
||||
email = result["email"]?
|
||||
|
||||
if email.nil?
|
||||
return Response::ErrorInvalidEmailFormat.new
|
||||
end
|
||||
return Response::ErrorInvalidEmailFormat.new if email.nil?
|
||||
end
|
||||
|
||||
# In this case we should not accept its registration.
|
||||
@ -72,7 +70,7 @@ class AuthD::Request
|
||||
end
|
||||
rescue e
|
||||
Baguette::Log.error "mailer: #{e}"
|
||||
return Response::Error.new "cannot contact the user (not registered)"
|
||||
return Response::ErrorCannotContactUser.new
|
||||
end
|
||||
|
||||
# add the user only if we were able to send the confirmation mail
|
||||
|
@ -13,14 +13,14 @@ class AuthD::Request
|
||||
return Response::ErrorUserNotFound.new if user.nil?
|
||||
|
||||
if user.contact.activation_key.nil?
|
||||
return Response::Error.new "user already validated"
|
||||
return Response::ErrorUserAlreadyValidated.new
|
||||
end
|
||||
|
||||
# Remove the user contact activation key: the email is validated.
|
||||
if user.contact.activation_key == @activation_key
|
||||
user.contact.activation_key = nil
|
||||
else
|
||||
return Response::Error.new "wrong activation key"
|
||||
return Response::ErrorInvalidActivationKey.new
|
||||
end
|
||||
|
||||
authd.users_per_uid.update user.uid.to_s, user
|
||||
|
@ -65,4 +65,41 @@ class AuthD::Response
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorInvalidCredentials
|
||||
|
||||
IPC::JSON.message ErrorReadOnlyProfileKeys, 30 do
|
||||
property read_only_keys : Array(String)
|
||||
def initialize(@read_only_keys)
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorReadOnlyProfileKeys
|
||||
|
||||
IPC::JSON.message ErrorInvalidActivationKey, 31 do
|
||||
def initialize()
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorInvalidActivationKey
|
||||
|
||||
IPC::JSON.message ErrorUserAlreadyValidated, 32 do
|
||||
def initialize()
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorUserAlreadyValidated
|
||||
|
||||
IPC::JSON.message ErrorCannotContactUser, 33 do
|
||||
def initialize()
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorCannotContactUser
|
||||
|
||||
IPC::JSON.message ErrorInvalidRenewKey, 34 do
|
||||
def initialize()
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorInvalidRenewKey
|
||||
|
||||
IPC::JSON.message ErrorAlreadyUsersInDB, 35 do
|
||||
def initialize()
|
||||
end
|
||||
end
|
||||
AuthD.responses << ErrorAlreadyUsersInDB
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user