How to use the meteor/meteor.Meteor.methods function in meteor

To help you get started, we’ve selected a few meteor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github meteor / todos / imports / api / generate-data.app-tests.js View on Github external
import { Meteor } from 'meteor/meteor';
import { Factory } from 'meteor/dburles:factory';
import { resetDatabase } from 'meteor/xolvio:cleaner';
import { Random } from 'meteor/random';
import { _ } from 'meteor/underscore';

import { denodeify } from '../utils/denodeify';

const createList = (userId) => {
  const list = Factory.create('list', { userId });
  _.times(3, () => Factory.create('todo', { listId: list._id }));
  return list;
};

Meteor.methods({
  generateFixtures() {
    resetDatabase();

    // create 3 public lists
    _.times(3, () => createList());

    // create 3 private lists
    _.times(3, () => createList(Random.id()));
  },
});

if (Meteor.isClient) {
  // Create a second connection to the server to use to call test data methods
  // We do this so there's no contention w/ the currently tested user's connection
  const testConnection = Meteor.connect(Meteor.absoluteUrl());
github studiointeract / accounts-ui / imports / api / server / loginWithoutPassword.js View on Github external
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

///
/// LOGIN WITHOUT PASSWORD
///

// Method called by a user to request a password reset email. This is
// the start of the reset process.
Meteor.methods({
  loginWithoutPassword: function ({ email, username = null }) {
    if (username !== null) {
      check(username, String);

      var user = Meteor.users.findOne({ $or: [{
          "username": username, "emails.address": { $exists: 1 }
        }, {
          "emails.address": email
        }]
      });
      if (!user)
        throw new Meteor.Error(403, "User not found");

      email = user.emails[0].address;
    }
    else {
github Urigo / meteor-angular-socially / imports / api / parties / methods.ts View on Github external
});
  } else {
    // update rsvp entry
    const userId = this.userId;
    Parties.update({
      _id: partyId,
      'rsvps.user': userId
    }, {
      $set: {
        'rsvps.$.rsvp': rsvp
      }
    });
  }
}

Meteor.methods({
  invite,
  rsvp
});
github RocketChat / Rocket.Chat / app / emoji-custom / server / methods / insertOrUpdateEmoji.js View on Github external
import { Meteor } from 'meteor/meteor';
import _ from 'underscore';
import s from 'underscore.string';
import limax from 'limax';

import { hasPermission } from '../../../authorization';
import { Notifications } from '../../../notifications';
import { EmojiCustom } from '../../../models';
import { RocketChatFileEmojiCustomInstance } from '../startup/emoji-custom';

Meteor.methods({
	insertOrUpdateEmoji(emojiData) {
		if (!hasPermission(this.userId, 'manage-emoji')) {
			throw new Meteor.Error('not_authorized');
		}

		if (!s.trim(emojiData.name)) {
			throw new Meteor.Error('error-the-field-is-required', 'The field Name is required', { method: 'insertOrUpdateEmoji', field: 'Name' });
		}

		emojiData.name = limax(emojiData.name, { replacement: '_' });
		emojiData.aliases = limax(emojiData.aliases, { replacement: '_' });

		// allow all characters except colon, whitespace, comma, >, <, &, ", ', /, \, (, )
		// more practical than allowing specific sets of characters; also allows foreign languages
		const nameValidation = /[\s,:><&"'\/\\\(\)]/;
		const aliasValidation = /[:><&\|"'\/\\\(\)]/;
github 4minitz / 4minitz / imports / collections / users_private.js View on Github external
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
import { check, Match } from 'meteor/check';

import { AdminRegisterUserMailHandler } from '/imports/mail/AdminRegisterUserMailHandler';
import { emailAddressRegExpTest } from '/imports/helpers/email';
import { checkWithMsg } from '/imports/helpers/check';

Meteor.methods({
    'users.saveSettings'(settings) {
        const id = Meteor.userId();
        Meteor.users.update(id, { $set: {settings} });
        console.log(`saved settings for user ${id}: ${settings}`);
    },

    'users.editProfile'(userId, eMail, longName) {
        check(eMail, String);
        check(longName, String);
        if (! Meteor.userId()) {
            throw new Meteor.Error('Cannot edit profile', 'User not logged in.');
        }

        if (!Meteor.user().isAdmin) {
            if (Meteor.userId() !== userId) {
                throw new Meteor.Error('Cannot edit profile', 'You are not admin or you are trying to change someone else\'s profile');
github Blockrazor / blockrazor / imports / api / wallet / methods.js View on Github external
import { Meteor } from 'meteor/meteor'
import { Wallet, WalletImages, Currencies, Ratings, Bounties, REWARDCOEFFICIENT } from '/imports/api/indexDB.js'
import { creditUserWith, removeUserCredit } from '/imports/api/utilities.js'
import { sendMessage } from '/imports/api/activityLog/methods'
import { log } from '/imports/api/utilities'

Meteor.methods({
	initializeWallet: function() {
		if (_.size(Wallet.findOne({owner: this.userId})) == 0) {
			Wallet.insert({
				time: new Date().getTime(),
				owner: this.userId,
        type: "welcome",
        read: false,
				from: "System",
				message: "Welcome to Blockrazor! Your wallet has been created. Why not head over to the Bounty list and earn your first Rozar!",
				amount: 0
			})
		}
    },

	getWalletReward: (userId, rId) => {
        let bounty = Bounties.findOne({
github SparkEdUAB / SparkEd / imports / api / settings / methods.js View on Github external
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { _Settings } from './settings';
import { _Slides, Slides } from './slides';
import { Institution } from './institution';
import { Titles } from './titles';

Meteor.methods({
  addSliding(id, sku, file) {
    check(id, String);
    check(sku, String);
    check(file, Object);
    if (Roles.userIsInRole(this.userId, ['admin'])) {
      _Slides.insert({
        name: sku,
        file,
        createdAt: new Date(),
        CreatedBy: this.userId,
      });
    } else {
      throw new Meteor.Error('oops', 'You are not allowed to not make changes');
    }
  },
github cesarve77 / simple-chat / methods_server.js View on Github external
/**
 * Created by cesar on 23/2/16.
 */
import {Meteor} from 'meteor/meteor'
import {check} from 'meteor/check'
import {Chats} from './collections'
import {Rooms} from './collections'
import {SimpleChat} from './config'

//todo improve security, for now any body con access to this methods and potentially change the data  (off messages recieved or room joins no a big deal but have to be fixed)
Meteor.methods({
    "SimpleChat.messageReceived": function (id, username) {

        check(id, String)
        check(id, username)

        this.unblock()
        if (!SimpleChat.options.showReceived) return false

        Meteor._sleepForMs(800 * Meteor.isDevelopment)
        const message = Chats.findOne(id, {fields: {roomId: 1, receivedBy: 1}})
        if (!message)
            throw Meteor.Error(403, "Message does not exist")
        const room = Rooms.findOne(message.roomId)
        if (!_.contains(message.receivedBy, username)) {
            return Chats.update(id, {
                $addToSet: {receivedBy: username},
github RocketChat / Rocket.Chat / packages / rocketchat-cloud / server / methods.js View on Github external
import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import { hasPermission } from 'meteor/rocketchat:authorization';
import { Settings } from 'meteor/rocketchat:models';

import { retrieveRegistrationStatus } from './functions/retrieveRegistrationStatus';
import { connectWorkspace } from './functions/connectWorkspace';
import { getOAuthAuthorizationUrl } from './functions/getOAuthAuthorizationUrl';
import { finishOAuthAuthorization } from './functions/finishOAuthAuthorization';

Meteor.methods({
	'cloud:checkRegisterStatus'() {
		if (!Meteor.userId()) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cloud:checkRegisterStatus' });
		}

		if (!hasPermission(Meteor.userId(), 'manage-cloud')) {
			throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'cloud:checkRegisterStatus' });
		}

		return retrieveRegistrationStatus();
	},
	'cloud:updateEmail'(email) {
		check(email, String);

		if (!Meteor.userId()) {
			throw new Meteor.Error('error-invalid-user', 'Invalid user', { method: 'cloud:updateEmail' });