message: Try lowercase username on login
  Fixes
diff: @@ -143,23 +143,34 @@ export default class Login {
  Object.assign(loginParams, legacyParams);
  const client = this._createTemporaryClient();
  - return client.login('m.login.password', loginParams).then(function(data) {
  +
  + const tryFallbackHs = (originalError) => {
  + const fbClient = Matrix.createClient({
  + baseUrl: self._fallbackHsUrl,
  + idBaseUrl: this._isUrl,
  + });
  +
  + return fbClient.login('m.login.password', loginParams).then(function(data) {
  return Promise.resolve({
  - homeserverUrl: self._hsUrl,
  + homeserverUrl: self._fallbackHsUrl,
  identityServerUrl: self._isUrl,
  userId: data.user_id,
  deviceId: data.device_id,
  accessToken: data.access_token,
  });
  - }, function(error) {
  - if (error.httpStatus === 403) {
  - if (self._fallbackHsUrl) {
  - const fbClient = Matrix.createClient({
  - baseUrl: self._fallbackHsUrl,
  - idBaseUrl: this._isUrl,
  + }, function(fallback_error) {
  + // throw the original error
  + throw originalError;
  });
  -
  - return fbClient.login('m.login.password', loginParams).then(function(data) {
  + };
  + const tryLowercaseUsername = (originalError) => {
  + const loginParamsLowercase = Object.assign({}, loginParams, {
  + user: username.toLowerCase(),
  + identifier: {
  + user: username.toLowerCase(),
  + },
  + });
  + return client.login('m.login.password', loginParamsLowercase).then(function(data) {
  return Promise.resolve({
  homeserverUrl: self._fallbackHsUrl,
  identityServerUrl: self._isUrl,
  @@ -169,11 +180,36 @@ export default class Login {
  });
  }, function(fallback_error) {
  // throw the original error
  - throw error;
  + throw originalError;
  + });
  + };
  +
  + let originalLoginError = null;
  + return client.login('m.login.password', loginParams).then(function(data) {
  + return Promise.resolve({
  + homeserverUrl: self._hsUrl,
  + identityServerUrl: self._isUrl,
  + userId: data.user_id,
  + deviceId: data.device_id,
  + accessToken: data.access_token,
  });
  + }).catch((error) => {
  + originalLoginError = error;
  + if (error.httpStatus === 403) {
  + if (self._fallbackHsUrl) {
  + return tryFallbackHs(originalLoginError);
  }
  }
  - throw error;
  + throw originalLoginError;
  + }).catch((error) => {
  + if (
  + error.httpStatus === 403 &&
  + loginParams.identifier.type === 'm.id.user' &&
  + username.search(/[A-Z]/) > -1
  + ) {
  + return tryLowercaseUsername(originalLoginError);
  + }
  + throw originalLoginError;
  });
  }
  