standard_id 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e7f12cdcd431146c994f1ae5b1bf0919357fc7abf8e3668d13363e22eb421fe0
|
|
4
|
+
data.tar.gz: 2017963a39eb1430206fdc8ebf8354c12fc9fa46b755a7706452cb06ac6352b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 61b5e5a16dca753e8128300fb88b37e931252f05e73cfccc5fbc7467e4c58eca7435bc004877eca56c59305310de40c56b0491856cc173cddd5c815bf72b42c9
|
|
7
|
+
data.tar.gz: 1af3914e27993f6a51bb15fc821f40c8bd2095744e0187b107a2273ca70ab006e4c9a5522c3001db6f7f1240345e744fc7805ba5970410f2f263382bbb8c36cd
|
|
@@ -10,5 +10,48 @@ module StandardId
|
|
|
10
10
|
|
|
11
11
|
accepts_nested_attributes_for :identifiers
|
|
12
12
|
end
|
|
13
|
+
|
|
14
|
+
class_methods do
|
|
15
|
+
def find_or_create_by_verified_email!(email, **account_attributes)
|
|
16
|
+
raise ArgumentError, "email is required" if email.blank?
|
|
17
|
+
|
|
18
|
+
normalized_email = email.to_s.strip.downcase
|
|
19
|
+
|
|
20
|
+
identifier = StandardId::EmailIdentifier.includes(:account).find_by(value: normalized_email)
|
|
21
|
+
return identifier.account if identifier.present?
|
|
22
|
+
|
|
23
|
+
# Best-effort intent signal — fires before create! so subscribers may see
|
|
24
|
+
# ACCOUNT_CREATING without a matching ACCOUNT_CREATED if create! raises.
|
|
25
|
+
StandardId::Events.publish(
|
|
26
|
+
StandardId::Events::ACCOUNT_CREATING,
|
|
27
|
+
email: normalized_email,
|
|
28
|
+
source: "find_or_create_by_verified_email"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
merged_attributes = account_attributes.dup
|
|
32
|
+
merged_attributes[:email] = normalized_email if column_names.include?("email") && !merged_attributes.key?(:email)
|
|
33
|
+
|
|
34
|
+
account = create!(
|
|
35
|
+
**merged_attributes,
|
|
36
|
+
identifiers_attributes: [
|
|
37
|
+
{ type: "StandardId::EmailIdentifier", value: normalized_email, verified_at: Time.current }
|
|
38
|
+
]
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
StandardId::Events.publish(
|
|
42
|
+
StandardId::Events::ACCOUNT_CREATED,
|
|
43
|
+
account: account,
|
|
44
|
+
email: normalized_email,
|
|
45
|
+
source: "find_or_create_by_verified_email"
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
account
|
|
49
|
+
rescue ActiveRecord::RecordNotUnique
|
|
50
|
+
identifier = StandardId::EmailIdentifier.includes(:account).find_by(value: normalized_email)
|
|
51
|
+
raise unless identifier
|
|
52
|
+
|
|
53
|
+
identifier.account
|
|
54
|
+
end
|
|
55
|
+
end
|
|
13
56
|
end
|
|
14
57
|
end
|
|
@@ -12,11 +12,7 @@ module StandardId
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def find_or_create_account!(email)
|
|
15
|
-
|
|
16
|
-
return identifier.account if identifier.present?
|
|
17
|
-
|
|
18
|
-
identifiers_attributes = [{ type: "StandardId::EmailIdentifier", value: email, verified_at: Time.current }]
|
|
19
|
-
Account.create!(identifiers_attributes:)
|
|
15
|
+
Account.find_or_create_by_verified_email!(email)
|
|
20
16
|
end
|
|
21
17
|
|
|
22
18
|
def sender_callback
|
data/lib/standard_id/version.rb
CHANGED