In a nutshell, I have created register and login functionalities. The problem is that I do not want the information/retrieved from the default User class, but from a custom one, such as Customers, however, i do not know how to change it.
This is how I refer to the default class (User).
$scope.signUp = function(form) {
var user = new Parse.User();
user.set("password", form.password);
user.set("username", form.username);
user.signUp(null, {
success: function(user) {
window.location = 'myprofile.php'
},
error: function(user, error) {
alert("Unable to sign up: " + error.code + " " + error.message);
}
});
};
$scope.logIn = function(form) {
Parse.User.logIn(form.lusername, form.lpassword, {
success: function(user) {
window.location = 'admin.php'
},
error: function(user, error) {
alert("Unable to log in: " + error.code + " " + error.message);
}
});
};
$scope.logOut = function(form) {
Parse.User.logOut();
window.location = 'index.html'
};
}]);
Related
This is my likedc.js which I tried to upload but however the terminal reported me that it is failed because Error: Uncaught SyntaxError: Unexpected string in likedc.js:40 at main.js:3:1
I tried to comment but the terminal still says the same thing. I'm not sure what are the alternatives that I can amend
Parse.Cloud.define("StatusUpdate", function(request,response){
//query Installation for user
var Installationquery = Parse.Object.extend("Installation");
var query = new Parse.Query(Installationquery);
var message = request.params.message
query.equalTo("user", request.params.User);
query.find({
success: function(results) {
response.success("found user" + results)
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
Parse.Push.send({
where: query, // Set our Installation query
data: {
alert: createMessage(message)
badge: "Increment", **//<---- Line 40**
sound: "";
}
}, {
success: function() {
// Push was successful
console.log("sent ")
},
error: function(error) {
console.log("Error " + error)
}
}
},
error: function(error) { // <--- Line 54**
alert("Error: " + error.code + " " + error.message);
}
});
})
});
var alertMessage = function createMessage(request)
{
var message = "";
if (request.object.get("StatusUpdate") === "likedby") {
if (request.user.get('postedby')) {
message = request.user.get('postedby') + ': ' + request.object.get('statusOBJID').trim();
} else {
message = "Someone liked on your status update.";
}
// Trim our message to 140 characters.
if (message.length > 140) {
message = message.substring(0, 140);
}
return message;
}
}
data: {
alert: createMessage(message), //<-- add comma here
badge: "Increment", **//<---- Line 40**
sound: "" //<-- remove semicolon here
}
For the second part, from the context I think your error block is out of place, try rearranging like
Parse.Cloud.define("StatusUpdate", function(request, response) {
//query Installation for user
var Installationquery = Parse.Object.extend("Installation");
var query = new Parse.Query(Installationquery);
var message = request.params.message
query.equalTo("user", request.params.User);
query.find({
success: function(results) {
response.success("found user" + results)
// Do something with the returned Parse.Object values
for (var i = 0; i < results.length; i++) {
var object = results[i];
Parse.Push.send({
where: query, // Set our Installation query
data: {
alert: createMessage(message),
badge: "Increment", //<---- Line 40**
sound: ""
}
}, {
success: function() {
// Push was successful
console.log("sent ")
},
error: function(error) {
console.log("Error " + error)
}
});
}
},
error: function(error) { // <--- Line 54**
alert("Error: " + error.code + " " + error.message);
}
});
});
I'm trying to create a Lobby for a web game I'm working on and I want to add the person who is creating the lobby to the lobby's "Players" array. I'm using parse and I can't for the life of me figure out how to append just the player object into the array. Any help is great!
function createLobby(){
var ses = Parse.Object.extend("Session");
var query = new Parse.Query(ses);
var exists = false;
query.equalTo("sessionName", document.getElementById("lobby").value);
query.find({
success: function(results) {
console.log("Successfully retrieved " + results.length );
if(results.length!=0){
alert("Session already exists");
exists = true;
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
if(exists==false){
session.set("sessionName",document.getElementById("lobby").value);
var Players = Parse.Object.extend("Player");
var query = new Parse.Query(Players);
query.equalTo("Name", "testName");
query.find({
success: function(results) {
var query2 = new Parse.Query(Players);
query2.get(results[0].id, {
success: function(k) {
console.log(k);
session.add("Players", k);
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
session.save(null, {
success: function(object) {
$(".success").show();
},
error: function(model, error) {
$(".error").show();
}
});
}
}
You're failing to understand how callbacks work. I recommend you read about JavaScript callbacks and promises. Here's how this should be written:
function createLobby() {
var ses = Parse.Object.extend("Session");
var query = new Parse.Query(ses);
var exists = false;
query.equalTo("sessionName", document.getElementById("lobby").value);
query.find({
success: function(results) {
console.log("Successfully retrieved " + results.length);
if (results.length != 0) {
alert("Session already exists");
return;
}
session.set("sessionName", document.getElementById("lobby").value);
var Players = Parse.Object.extend("Player");
var query = new Parse.Query(Players);
query.equalTo("Name", "testName");
query.find({
success: function(results) {
var query2 = new Parse.Query(Players);
query2.get(results[0].id, {
success: function(k) {
console.log(k);
session.add("Players", k);
},
error: function(object, error) {
// The object was not retrieved successfully.
// error is a Parse.Error with an error code and message.
}
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
session.save(null, {
success: function(object) {
$(".success").show();
},
error: function(model, error) {
$(".error").show();
}
});
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
}
I'm writing a cloud code function for run many task after delete an object.
How can I do this cleanly and without nesting?
You can run tasks in parallel or it is better to have them sequentially? If so, how?
This is my code, can you help me to clean/change?
Parse.Cloud.afterDelete("Photo", function(request) {
Parse.Cloud.useMasterKey();
//delete all related activities
var queryAct = new Parse.Query("Activity");
queryAct.equalTo("photo",{
__type: "Pointer",
className: "Photo",
objectId: request.object.id
});
queryAct.limit(1000);
queryAct.find({
success: function(activities) {
Parse.Object.destroyAll(activities, {
success: function() {
//delete all related hashtags
var queryTags = new Parse.Query("hashTags");
queryTags.equalTo("photo",{
__type: "Pointer",
className: "Photo",
objectId: request.object.id
});
queryTags.limit(1000);
queryTags.find({
success: function(hashtags) {
Parse.Object.destroyAll(hashtags, {
success: function() {},
error: function(error) {
console.error("Error deleting related hashtags " + error.code + ": " + error.message);
}
});
},
error: function(error){
console.error("Error finding related hashtags " + error.code + ": " + error.message);
}
});
},
error: function(error) {
console.error("Error deleting related activities " + error.code + ": " + error.message);
}
});
},
error: function(error) {
console.error("Error finding related activities " + error.code + ": " + error.message);
}
});
});
Thanks to all!
Here find.then.delete is a series of tasks in a row. However, you can delete your hastags and activities in parallel since they don't seem to be dependent. Please check promises guide for more info.
Your code can be shortened as below:
var Photo = Parse.Object.extend("Photo");
Parse.Cloud.afterDelete("Photo", function(request) {
Parse.Cloud.useMasterKey();
var photo = Photo.createWithoutData(request.object.id);
var queryAct = new Parse.Query("Activity");
queryAct.equalTo("photo", photo);
queryAct.limit(1000);
var promiseForActivities = queryAct.find().then(function (activities) {
return Parse.Object.destroyAll(activities);
});
var queryTags = new Parse.Query("hashTags");
queryTags.equalTo("photo", photo);
queryTags.limit(1000);
var promiseForHashtags = queryTags.find().then(function (hashtags) {
return Parse.Object.destroyAll(hashtags);
});
return Parse.Promise.when([promiseForActivities, promiseForHashtags]).then(function () {
console.log("Done");
}, function (err) {
console.error(err);
});
});
Note that you don't need to create your own pointer objects like:
{
__type: "Pointer",
className: "Photo",
objectId: "someId"
}
Rather you can use createWithoutData which is a shortcut for:
var Photo = Parse.Object.extend("Photo");
var p = new Photo();
p.id = "someId";
I also think that it could be enough to pass the request.object directly, like queryAct.equalTo("photo", request.object);
I have class say 'inspection' and there is a field name property (this is a pointer) . I am trying to retrieve a record by field value but getting nothing as a result. I am using following code
getInspectionByProperty = function(req) {
console.log(req.body.propertyId)
var query = new Parse.Query("Inspection");
query.include('property');
query.equalTo('property', req.body.propertyId);
query.find({
success: function(data) {
console.log('in success');
console.log(data);
// Successfully retrieved the object.
},
error: function(error) {
console.log('in error')
console.log("Error: " + error.code + " " + error.message);
}
});
};
I am getting this error in parse log
Error: 102 pointer field property needs a pointer value
How can i get the record .Thanks in advance
Here what i try and thats work for me.
getInspectionByProperty = function(req) {
console.log(req.body.propertyId)
var query = new Parse.Query("Inspection");
query.include('property');
query.equalTo("property", {
"__type": "Pointer",
"className": "Property",
"objectId": propertyId
});
query.find({
success: function(data) {
console.log('in success');
console.log(data);
// Successfully retrieved the object.
},
error: function(error) {
console.log('in error')
console.log("Error: " + error.code + " " + error.message);
}
});
};
How would I create a test suite where I have a test case that is dependent on a previous test case to start?
Example:
Test 1 Login with user X
Test 2 My account page (Comes after user logged in)
Test 3 "Follow up with other tests with the same user, but on other pages"
I've been through documentation of CasperJS writing_modules & other examples but I cannot find or understand how to set it up for my specific requirements.
Or if it's even possible to do so.
Currently I have it setup as follows:
File 1 Suite
// Suite.js
var Suite;
Suite = require("./Login_User.js");
Suite.login_User("randomname","randompassword");
casper.then(function() { ;
this.test.pass("Hit the first then");
Suite = require("./MyAccount.js");
Suite.Enterprise();;
});
casper.run(function() {
return this.test.done();
});
File 2 Login Functionality
// Login_User.js (Test 2)
casper.test.begin("login page", function(test) {
casper.options.waitTimeout = 5000;
casper.on('remote.message', function(msg) {
this.echo('rem msg: ' + msg);
});
casper.on("page.error", function(msg) {
this.echo("Page Error: " + msg, "ERROR");
});
var url = "https://website.com";
casper.start(url, function() {
console.log("page loaded");
});
exports.login_User = function(username, password) {
casper.test.comment(username + "\n" + password);
casper.then(function() {
this.evaluate(function(username, password) {
$("cmpLogin_UserName").val(username);
$("cmpLogin_Password").val(password);
$("cmpLogin_LoginButton").click();
}, {
"username": username,
"password": password
})
casper.waitForUrl("https://website.com/myAccount.aspx", function() {
console.log("Logged in");
casper.capture("Loggedin.png");
});
});
casper.then(function(){
this.test.assertTitle("My Account", "Title is Login");
});
casper.run(function() {
test.done();
});
}
});
File 3 My Account Content
// MyAccount (Test 3)
casper.test.begin("Account page", function(test) {
casper.options.waitTimeout = 5000;
casper.on('remote.message', function(msg) {
this.echo('rem msg: ' + msg);
});
casper.on("page.error", function(msg) {
this.echo("Page Error: " + msg, "ERROR");
});
var url = "https://website.com/myAccount.aspx?";
casper.start(url, function() {
console.log("page loaded");
casper.capture("MyAccountEnt.png");
});
// It does not reach this section!!!
exports.Enterprise = function() {
casper.then(function() {
this.test.assertTitle("My Account", "My Account page");
this.test.pass("test test test");
});
casper.run(function() {
test.done();
});
}
});
Command line output
http://i.imgur.com/ZHsZ5hX.png?1