-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invite link can't be used to log in after you set a password or sign …
…in with 3rd party
- Loading branch information
Showing
6 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,8 @@ class Invite < ActiveRecord::Base | |
def user_doesnt_already_exist | ||
@email_already_exists = false | ||
return if email.blank? | ||
if User.where("email = ?", Email.downcase(email)).exists? | ||
u = User.where("email = ?", Email.downcase(email)).first | ||
if u && u.id != self.user_id | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
nlalonde
Author
Member
|
||
@email_already_exists = true | ||
errors.add(:email) | ||
end | ||
|
@@ -40,8 +41,13 @@ def expired? | |
created_at < SiteSetting.invite_expiry_days.days.ago | ||
end | ||
|
||
# link_valid? indicates whether the invite link can be used to log in to the site | ||
def link_valid? | ||
invalidated_at.nil? | ||
end | ||
|
||
def redeem | ||
InviteRedeemer.new(self).redeem unless expired? || destroyed? | ||
InviteRedeemer.new(self).redeem unless expired? || destroyed? || !link_valid? | ||
end | ||
|
||
|
||
|
@@ -100,6 +106,15 @@ def self.filter_by(email_or_username) | |
rails4? ? all : scoped | ||
end | ||
end | ||
|
||
def self.invalidate_for_email(email) | ||
i = Invite.where(email: Email.downcase(email)).first | ||
if i | ||
i.invalidated_at = Time.zone.now | ||
i.save | ||
end | ||
i | ||
end | ||
end | ||
|
||
# == Schema Information | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddInvalidatedAtToInvites < ActiveRecord::Migration | ||
def change | ||
add_column :invites, :invalidated_at, :datetime | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
What's the purpose of this logic? Allowing users to invite themselves?