Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 1 addition & 11 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,4 @@ proxy_backends/collection/permissions.js
proxy_backends/collection/regex.js
proxy_backends/collection/schema.js
proxy_backends/collection/server/publications.js
proxy_backends/server/methods.js
users/client/account/account.js
users/client/account/password/autoform.js
users/client/lib/accounts_config.js
users/collection/roles_schema.js
users/collection/server/publications.js
users/collection/users_permissions.js
users/server/accounts_hooks.js
users/server/login_verify.js
users/server/methods.js
users/server/startup_roles.js
proxy_backends/server/methods.js
1 change: 1 addition & 0 deletions users/client/account/account.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Modal } from 'meteor/peppelg:bootstrap-3-modal';
import { Template } from 'meteor/templating';

Template.account.events({
Expand Down
9 changes: 7 additions & 2 deletions users/client/account/password/autoform.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { Accounts } from 'meteor/accounts-base';
import { AutoForm } from 'meteor/aldeed:autoform';
import { TAPi18n } from 'meteor/tap:i18n';
import { sAlert } from 'meteor/juliancwirko:s-alert';

AutoForm.hooks({
updatePassword: {
onSubmit (insertDoc, updateDoc, currentDoc) {
onSubmit (insertDoc) {
this.event.preventDefault();
const instance = this;
Accounts.changePassword(insertDoc.old, insertDoc.new, function (error) {
Accounts.changePassword(insertDoc.old, insertDoc.new, (error) => {
$('.btn-primary').attr('disabled', null);
if (error) {
// Alert the user of failure
Expand Down
2 changes: 2 additions & 0 deletions users/client/lib/accounts_config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { AccountsTemplates } from 'meteor/useraccounts:core';

// User accounts guide
// https://github.com/meteor-useraccounts/core/blob/master/Guide.md
AccountsTemplates.configure({
Expand Down
3 changes: 3 additions & 0 deletions users/collection/roles_schema.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { Meteor } from 'meteor/meteor';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';

const RolesSchema = new SimpleSchema({
name: {
type: String,
Expand Down
13 changes: 9 additions & 4 deletions users/collection/server/publications.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';

import Apis from '/apis/collection';

Meteor.publish('allUsersUsernamesOnly', function () {
Meteor.publish('allUsersUsernamesOnly', () => {
return Meteor.users.find({}, { fields: { username: 1 } });
});

// TODO: determine whether this publication is used
// If it is used, refactor it to be a regular publication
Meteor.publishComposite('user', function () {
Meteor.publishComposite('user', () => {
return {
find () {
return Meteor.users.find({
Expand All @@ -17,12 +19,15 @@ Meteor.publishComposite('user', function () {
};
});

Meteor.publish('apiAuthorizedUsersPublicDetails', function (apiId) {
Meteor.publish('apiAuthorizedUsersPublicDetails', (apiId) => {
// Make sure apiId is a String
check(apiId, String);

// Get API document
const api = Apis.findOne(apiId);

// Return all authorized user documents
return Meteor.users.find({_id: {$in: api.authorizedUserIds } },
return Meteor.users.find({ _id: { $in: api.authorizedUserIds } },
{ fields: { username: 1, emails: 1, _id: 1 } }
);
});
6 changes: 3 additions & 3 deletions users/collection/users_permissions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Meteor } from 'meteor/meteor';

Meteor.users.allow({
update (currentUserId, user) {
// Only allow user to update own username
if (currentUserId === user._id) {
return true;
}
return (currentUserId === user._id);
},
});
2 changes: 1 addition & 1 deletion users/server/accounts_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Accounts.onCreateUser((options, user) => {
];
// Search 'githubUsername' from database.
const githubUsername = user.services.github.username;
const existingUser = Meteor.users.findOne({ 'username': githubUsername });
const existingUser = Meteor.users.findOne({ username: githubUsername });
if (existingUser === undefined) {
// Username available, set username to Github username.
user.username = githubUsername;
Expand Down
5 changes: 3 additions & 2 deletions users/server/login_verify.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Meteor } from 'meteor/meteor';
import { TAPi18n } from 'meteor/tap:i18n';
import { Roles } from 'meteor/alanning:roles';
import { _ } from 'lodash';

import Settings from '/settings/collection';
import { mailSettingsValid } from '/core/helper_functions/validate_settings';

import { _ } from 'lodash';

// Login attempt verifier to require verified email before login
export function loginAttemptVerifier (parameters) {
export default function loginAttemptVerifier (parameters) {
// Init user login allowed
let userLoginAllowed = false;

Expand Down
23 changes: 19 additions & 4 deletions users/server/methods.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import { ValidEmail } from 'meteor/froatsnook:valid-email';
import { check } from 'meteor/check';

import Settings from '/settings/collection';

Meteor.methods({
deleteAccount (userId) {
// Make sure userId is a String
check(userId, String);

let user;
if (this.userId === userId) {
return Meteor.users.remove({
user = Meteor.users.remove({
_id: this.userId,
});
}
return user;
},
checkIfEmailIsRegistered (email) {
// Make sure email is a valid email
check(email, ValidEmail);

// Get any user with matching email
const user = Accounts.findUserByEmail(email);

Expand All @@ -25,13 +37,16 @@ Meteor.methods({

return emailIsRegistered;
},
sendRegistrationEmailVerification( userId ) {
sendRegistrationEmailVerification (userId) {
// Make sure userId is a String
check(userId, String);

// Get settings
const settings = Settings.findOne();

// Check mail settings have been enabled
if(settings && settings.mail && settings.mail.enabled) {
Accounts.sendVerificationEmail( userId );
if (settings && settings.mail && settings.mail.enabled) {
Accounts.sendVerificationEmail(userId);
}
},
});
3 changes: 2 additions & 1 deletion users/server/startup.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Accounts } from 'meteor/accounts-base';
import { Meteor } from 'meteor/meteor';
import { loginAttemptVerifier } from './login_verify';

import loginAttemptVerifier from './login_verify';

Meteor.startup(() => {
// In case of server restart, we need to set MAIL_URL
Expand Down
2 changes: 1 addition & 1 deletion users/server/startup_roles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Meteor.startup(() => {
const roles = Roles.getAllRoles().fetch();

// Create an array of role names
const roleNames = _.map(roles, (role) => role.name);
const roleNames = _.map(roles, (role) => { return role.name; });

// Check if 'manager' role is defined
const managerRoleIsDefined = _.includes(roleNames, 'manager');
Expand Down