FEATURE: redeem Invite when user sign up
This commit is contained in:
parent
0de564f598
commit
b301391116
|
@ -57,6 +57,8 @@ class EmailToken < ActiveRecord::Base
|
||||||
user.save!
|
user.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
# redeem invite, if available
|
||||||
|
Invite.redeem_from_email(user.email)
|
||||||
user
|
user
|
||||||
rescue ActiveRecord::RecordInvalid
|
rescue ActiveRecord::RecordInvalid
|
||||||
# If the user's email is already taken, just return nil (failure)
|
# If the user's email is already taken, just return nil (failure)
|
||||||
|
|
|
@ -130,6 +130,14 @@ class Invite < ActiveRecord::Base
|
||||||
i
|
i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.redeem_from_email(email)
|
||||||
|
invite = Invite.find_by(email: Email.downcase(email))
|
||||||
|
if invite
|
||||||
|
InviteRedeemer.new(invite).redeem
|
||||||
|
end
|
||||||
|
invite
|
||||||
|
end
|
||||||
|
|
||||||
def self.base_directory
|
def self.base_directory
|
||||||
File.join(Rails.root, "public", "csv", RailsMultisite::ConnectionManagement.current_db)
|
File.join(Rails.root, "public", "csv", RailsMultisite::ConnectionManagement.current_db)
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,6 +19,10 @@ InviteRedeemer = Struct.new(:invite) do
|
||||||
|
|
||||||
# extracted from User cause it is very specific to invites
|
# extracted from User cause it is very specific to invites
|
||||||
def self.create_user_from_invite(invite)
|
def self.create_user_from_invite(invite)
|
||||||
|
|
||||||
|
user_exists = User.find_by_email(invite.email)
|
||||||
|
return user if user_exists
|
||||||
|
|
||||||
username = UserNameSuggester.suggest(invite.email)
|
username = UserNameSuggester.suggest(invite.email)
|
||||||
|
|
||||||
DiscourseHub.username_operation do
|
DiscourseHub.username_operation do
|
||||||
|
|
Loading…
Reference in New Issue