Showing posts with label devlopment. Show all posts
Showing posts with label devlopment. Show all posts

Thursday, 7 January 2010

sfDoctrineGuardPlugin login with email bug

There is a bug in 4.0.1, but it's been patched here

NB: you may need to subscribe to the symfony project site in order to see the ticket - but if you haven't already, why are you reading about symfony bugs! LOL

How to display source code with line numbers and formatting in blogger

While setting up this blog, I realised I wanted some nicely formatted source code. As I'm blogging about coding, even if it is for my own use mainly, I wanted a solution that made the source code easy to read.

I settled on (after not too long a search) these two ideas which I have combined into one....


OK, so the css solution works like a charm, no need to go into detail here just pop over to the link above for details. Kudos to The Blogger Guide.

However, I had to tweak the line numbers solution. Again, most of the description at that site is valid, but I changed the way the new content is generated, not least using lists rather than tables. This should still  allow for content to be copied and pasted ok too.

Enjoy :)


Anyway, I'm not going through everything here as it's all been covered in the two links above. but I have posted the javascript and css I'm using on this site as a starting point:

CSS
pre {     border:1px dashed #aaaaaa;     background:#eeeeee;     white-space:pre;     font-family:monospace;     font-size:9pt;     line-height: 10pt;     height:auto;     width:auto;     padding:5px;     overflow:auto; } ol.pre {     margin: 0 0 0 15px;      padding: 0px;      padding-left: 5px; } .pre li {     margin: 0;     padding: 0;      background: none !important; }
and the JavaScript
function showLineNumbers() {
    /****************************************
    * Written by Andreas Papadopoulos       *
    * http://akomaenablog.blogspot.com      *
    * akoma1blog@yahoo.com                  *
    *                                       *
    * And heavily refactored by Matt Keeble *
    * http://codinginharmony.blogspot.com   *
    ****************************************/
    
    var isIE = navigator.appName.indexOf('Microsoft') != -1;
    var preElems = document.getElementsByTagName('pre');
    if (preElems.length == 0) return;

    for (var i = 0; i < preElems.length; i++) {
        var pre = preElems[i];
        var oldContent = pre.innerHTML;
        oldContent = oldContent.replace(/ /g," ");
        oldContent = oldContent.replace(/\n/g, "<br />");
        var strs = oldContent.split("<br />");
        
        if (isIE) {
            strs = oldContent.split("<BR />");
        }
                
        if(oldContent.substring(0,4) == '<br />')
        {
            oldContent = oldContent.substring(4);
        }
        
        newContent = '<ol class="pre">';
        if(strs.length == 1)
        {
            newContent+= "<li>"+strs+"</li>";
        } 
        else
        {        
            for(var j=0; j < strs.length; j++) {
                if(strs[j] !== '')    newContent += "<li>"+strs[j]+"</li>"
            }
        }
        newContent+= "</ol>";
        pre.innerHTML = newContent;
    }
}

sfDoctrineGuardPlugin and custom algorithms

OK - so I have hunted around for a solution to this problem twice now and struggled to find it. So as my memory's crap, I've decided to start this blog in order to capture the solutions, hints & tips I find. (yeah, this is the first post...)

So the problem is, that when using the symfony doctrine:data-load to import new data into my app, the sf_guard_user table was not being updated with the correct algorithm. Whatever happened, the default 'sha1' algorithm was being used.

I finally realised, that my app specific settings for the alogrithm_callable option were not being called during the data-load process, even though they were within the app - this obviously caused problems when trying to log in users constructed during the build/load process from the command line.

There are two solutions: 

The hard way
The reason it's the hard way is because it relies on my memory... the solution is to add the application option to the data-load task. So instead of just calling symfony doctrine:data-load actually call
symfony doctrine:data-load --application=frontend
(replacing frontend with the correct application name of course!)

The easy way
This solution is more robust because I don't have to remember to do anything different from normal.... basically, create app.yml in the project's config directory and add the option there. This way, you don't need to remember any additional options when running data-load and if you do want a different alogrithm to be used for your backend application for example (to ensure your customers can't login to the admin section without worrying about permissions) you can override the option on an app-by-app basis.
    So all is good - should solve the problem! I'm off to refactor my code :)

    [UPDATE:] make sure you run
    ./symfony cc
    to clear the cache before you try and reload the data - otherwise it won't work