[FIX] CAS login not merging users with local accounts (#18238)

pull/18226/head^2
pierre-lehnen-rc 5 years ago committed by GitHub
parent 2e2c4cc2bb
commit d025656a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      app/cas/server/cas_server.js

@ -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 } });

Loading…
Cancel
Save