summaryrefslogtreecommitdiff
path: root/app/models/account.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/account.rb')
-rw-r--r--app/models/account.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/app/models/account.rb b/app/models/account.rb
index 32ed445..67fec58 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -16,11 +16,21 @@ class Account
# Returns the user record so it can be used in views.
def self.create(attrs)
- @user = User.create(attrs)
+ @user = User.new(attrs)
+ @user.save
if @user.persisted?
- identity = @user.identity
- identity.user_id = @user.id
- identity.save
+ @identity = @user.identity
+ @identity.user_id = @user.id
+ @identity.save
+ @identity.errors.each do |attr, msg|
+ @user.errors.add(attr, msg)
+ end
+ end
+ rescue StandardError => ex
+ @user.errors.add(:base, ex.to_s)
+ ensure
+ if @user && @user.persisted? && (@identity.nil? || !@identity.persisted?)
+ @user.destroy
end
return @user
end