Implement the basic interface for the Authentication endpoint

* Handle errors as 422
* Require parameters through strong_parameters
* Use a custom rescue_from
This commit is contained in:
Maciej Szlosarczyk 2018-07-19 11:50:40 +03:00
parent 1c6b838b2b
commit dad57ba528
No known key found for this signature in database
GPG key ID: 41D62D42D3B0D765
4 changed files with 35 additions and 11 deletions

View file

@ -53,10 +53,14 @@ class RegistrantUser < User
end
def find_or_create_by_api_data(api_data = {})
return false unless api_data[:ident]
return false unless api_data[:first_name]
return false unless api_data[:last_name]
estonian_ident = "EE-#{api_data[:ident]}"
user = find_or_create_by(registrant_ident: estonian_ident)
user.username = "#{api_data[:first_name]}, #{api_data[:last_name]}"
user.username = "#{api_data[:first_name]} #{api_data[:last_name]}"
user.save
user