|
|
@ -179,11 +179,12 @@ Accounts.registerLoginHandler(function(options) { |
|
|
|
// First, look for a user that has logged in from CAS with this username before
|
|
|
|
// First, look for a user that has logged in from CAS with this username before
|
|
|
|
let user = Meteor.users.findOne({ 'services.cas.external_id': result.username }); |
|
|
|
let user = Meteor.users.findOne({ 'services.cas.external_id': result.username }); |
|
|
|
if (!user) { |
|
|
|
if (!user) { |
|
|
|
// If that user was not found, check if there's any CAS user that is currently using that username on Rocket.Chat
|
|
|
|
// If that user was not found, check if there's any Rocket.Chat user with that username
|
|
|
|
// With this, CAS login will continue to work if the user is renamed on both sides and also if the user is renamed only on Rocket.Chat.
|
|
|
|
// With this, CAS login will continue to work if the user is renamed on both sides and also if the user is renamed only on Rocket.Chat.
|
|
|
|
|
|
|
|
// It'll also allow non-CAS users to switch to CAS based login
|
|
|
|
if (trustUsername) { |
|
|
|
if (trustUsername) { |
|
|
|
const username = new RegExp(`^${ result.username }$`, 'i'); |
|
|
|
const username = new RegExp(`^${ result.username }$`, 'i'); |
|
|
|
user = Meteor.users.findOne({ 'services.cas.external_id': { $exists: true }, username }); |
|
|
|
user = Meteor.users.findOne({ username }); |
|
|
|
if (user) { |
|
|
|
if (user) { |
|
|
|
// Update the user's external_id to reflect this new username.
|
|
|
|
// Update the user's external_id to reflect this new username.
|
|
|
|
Meteor.users.update(user, { $set: { 'services.cas.external_id': result.username } }); |
|
|
|
Meteor.users.update(user, { $set: { 'services.cas.external_id': result.username } }); |
|
|
|