2
0

loginHandler.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. module.exports = {
  2. addGroups: function (user, groups){
  3. teamArray=[]
  4. teams = user.teams
  5. if (!teams)
  6. {
  7. for (group of groups){
  8. team = Team.findOne({"teamDisplayName": group});
  9. if (team)
  10. {
  11. team_hash = {'teamId': team._id, 'teamDisplayName': group}
  12. teamArray.push(team_hash);
  13. }
  14. }
  15. teams = {'teams': teamArray}
  16. users.update({ _id: user._id }, { $set: teams});
  17. return;
  18. }
  19. else{
  20. for (group of groups){
  21. team = Team.findOne({"teamDisplayName": group})
  22. team_contained= false;
  23. if (team)
  24. {
  25. team_hash = {'teamId': team._id, 'teamDisplayName': group}
  26. for (const [count,teams_hash] of Object.entries(teams))
  27. {
  28. if (teams_hash["teamId"] === team._id)
  29. {
  30. team_contained=true;
  31. break;
  32. }
  33. }
  34. if (team_contained)
  35. {
  36. continue;
  37. }
  38. else
  39. {
  40. console.log("TEAM to be added:", team);
  41. teams.push({'teamId': Team.findOne({'teamDisplayName': group})._id, 'teamDisplayName': group});
  42. }
  43. }
  44. }
  45. console.log("XXXXXXXXXXX Team Array: ", teams);
  46. teams = {'teams': teams}
  47. users.update({ _id: user._id }, { $set: teams});
  48. }
  49. },
  50. changeUsername: function(user, name)
  51. {
  52. username = {'username': name};
  53. if (user.username != username) users.update({ _id: user._id }, { $set: username});
  54. },
  55. changeFullname: function(user, name)
  56. {
  57. username = {'profile.fullname': name};
  58. if (user.username != username) users.update({ _id: user._id }, { $set: username});
  59. },
  60. addEmail: function(user, email)
  61. {
  62. user_email = user.emails || [];
  63. var contained = false;
  64. position = 0;
  65. for (const [count, mail_hash] of Object.entries(user_email))
  66. {
  67. if (mail_hash['address'] === email)
  68. {
  69. contained = true;
  70. position = count;
  71. break;
  72. }
  73. }
  74. if(contained && position != 0)
  75. {
  76. user_email.splice(position,1);
  77. contained = false;
  78. }
  79. if(!contained)
  80. {
  81. user_email.unshift({'address': email, 'verified': true});
  82. user_email = {'emails': user_email};
  83. console.log(user_email);
  84. users.update({ _id: user._id }, { $set: user_email});
  85. }
  86. }
  87. }