Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/cas/server/cas_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,12 @@ Accounts.registerLoginHandler(function(options) {
// 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 });
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.
// It'll also allow non-CAS users to switch to CAS based login
if (trustUsername) {
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) {
// Update the user's external_id to reflect this new username.
Meteor.users.update(user, { $set: { 'services.cas.external_id': result.username } });
Expand Down