Esempio n. 1
0
app.post("/sendPasswordReset", (req, res) => {
	console.log("Sending password reset email to: " + req.body.email);

	var subject = "Password Reset";

	var body = "Click the link below to reset your password.";

	// build hash for password reset link

	var query = new Parse.Query("User");
	query.equalTo("username", req.body.email);

	query.first({
		success (user) {
			var toHash = user.getUsername() + user.get("createdAt") + user.id + "passReset";
			var hash = md5(toHash);

			var link = "http://localhost:3000/#/changePassword/" + req.body.email + "/" + hash;

			mailAdapter.sendEmail(req.body.email, subject, body, link).then(
				() => {
					res.send("Password reset email sent successfully.");
				},
				() => {
					res.send("Error: Password reset email failed.");
				}
			);
		},
		error (err) {
			// if hash fails to build, fail out of the webhook
			console.log("Hash build failed, exiting webhook.");
			return console.log(err);
		}
	});
});
Esempio n. 2
0
 }).then(function() {
   var query = new Parse.Query('BeforeSaveChanged');
   return query.get(obj.id).then(function(objAgain) {
     expect(objAgain.get('foo')).toEqual('baz');
     done();
   });
 }, function(error) {
Esempio n. 3
0
app.get('/verify', (req, res) => {
	var result = req.query.email + '<br />' + req.query.hash + '<br />';

	var User = Parse.Object.extend("User");
	var query = new Parse.Query(User);

	query.equalTo("username", req.query.email);

	query.find({
		success(data) {
			var user = data[0];
			result += 'Attempting to verify... <br />';

			// test a new hash straight from parse against the link's hash
			var parseHash = md5(user.get("username") + user.get("createdAt") + user.id);
			var verifyMatch = req.query.hash === parseHash;

			if (verifyMatch) {
				// use master key to update account (since Node isn't logged in)
				Parse.Cloud.useMasterKey();
				user.set("verified", true);
				result += "Verification passed.";
				user.save();
			} else {
				result += "Verification failed.";
			}

			res.send(result);
		}
	});
});
Esempio n. 4
0
app.get('/resetpassword', (req, res) => {
	var email = req.query.email, hash = req.query.hash;

	var User = Parse.Object.extend("User");
	var query = new Parse.Query(User);

	query.equalTo("username", email);

	query.find({
		success (data) {
			var user = data[0];

			var toHash = email + user.get("createdAt") + user.id + "cattyPassphrase";
			var parseHash = md5(toHash);

			if (parseHash === hash){
				// if hash is correct, send user along (w/ query params) to the next step
				res.redirect('/choosepassword?email=' + email + '&hash=' + hash);
			} else {
				// else, send the user to an invalid link page
				res.sendFile(__dirname + '/client/html/invalid-link.html');
			}
		}
	});
});
Esempio n. 5
0
app.post('/choosepassword', bodyParser.urlencoded({extended: false}), (req, res) => {
	// check if passwords match; should actually happen before submitting the password
	if (req.body.password !== req.body.confirm) {
		res.send('Passwords do not match.');
	}

	var User = Parse.Object.extend("User");
	var query = new Parse.Query(User);

	query.equalTo("username", req.body.email);

	query.find({
		success (data) {
			var user = data[0];

			var toHash = req.body.email + user.get("createdAt") + user.id + "cattyPassphrase";
			var parseHash = md5(toHash);

			// test new parse hash and link hash against each other
			if (parseHash === req.body.hash) {
				console.log('Updating user.');
				Parse.Cloud.useMasterKey();
				user.set("password", req.body.password);
				user.save().then(() => {console.log('success, password changed to ' + req.body.password)})
			} else {
				console.log('Hash does not match.');
			}
		}
	});

	res.redirect('/');
});
Esempio n. 6
0
router.post('/removeProduce', function(req, res, next) {
  console.log("prdocuer: " + req.body.producerId);
  console.log("produce: " + req.body.produceId);
  // Finds the Produce class in Parse
  var Produce = Parse.Object.extend("Produce");
  // Creates a Query based on the Produce class
  var query = new Parse.Query(Produce);
  
  // Gets a single row based on ID
  query.get(req.body.produceId, {
    success: function(produce) {
      produce.destroy({
        success: function(produce) {
          res.redirect('/farm/' + req.body.producerId);
        },
        error: function(produce, error) {
          // Couldn't delete the produce. Displays the error
          console.log(error);
          res.render('error', {message: error.message, error: error});          
        }
      });
    },
    error: function(object, error) {
      // Couldn't find the produce by ID. Displays the error
      console.log("Couldn't find produce");
      console.log(error);
      res.render('error', {message: error.message, error: error});
    }
  });
});
Esempio n. 7
0
app.post("/verifyEmail", (req, res) => {
	console.log("Sending verification email to: " + req.body.email);

	var subject = "Email Verification";

	var body = "Please verify your email by clicking the link below.";

	// build hash for verification link

	var query = new Parse.Query("User");
	query.equalTo("username", req.body.email);

	query.first({
		success (user) {
			var toHash = user.getUsername() + user.get("createdAt") + user.id;
			var hash = md5(toHash);

			var link = "http://localhost:3000/#/verifyEmail/" + req.body.email + "/" + hash;

			mailAdapter.sendEmail(req.body.email, subject, body, link).then(
				() => {
					res.send("Verification email sent successfully.");
				},
				() => {
					res.send("Error: Verification email failed.");
				}
			);
		},
		error (err) {
			// if hash fails to build, fail out of the webhook
			console.log("Hash build failed, exiting webhook.");
			return console.log(err);
		}
	});
});
Esempio n. 8
0
 Parse.Cloud.beforeSave('BeforeSaveFailWithPromise', function (req, res) {
   var query = new Parse.Query('Yolo');
   query.find().then(() => {
    res.error('Nope');
   }, () => {
     res.success();
   });
 });
Esempio n. 9
0
 }, (err) => {
   expect(err).toBe(null);
   const query = new Parse.Query(TestObject);
   return query.count().then((count) => {
     expect(count).toBe(0);
     done();
   });
 });
Esempio n. 10
0
 obj.destroy().then(function(){
     let query = new Parse.Query('AfterDeleteTestProof');
     query.equalTo('proof', obj.id);
     query.find().then(function(results) {
         expect(results.length).toEqual(1);
         let deletedObject = results[0];
         expect(deletedObject.get('proof')).toEqual(obj.id);
         done();
     }, errorHandler);
 }, errorHandler)
Esempio n. 11
0
        return createStoreWithItemP(item).then(function(store) {
          const itemQuery = new Parse.Query(Item);
          itemQuery.equalTo("price", 30);

          const storeQuery = new Parse.Query(Store);
          storeQuery.matchesQuery("item", itemQuery);
          return storeQuery.count().then(function(storeCount) {
            assert.equal(storeCount, 1);
          });
        });
Esempio n. 12
0
	queryFind(function() {
		let query = new Parse.Query(Hack);
		query.select([
			'name',
			'tableNumber',
			'categories',
			'team'
		]);
		return query;
	}),
Esempio n. 13
0
 return Parse.Object.saveAll([item, item2]).then(function(items) {
   assert.equal(items.length, 2);
   const query = new Parse.Query(Item);
   query.equalTo("price", 30);
   return query.find().then(function(items) {
     assert.equal(items.length, 2);
     assert.equal(items[0].get("price"), 30);
     assert.equal(items[1].get("price"), 30);
   });
 });
Esempio n. 14
0
 return brandQuery.find().then(function(brands) {
   assert.equal(brands.length, 1);
   const brandQuery2 = new Parse.Query(Brand);
   brandQuery2.limit(1);
   brandQuery2.skip(1);
   return brandQuery2.find().then(function(moreBrands) {
     assert.equal(moreBrands.length, 1);
     assert.notEqual(moreBrands[0].id, brands[0].id);
   });
 });
Esempio n. 15
0
 Parse.Object.saveAll([obj0, obj1]).then(() => {
   const query = new Parse.Query('MyObject');
   query.equalTo('forced', false);
   query.find().then((results) => {
     expect(results.length).toBe(1);
     const firstResult = results[0];
     expect(firstResult.get('forced')).toBe(true);
     done();
   });
 });
Esempio n. 16
0
 obj.save().then(function() {
   const query = new Parse.Query('MyObject');
   query.get(obj.id).then(function(result) {
     expect(result.get('secretField')).toEqual('###');
     done();
   }, function(error) {
     fail(error);
     done();
   });
 }, function(error) {
Esempio n. 17
0
 it('should always hash a query to the same string', function() {
   const q = new Parse.Query(Item);
   q.equalTo('field', 'value');
   q.exists('name');
   q.ascending('createdAt');
   q.limit(10);
   const firstHash = queryHash(q);
   const secondHash = queryHash(q);
   expect(firstHash).toBe(secondHash);
 });
Esempio n. 18
0
 obj.save().then(function() {
   const query = new Parse.Query('MyObject');
   query.equalTo('objectId',obj.id);
   query.find().then(function() {
     fail("AfterFind should handle response failure correctly");
     done();
   }, function() {
     done();
   });
 }, function() {
Esempio n. 19
0
 obj.save().then(function() {
   const query = new Parse.Query('MyObject');
   query.equalTo('objectId',obj.id);
   query.find().then(function(results) {
     expect(results[0].get('secretField')).toEqual('###');
     done();
   }, function(error) {
     fail(error);
   });
 }, function(error) {
Esempio n. 20
0
      brand.save().then(savedBrand => {
        assert(savedBrand.has('cool'));
        assert(savedBrand.get('cool'));

        var q = new Parse.Query(Brand);
        q.first().then(queriedBrand => {
          assert(queriedBrand.has('cool'));
          assert(queriedBrand.get('cool'));
        });
      });
Esempio n. 21
0
 it('matches existence queries', function() {
   var obj = {
     id: new Id('Item', 'O1'),
     count: 15
   };
   var q = new Parse.Query('Item');
   q.exists('count');
   expect(matchesQuery(obj, q)).toBe(true);
   q.exists('name');
   expect(matchesQuery(obj, q)).toBe(false);
 });
Esempio n. 22
0
 obj.save().then(function() {
   const query = new Parse.Query('BeforeSaveAddACL');
   query.get(obj.id).then(function(objAgain) {
     expect(objAgain.get('lol')).toBeTruthy();
     expect(objAgain.getACL().equals(acl));
     done();
   }, function(error) {
     fail(error);
     done();
   });
 }, error => {
Esempio n. 23
0
 setTimeout(function() {
   var query = new Parse.Query('AfterDeleteProof');
   query.equalTo('proof', obj.id);
   query.find().then(function(results) {
     expect(results.length).toEqual(1);
     done();
   }, function(error) {
     fail(error);
     done();
   });
 }, 500);
Esempio n. 24
0
 Parse.Object.saveAll([item, item2]).then(function(items) {
   assert(items.length === 2);
   var query = new Parse.Query(Item);
   query.equalTo("price", 30);
   return query.find().then(function(items) {
     assert(items.length === 2);
     assert(items[0].get("price") === 30);
     assert(items[1].get("price") === 30);
     done();
   });
 });
Esempio n. 25
0
 (err) => {
   expect(err).toBe(null);
   const query = new Parse.Query('TestObject');
   query.ascending('data');
   query.find().then((results) => {
     expect(results.length).toEqual(2);
     expect(results[0].id).toEqual('aaaaaaaaaa');
     expect(results[1].id).toEqual('bbbbbbbbbb');
     done();
   });
 }
Esempio n. 26
0
        createStoreWithItemP(item).then(function(store) {
          var itemQuery = new Parse.Query(Item);
          itemQuery.equalTo("price", 30);

          var storeQuery = new Parse.Query(Store);
          storeQuery.matchesQuery("item", itemQuery);
          storeQuery.count().then(function(storeCount) {
            assert(storeCount === 1);
            done();
          });
        });
 .then(() => {
   const now = new Date();
   const future = new Date(
     now.getFullYear(),
     now.getMonth() + 1,
     now.getDate()
   );
   const pipeline = [{ match: { createdAt: future } }];
   const query = new Parse.Query(TestObject);
   return query.aggregate(pipeline);
 })
 .then(() => {
   const now = new Date();
   const today = new Date(
     now.getFullYear(),
     now.getMonth(),
     now.getDate()
   );
   const pipeline = [{ match: { updatedAt: { $gte: today } } }];
   const query = new Parse.Query(TestObject);
   return query.aggregate(pipeline);
 })
	}).then(function(athleticsData) {
		const oldTeamsQuery = new Parse.Query("AthleticsTeam");
		oldTeamsQuery.limit(1000);
		return oldTeamsQuery.find({
			useMasterKey: true
		}).then(function(oldTeams) {
			return Parse.Object.destroyAll(oldTeams, {useMasterKey: true});
		}).then(function() {
			return createNewAthleticsTeams(athleticsData);
		});
	}).then(function() {
Esempio n. 30
0
 brandQuery.find().then(function(brands) {
   assert(brands.length === 1);
   var brandQuery2 = new Parse.Query(Brand);
   brandQuery2.limit(1);
   brandQuery2.skip(1);
   brandQuery2.find().then(function(moreBrands) {
     assert(moreBrands.length === 1);
     assert(moreBrands[0].id !== brands[0].id);
     done();
   });
 });