2

On our website I want people to be able to report if a video is uploaded on Youtube so we have 3 fields on our website. A Username, password and video Id field. When the user clicks the Html button we have it call a javascript function.

    function reportUpload() {
    Parse.Cloud.run('report_upload',
    {
        username: "testUser",
        password: "testPassword",
        videoId: "VQv9xfOfLOY"
    },{
        success: function(result) {
            //Do Neat Stuff
        },
        error: function(e) {
            //error
        }
    });
}

That then calls our cloud code function. We need the cloud code function to pull the usernames from the User class and test if any of them match. If any do match they will then need to check if the passwords match. if all of that doesn't fail it will send a push notification to one of the users of the app.

So far in the cloud code funtion I have figured out how to query all the usernames.

Parse.Cloud.define("report_upload", function(request, response) {
    console.log(request.params);
    var query = new Parse.Query(Parse.User);
    query.find({
        success: function(results){
            var users = [];
            //extract out user names from results
            for(var i = 0; i < results.length; ++i){
                users.push(results[i].get("username"));
            }
            response.success(users);
            console.log(JSON.stringify(users));
        }, error: function(error){
            response.error("Error");
          }
    });
});

Thanks

Dawson
  • 23
  • 4
  • Do you want to check if a video exists for "the currently logged in" user? – Akshay Arora Dec 30 '15 at 06:29
  • If yes, you need not send the password. You should send `Parse.User.current()` as a parameter to identify the user. As a sidenote, I don't really think you can match the password in any case. – Akshay Arora Dec 30 '15 at 06:31
  • @Akshay Arora The video id doesn't really matter it will just be sent in the push notification. So there is no way to check if the user has already made a account with our IOS app? – Dawson Dec 30 '15 at 06:47
  • You can definitely check if a user exists, but you cannot send and compare passwords the way you did. – Akshay Arora Dec 30 '15 at 06:50

1 Answers1

1

Seems like you want to check if a particular user has made an account already with a particular username.

You will have to query the User class. The user class is secured by default. In the cloud code, you should write Parse.useMasterKey(); to have a full access (Careful, read note below).

var myquery = new Parse.Query(Parse.User);
myquery.equalTo("username",yourUsernameHere);
myquery.find({
success: function(results){
if(results.length === 0)
{
    // User not found
}
else
{
    // found
}
});

Note: Using the master key overrides all individual access privileges for your data. Be absolutely sure what you are doing.

Akshay Arora
  • 1,953
  • 1
  • 14
  • 30