lib/lifen/user.rb in lifen-1.5.1 vs lib/lifen/user.rb in lifen-1.5.2
- old
+ new
@@ -10,19 +10,38 @@
attribute :email, String
attribute :last_name, String
attribute :first_name, String
attribute :profile_picture_url, String
+ @@create_lock = Mutex.new
+
def flows
Lifen::Flows.new(user: self).all
end
- def create
+ def create(persisted_lifen_uuid: ->(user) {}, save_to_db: ->(user) {})
+
params = {emailAddress: email, lastName: last_name, firstName: first_name, profilePicUrl: profile_picture_url}
- json = application_client.post("authentication/api/register/third_party", params)
+ @@create_lock.synchronize do
- self.uuid = json["accountUuid"]
+ exisiting_uuid = persisted_lifen_uuid.call(self)
+
+ if exisiting_uuid.nil?
+
+ json = application_client.post("authentication/api/register/third_party", params)
+
+ self.uuid = json["accountUuid"]
+
+ else
+
+ self.uuid = exisiting_uuid
+
+ end
+
+ save_to_db.call(self)
+ end
+
end
def self.find(uuid)
json = application_client.get("docbook/api/thirdParty/person/#{uuid}")
\ No newline at end of file