In my action:
$this->getUser()->setFlash ('error', 'Something went wrong!');
$this->redirect (sfConfig::get('app_default_module'));
and in my view:
echo $sf_user->getFlash('error');
shows nothing. I know its not too much, but what can I do?
If you all want to cry and laugh at the same time: I overridden the "myUser::shutdown()" method, and nobody told to call its parent...
Related
I have a pretty standard setup for my meteor app using IronRouter. What I am having problems with is this, I am attempting to redirect someone to a page based on some tokens in a url coming from a third party website but when the user is sent to their destination from the Accounts.onLogin callback via Router.go("some/fun/url"); the waitOn function runs endlessly.
Below is the pertinent part of the setup.
First the route that I am redirecting to:
Router.route("/shows/:show_acronym/sponsorships", {
name:"sponsorshipsSalesPortal",
data:function(){
return {show:Shows.findOne({acronym:this.params.show_acronym})};
},
waitOn:function(){
console.log("wait on");
return [Meteor.subscribe("show_by_acronym",this.params.show_acronym),Meteor.subscribe("catalogue_products_by_acronym", this.params.show_acronym)];
}
});
Next the relevant part of the onLogin hook:
Accounts.onLogin(function(){
if (Session.get("showToRedirectTo")){
console.log("sending to sponsorship portal");
var ur ="/shows/"+Session.get("showToRedirectTo")+"/sponsorships"
return Router.go(ur);
}
});
When it hits the redirect, the url changes and the message "wait on" prints in the console forever. Does anyone know of a solution to this? I would prefer to keep all of my subscriptions at the router level if at all possible.
Thanks
You should only return subscription cursors (Meteor.subscribe(*)) in the waitOn return array.
In your case, "this.params.show_acronym" is the problem...
Actually your code looks good, its been a while since i dont use Iron Router or Sessions.
But looking at the WaitOn, it seems okay, the problem can come from the Server side where show_by_acronym or catalogue_products_by_acronym its throwing an error, but in all the cases this should cause you to get a spinner loading forever, not a console.log("wait on"); printed forever.
so i think your Accounts.onLogin is causing this.
Try something like.
Accounts.onLogin(function(){
if (Session.get("showToRedirectTo")){
console.log("sending to sponsorship portal");
var ur ="/shows/"+Session.get("showToRedirectTo")+"/sponsorships"
Router.go(ur);
Session.set('showToRedirectTo', false)
}
});
I'm following this fantastic tutorial on customizing login found as the answer on this post - http://goo.gl/VLO34 - but it's not working for me.
I copied all the files verbatim, and even added supplementary smart packages such as underscore _.pick, and http Meteor.http.get just in case it was required, and mistakenly left out.
Anyhoo - I get github to authorize my app, but Meteor.users in the web console and db.users.findOne() on the local mongo instance show that Accounts.OnCreateUser() didn't add any new information to my user profile [that I'm pulling in from github]. In other words, {{currentUser.profile.avatar_url}} and {{currentUser.profile.login}} won't reveal anything following that tutorial. So I get blank info on the screen.
I tried that screencasts first attempt, and noticed that {loginButtons}} returns values for {{currentUser.profile.login}}. I've reviewed the code many times for typos, but feel that something is quite off with Accounts.onCreateUser(fn)...
I'm using Meteor 0.5.7, and if anyone else has experienced this problem following that screencast, please let me know. Thanks,
EDIT: I've deployed the project to - http://rptest-customlogin.meteor.com/.
Author of the screencast here. And as of a few seconds ago, a new user on your site :-). So, it looks like login is working on your site. But I'm guessing what's happening in your app is the login info isn't available yet at the time of rendering or at the time you're printing to the console. The reason is that all of that info is being populated asynchronously. It takes a few seconds for the process to complete. If you're relying on Meteor.user().profile data in your templates you need to check first if the login process is still underway.
To do that, you can use either the Meteor.loggingIn() javascript function or the {{#if loggingIn}} handlebars block helper. That function is "reactive" which means once the result changes from true to false your UI will update. So the template might look something like this:
<template name="loginDependentWidget">
{{#if loggingIn}}
Logging In
{{else}}
{{currentUser.profile.avatar_url}}
{{/if}}
</template>
Does this help?
Might be a typo but Accounts.OnCreateUser(fn); should be Accounts.onCreateUser(fn);
Meteor docs: http://docs.meteor.com/#accounts_oncreateuser
And then another post on the same subject:
Meteor login with external service: how to get profile information?
EDIT:
Posting as edit due the formatting of the below piece of code.
In the meantime I have got it running on my own project with this piece of code:
Accounts.onCreateUser(function(options, user) {
if(!options || !user) {
console.log('error creating user');
return;
} else {
if(options.profile) {
user.profile = options.profile;
}
}
return user;
});
Which is working just fine. Have you placed the Accounts.onCreateUser(); on the server?
This is giving me quite some headache. I have an page-tab-application, where DB-interaction uses the facebook-user-id to assign and save data and also to check user permissions. Until a weak ago everything was working fine, but now with the upcoming december-changes this setup doesnt work anymore:
config.php:
$facebook = new Facebook( array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
index.php:
includes config.php and gets the signed request (not important for the question
javascript.js:
calls the read-user-status.php and handles the data
read-user-status.php:
gives json-response, includes config.php and calls the $facebook -> getUser()-function to get the uid
Even when called from the index.php directly after page-load, I sometimes get the uid and sometimes I don't. Strangly enough I usually have to wait a little until I reload the page and then it works again. But this isn't always the case. This all is just very strange to me.
EDIT: Should have mentioned that this call:
$uid = $facebook -> getUser();
if ($uid) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$uid = FALSE;
echo "EXCEPTION $e";
}
}
gives out "EXCEPTION An active access token must be used to query information about the current user".
I know there quite a lot of similar questions out there, but none of the answers were helpful to my particular (and probably to the new breaking changes relied) problem.
EDIT2: I now suppose that it is a sdk-bug (https://developers.facebook.com/bugs/238039849657148 , thanks to CBroe). Any recommendations for a work-around are of course very welcome.
EDIT 3, TEMPORARY SOLUTION
Everytime you make an ajax request, you post the token you get from the FB.getLoginStatus or FB.login and read it out in the php file and set it via $facebook -> setAccessToken. Not suitable in all circumstances (you definately need to use post), is slower and brings some security issues, but still works.
Sounds like you are affected by the bug I reported beginning of November, https://developers.facebook.com/bugs/238039849657148
They’ve confirmed it and say they’re working on a fix – but since the change is only a few days away now, they should hurry up a little …
I got this working by doing the following...
if(!$user){
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'email',
'redirect_uri' => $app_url
));
header('Location: ' . $loginUrl);
}
I also added my app to be integrated with:
Website with Facebook login
App on Facebook
Page Tab
try by adding access token to request.
$accessToken = $facebook->getAccessToken();
$user_profile = $facebook->api('/me?access_token=' . $accessToken);
I found a work-around for this, until it is fixed (which it seems like, wont be in time until the changes take place).
Everytime you make an ajax request, you post the token you get from the FB.getLoginStatus or FB.login and read it out in the php file and set it via $facebook -> setAccessToken. Not suitable in all circumstances (you definately need to use post), is slower and brings some security issues, but still works.
if it you are lucky and your version of php sdk still registers session variables than right after _graph method declaration:
//find this method below
protected function _graph ($path, $method = 'GET', $params = array ())
{
//paste right after _graph method declaration code below:
if (isset($_SESSION["fb_".$this->getAppId()."_access_token"]))
{
$this->setAccessToken($_SESSION["fb_".$this->getAppId()."_access_token"]);
}
//till here
//and you are good to go
//remember: your version of sdk must be registering access token variable in session
//right after ajax call
//i used git to get version before last commit of sdk published on github
This happens when the project is running... when we are on a page (for example /Project) everything renders fine... but at random time (I can't figure out when it happens) it just gets thrown.
This is the stacktrace
at System.Web.HttpApplication.ThrowIfEventBindingDisallowed()
at System.Web.HttpApplication.RemoveSyncEventHookup(Object key, Delegate handler,
RequestNotification notification, Boolean isPostNotification)
at System.Web.HttpApplication.remove_PostResolveRequestCache(EventHandler value)
at OpenRasta.Hosting.AspNet.OpenRastaModule.<>c__DisplayClass2.<Init>b__1() in c:\TeamCity\buildAgent\work\446ececd36f5f871\src\OpenRasta.Hosting.AspNet\OpenRastaModule.cs:line 75
at OpenRasta.Hosting.AspNet.OpenRastaModule.Dispose() in c:\TeamCity\buildAgent\work\446ececd36f5f871\src\OpenRasta.Hosting.AspNet\OpenRastaModule.cs:line 66
at System.Web.HttpApplication.DisposeInternal()
I hope someone can clarify what I'm doing wrong :)
That'd be because you're on master and that's including some silly code that tries to cleanup stuff that shouldn't be.
Expect a commit this afternoon that'll fix that.
Using watir-webdriver, how do I wait for a page to load after I click a link?
At the moment I am using:
sleep n
But this is not ideal as the page response varies so much.
Is there a way to test whether the page is ready or whether there is a certain element in the page? I understand in the normal Watir gem there is Watir::Waiter.wait_until or something similar, but I don't see this in the webdriver version.
I don't know if they're the best way, but this is how I'm handling this for waiting for an updating div to clear:
while browser.div(:id=>"updating_div").visible? do sleep 1 end
This is how I handle waiting for something to display:
until browser.div(:id=>"some_div").exists? do sleep 1 end
Today's release adds an optional require that brings in some helpers for waiting for elements. These are not (at the moment) available in Watir 1.6, so be aware if you use both libraries side by side.
Check "AJAX and waiting for elements" in the Watir-webdriver Wiki for more information.
The best summary is found in "Waiting".
This is it in a nutshell:
require 'watir-webdriver'
b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
b.select_list(:id => 'entry_1').wait_until_present
b.text_field(:id => 'entry_0').when_present.set 'your name'
b.button(:value => 'Submit').click
b.button(:value => 'Submit').wait_while_present
Watir::Wait.until { b.text.include? 'Thank you' }
This is how I wait for AJAX in my project:
ajax_loader = $b.element(:xpath => "//*[#id='spinner-modal-transparent' and #aria-hidden='true']/div/div/div/div/img[#alt='Ajax transparent loader']")
if ajax_loader.exists?
ajax_loader.wait_while_present(timeout=350)
else
puts "The AJAX loader was not present."
end
browser.wait_until can be used.
It's more helpful because you can define what to wait for in the parameters (()), as in:
browser.wait_until(browser.text.include("some text"))
You can use the wait_until or waituntilExists methods.
I had the same problem, and I tried to fix it by combining wait_until_present and
until browser.div(:id=>"some_div").exists? do sleep 1 end
tricks povided by #marc:
some_div = browser.div(:id => 'some_div')
begin
Watir::Wait.until
some_div.visible?
end
rescue Watir::Wait::TimeoutError
until some_div.visible?
sleep 1
end
end
Notice that it is your own responsibility to make sure that
div(:id => "some_div")
does exist.