<commit_before>// import { Meteor } from 'meteor/meteor';
// import { Accounts } from 'meteor/accounts-base';

/* eslint-disable no-console */

/* Validate username, sending a specific error message on failure. */
// Accounts.validateNewUser(function validate(user) {
//   if (user) {
//     if (user.services.cas) {
//       const username = user.services.cas.id;
//       if (username && ValidUserAccounts.find({ username }).count() > 0) {
//         return true;
//       }
//       throw new Meteor.Error(403, 'User not in the allowed list');
//     } else if (user.services.password) {
//       const username = user.username;
//       if (username && ValidUserAccounts.find({ username }).count() > 0) {
//         return true;
//       }
//       throw new Meteor.Error(403, 'User not in the allowed list');
//     }
//   }
//   throw new Meteor.Error(403, 'User not in the allowed list');
// });


// Meteor.users.allow({
//   insert: function insert(userId, doc) {  // eslint-disable-line no-unused-vars
//     // Normally I would check if (this.userId) to see if the method is called by logged in user or guest
//     // you can also add some checks here like user role based check etc.,
//     return true;
//   },
//   update: function update(userId, doc, fieldNames, modifier) {  // eslint-disable-line no-unused-vars
//   // similar checks like insert
//     return true;
//   },
//   remove: function remove(userId, doc) {  // eslint-disable-line no-unused-vars
//     // similar checks like insert
//     return true;
//   },
// });

// Accounts.onCreateUser((options, user) => {
//   console.log('in on create user', user);
//   return user;
// });<commit_msg>Working on improving login.<commit_after>import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { Users } from '/imports/api/user/UserCollection';

/* eslint-disable no-console, no-param-reassign */

const errorMessage = 'User not registered with RadGrad.';

/* Make sure that the person attempting to login has a profile. Otherwise they are not logged in. */
Accounts.validateNewUser(function validate(user) {
  if (user) {
    if (user.services.cas) {
      const username = user.services.cas.id;
      if (username && Users.hasProfile(username)) {
        return true;
      }
      throw new Meteor.Error(403, errorMessage);
    } else if (user.services.password) {
      const username = user.username;
      if (username && Users.hasProfile(username)) {
        return true;
      }
      throw new Meteor.Error(403, errorMessage);
    }
  }
  throw new Meteor.Error(403, errorMessage);
});

// // THIS CODE DOES NOT WORK, SO IT IS COMMENTED OUT.
// // IT IS AN ATTEMPT TO ALLOW MIXED CASE LOGINS THROUGH CAS
// /* Make sure that the username is all lower case. */
// Accounts.onCreateUser((options, user) => {
//   if (user) {
//     if (user.services && user.services.cas) {
//       user.services.cas.id = user.services.cas.id.toLowerCase();
//     }
//     if (user.username) {
//       user.username = user.username.toLowerCase();
//     }
//   }
//   if (options.profile) {
//     user.profile = options.profile;
//     if (user.profile.name) {
//       user.profile.name = user.profile.name.toLowerCase();
//     }
//   }
//   return user;
// });


// Meteor.users.allow({
//   insert: function insert(userId, doc) {  // eslint-disable-line no-unused-vars
//     // Normally I would check if (this.userId) to see if the method is called by logged in user or guest
//     // you can also add some checks here like user role based check etc.,
//     return true;
//   },
//   update: function update(userId, doc, fieldNames, modifier) {  // eslint-disable-line no-unused-vars
//   // similar checks like insert
//     return true;
//   },
//   remove: function remove(userId, doc) {  // eslint-disable-line no-unused-vars
//     // similar checks like insert
//     return true;
//   },
// });

// Accounts.onCreateUser((options, user) => {
//   console.log('in on create user', user);
//   return user;
// });
{'fraction_non_alphanumeric': 0.15626547795938583, 'fraction_numerical': 0.004952947003467063, 'mean_word_length': 2.4199830651989838, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4137072', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1236, 'n_words': 362}