Parse.User.current(), globals etc - parse-platform

I am new to Express and Parse. I am trying to make a simple modification to the Anyimg cloud tutorial. I would like to display the default home page only if the user is authenticated. If I use Parse.User.authenticated(), I get:
The error was TypeError: Object function (){e.apply(this,arguments)} has no method 'authenticated'
at app.js:33:18
at main.js:1:1
Parse.User.current() compiles with no error, but the code does not work. What am I missing? I have tried literally over 60 different options over the last 3 days with no success.
I also tried to declare a GLOBAL from within user.js and that did not work. I did a require cloud/user from within app.js and that did not help at all.
I hope someone can help. It appears that Parse tutorials (outside parse.com) from about a year ago break.
On the other hand, I wanted to display the login page (not default) upon logout. I got it done in less than 10 minutes.

The correct way to do this would be:
var currentUser = Parse.User.current();
if (currentUser) {
// logged in
} else {
// not logged in
}
Parse.User.current() returns the current user, or undefined if not logged in.
as seen here: https://parse.com/docs/js_guide#users-current

As mentioned above, I already had code that was similar to Fosco's. However, the var statement was not in the scope of the function as I was trying out o. I just moved it in and it all works. Thanks to everyone for looking into this.

Related

Creating a simple, basic page object in Nightwatch.js

Ok, so I've read up on the use of page_objects in nightwatch.js, but I'm still getting issues with it (which I'm convinced is due to something obvious and/or simple).
Using http://nightwatchjs.org/guide/#page-objects as the guide, I added the the file cookieremoval.js in my page_objects folder.
module.exports = {
elements: {
removeCookies: {
selector: '.banner_continue--2NyXA'
}
}
}
In my nightwatch.conf.js file I have;
page_objects_path: "tests/functional/config/page_objects",
And in my test script I have;
module.exports = {
"/cars/road-tax redirects to /car-tax/ ": browser => {
browser.url(browser.launch_url + browser.globals.carReviews)
.assert.urlEquals(browser.launchUrl + "/car-reviews/")
.waitForElementPresent('#cookieRemove', 3000)
.click('#cookieRemove')
.end();
},
};
However, when I run the test, I keep getting an error reading;
Timed out while waiting for element <#cookieRemove>
Any ideas why this is not working?
Many thanks
First of all, you never instantiated your page object. You're asking the browser object to search for an unknown element, that's why it's timing out. Your code should look something like this in your test script: var cookieRemoval = browser.page.cookieremoval(); then use this object to access those variables and functions in your page object. For example, if you wanted to access the remove cookie element, then you would do this cookieRemoval.click('#removeCookies');.
Secondly, you will have to know when to use the global browser object and when to use your page object. If you need to access something within your page object, obviously use the page object to call a function or access a variable. Otherwise, browser won't know the element you're looking for exists. Hope this help you out, I would definitely spend some more time learning about objects and specifically how they're used in nightwatch.js.

cfajaxproxy is sending invalid parameters?

For some reason that I don't understand, on my development machine can't call to function of a cfc component from a cfajaxproxy.
In my cfm document:
<cfajaxproxy cfc="#Application.CfcPath#.empleado"
jsclassname="ccEmpleado">
This works, and also I can instantiate an object to get all the functions of that cfc component:
var cfcEmpleado = new ccEmpleado();
But, when I try to call a function of that object:
var nb_Empleado = cfcEmpleado.RSEmpeladoNombreBIND(1,1);
Debug complains:
Error: The ID_EMPRESA parameter to the RSEmpeladoNombreBIND function is required but was not passed in.
I got this from Network tab on Chrome and figured out that something is generating an invalid parameter:
http://127.0.0.1/vpa/componentes/empleado.cfc?method=RSEmpeladoNombreBIND&_cf_ajaxproxytoken=[object%20Object]&returnFormat=json&_cf_nodebug=true&_cf_nocache=true&_cf_clientid=41C92098C98042112AE2B3AAF523F289&_cf_rc=0
As you can see, there's a parameter [object%20Object], that is messing around my request, and that's why it fails. I don't why is happening this. Other people has tested this, and it works, but in mine doesn't.
I have Coldfusion 9, Apache, Windows 8. Is is some configuration issue on Coldfusion, or a bug?
I can't tell if this is your error or not, but it might be. This was a problem that we had for awhile. You should consider using explicit names to avoid any confusion. Add the "js" in there.
<cfajaxproxy cfc="cfcEmpleado" jsclassname="proxyEmpleado">
var jsEmpleado = new proxyEmpleado();
I will try to find a link to an article about this very thing.

Meteor: unreliable session variable?

I'm making a service where there are no user accounts, and I want to restrict by what page I'm visiting.
So each page is a "box", and on each "box" I have a bunch of "files".
I've published the relevant info in server/publications.coffee
Meteor.publish 'files', (boxId)->
console.log boxId
return Files.find({boxId:boxId})
My file for 'box' has a subscription handle:
#filesHandle = Meteor.subscribe 'files', Session.get('currentBoxId')
And the currentBoxId is stored in the session variable.
Here's the crazy part: I expect this to work, and it does on the first time I start the server. The console.log in the first bit of code prints the proper ID. Then, all of a sudden the console log suddenly starts returning "null", even when I console.log the session var in the browser console, it returns correctly.
I feel like there's some kind of loading asynchrony issue here, but I have no idea what's going on.
Any clues?
Ah, figured it out. The template can be rendered before the session variable is set, apparently. Usually you put your collection handles in the main.js file in the application scope, but this doesn't work if the subscription depends on session variables.
I did the following:
Template.boxPage.created = ()->
#filesHandle = Meteor.subscribe 'files', Session.get('currentBoxId')

Meteor 0.5.9: replacement for using Session in a server method?

So, I was attempting to do something like the following:
if(Meteor.isServer){
Meteor.methods({connect_to_api: function(vars){
// get data from remote API
return data;
}});
}
if(Meteor.isClient){
Template.myTpl.content = function(){
Meteor.call('connect_to_api', vars, function(err,data){
Session.set('placeholder', data);
});
return Session.get('placeholder');
};
}
This seemed to be working fine, but, of course, now breaks in 0.5.9 as the Session object has been removed from the server. How in the world do you now create a reactive Template that uses a server-only (stuff we don't want loading on the client) method call and get data back from that Method call. You can't put any Session references in the callback function because it doesn't exist on the server, and I don't know of any other reactive data sources available for this scenario.
I'm pretty new to Meteor, so I'm really trying to pin down best-practices stuff that has the best chance of being future-proof. Apparently the above implementation was not it.
EDIT: To clarify, this is not a problem of when I'm returning from the Template function. This is a problem of Session existing on the server. The above code will generate the following error message on the server:
Exception while invoking method 'connect_to_api' ReferenceError: Session is not defined
at Meteor.methods.connect_to_api (path/to/file.js:#:#)
at _.extend.protocol_handlers.method.exception ... etc etc
Setting the session in the callback seems to work fine, see this project I created on github: https://github.com/jtblin/meteor_session_test. In this example, I return data in a server method, and set it in the session in the callback.
There are 2 issues with your code:
1) Missing closing brace placement in Meteor.methods. The code should be:
Meteor.methods({
connect_to_api: function(vars) {
// get data from remote API
return data;
}
});
2) As explained above, you return the value in the session, before the callback is completed, i.e. before the callback method had the time to set the session variable. I guess this is why you don't see any data in the session variable yet.
I feel like an idiot (not the first time, not the last). Thanks to jtblin for showing me that Session.set does indeed work in the callback, I went back and scoured my Meteor.method function. Turns out there was one spot buried in the code where I was using Session.get which was what was throwing the error. Once I passed that value in from the client rather than trying to get it in the method itself, all was right with the world.
Oh, and you can indeed order things as above without issue.

Login logout in smarty

I have written the header.tpl and login.php file in smarty. i want to show the logout text if user is logged in. otherwise it should show login if user is not logged in.below is the code of login.php
if(isset($_REQUEST['submit']))
{
$name=$_REQUEST['name'];
$pass=$_REQUEST['pass'];
$rs=mysql_query("select * from form where name='$name'");
$fetchdata=mysql_fetch_array($rs);
if($rs)
{
$name=$fetchdata['name']
$_SESSION['name']=$name;
$name1=$_SESSION['name'];
//$smarty->assign('name',$_SESSION['name']);
$smarty->assign('name1',$name1);
$smarty->display("about.tpl");
}
else
{
$smarty->display("login.tpl");
}
}
below is the header.tpl code
{if $name1!= ''}: Logout{else}login{/if}
it is showing error
Parse error: syntax error, unexpected T_VARIABLE in D:\xampp\htdocs\smarty\login.php on line 29
I found a bunch of weird things.
You should escape the name and pass before inserting into sql query. see http://www.php.net/manual/en/function.mysql-real-escape-string.php for more details.
The php documentation recommend that you should use the MySQLi extension
I can't see a authentication..I mean you don't use the give password. Is this correct?
I think mysql_query isn't falsey even when the result is empty. You can solve this with if($fetchdata=mysql_fetch_array($rs)){... instead of if($rs)
I'm not sure if this would throw an exception but i would write {if {$name1|default:""}!= ''}: Logout{else}login{/if} instead of {if $name1!= ''}: Logout{else}login{/if}
This is an old post, but I ran into a similar issue just a couple minutes ago.
I was getting an parse error for the variable: $_smarty_t
I tried different things to make there error go away, but there was nothing obvious. I confirmed that caching was turned off, but the issue persisted, even after deleting the individual cached file.
Eventually I deleted the entire contents of that directory and refreshed, and the error finally resolved.
This issue occurred with Smarty v3.1.27, as loaded through Composer, smarty/smarty.

Resources