{"id":116,"date":"2008-08-18T10:38:47","date_gmt":"2008-08-18T18:38:47","guid":{"rendered":"http:\/\/www.codebelay.com\/blog\/?p=116"},"modified":"2008-09-22T10:46:52","modified_gmt":"2008-09-22T18:46:52","slug":"installing-sfguardplugin-in-symfony-11-a-guide-for-the-perplexed","status":"publish","type":"post","link":"https:\/\/www.codebelay.com\/blog\/2008\/08\/18\/installing-sfguardplugin-in-symfony-11-a-guide-for-the-perplexed\/","title":{"rendered":"Installing sfGuardPlugin in symfony 1.1 &#8212; A Guide for the Perplexed"},"content":{"rendered":"<p>Like the verbally creative barfly, who is a dead ringer for a 21+ <a href=\"http:\/\/en.wikipedia.org\/wiki\/Juno_(film)\">Juno<\/a>, that you picked up  during last call on a Friday night, <a href=\"http:\/\/www.symfony-project.org\/\">symfony 1.1<\/a> starts to grow on you. Nevermind your friends, who found <a href=\"http:\/\/www.erlang.org\/\">Erlang<\/a> in some higher-scale, hipster, hippy hang out. They tell you it&#8217;s time to leave symfony 1.1. You&#8217;re perversely drawn to this framework and don&#8217;t mind racking up the future therapy bills.<\/p>\n<p>God is dead, and so everything is permitted, unless you can install something like symfony 1.1&#8217;s sfGuardPlugin to add logins and login protection to web pages.  Like the initiation rites into the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Eleusinian_Mysteries\">Eleusinian mysteries<\/a> or the Freemasons, not everything is articulated on how to do the install. But below, for the first time, it is.<\/p>\n<p>Note: I use psymfony as an alias which really just means &#8216;php symfony&#8217;.<\/p>\n<ul>\n<li>psymfony generate:app backend<\/li>\n<\/ul>\n<p>Now you can start following <a href=\"http:\/\/www.symfony-project.org\/plugins\/sfGuardPlugin\">the guide written on the symfony website<\/a>. Below is just from my shell&#8217;s history log:<\/p>\n<ul>\n<li>psymfony plugin:install sfGuardPlugin<\/li>\n<li>psymfony propel:build-model<\/li>\n<li>psymfony propel:build-sql<\/li>\n<li>psymfony propel:insert-sql &#8212; this didn&#8217;t work for me so I ended up just doing: mysql -uusername -p < data\/sql\/plugins.sfGuardPlugin.lib.model.schema.sql<\/li>\n<li>follow the instructions in the guide above for fixtures<\/li>\n<li>psymfony propel:data-load frontend<\/li>\n<li>psymfony propel:data-load backend<\/li>\n<li>vim apps\/frontend\/config\/settings.yml <\/li>\n<li>vim apps\/backend\/config\/settings.yml <\/li>\n<li>psymfony cc<\/li>\n<\/ul>\n<p>But you&#8217;re not done yet. Are you running into a propel connection error? Then you might have to <a href=\"http:\/\/vinodkram.wordpress.com\/2008\/04\/05\/no-connection-params-set-for-propel\/\">edit some yaml files based on this blog post<\/a>.<\/p>\n<p>In my case, I ended up having to edit config\/databases.yaml by adding the following below:<\/p>\n<pre>\r\n   propel:\r\n     class:          sfPropelDatabase\r\n     param:\r\n       phptype: mysql\r\n       host: localhost\r\n       database: dev_starster\r\n       username: writes\r\n       password: some_wicked_sick_password\r\n       dsn:          mysql:\/\/writes@localhost\/dev_starster\r\n       datasource: propel\r\n<\/pre>\n<p>Are we out of the woods yet?<\/p>\n<p>Unfortunately, symfony 1.1 has a signout bug, where sessions are not entirely cleared. Thanks<a href=\"http:\/\/eatmymonkeydust.com\/2008\/08\/symfony-security-sessions-not-cleared-when-logging-out\/\"> to this blog post<\/a>, I was able to hack something together.<\/p>\n<p>In apps\/yourapp\/modules\/sfGuardAuth\/actions\/actions.class.php write:<\/p>\n<p><code> public function executeSignout()<br \/>\n   {<br \/>\n     if (sfConfig::get('sf_environment') != 'test')<br \/>\n     {<br \/>\n        session_destroy();<br \/>\n        session_write_close();<br \/>\n        session_regenerate_id();<br \/>\n     }<br \/>\n     parent::executeSignout();<br \/>\n   }<\/p>\n<p><\/code><\/p>\n<p>You might have to link the sf_guard_user table to an account table, if you want the account table to do the authorization instead. If so edit apps\/modulename\/config\/app.yml by adding something that looks like this:<\/p>\n<pre>\r\n  sf_guard_plugin:\r\n    algorithm_callable: md5\r\n    success_signin_url: @homepage\r\n    profile_class: sfGuardUserProfile\r\n    profile_field_name: account_id\r\n    check_password_callable: [Account, checkPassword]\r\n<\/pre>\n<p>In the lib\/model\/Account.php you should add code that looks like this:<\/p>\n<pre>\r\n  public static function checkPassword($username, $password) {\r\n  \t$c = new Criteria();\r\n  \t$c->add(AccountPeer::EMAIL, $username);\r\n  \t$c->add(AccountPeer::PASSWORD, md5($password));\r\n  \t$rac = AccountPeer::doSelect($c);\r\n  \t\/\/print_r($rac) ; die();\r\n  \tif ($rac == TRUE) {\r\n  \t\treturn TRUE;\r\n  \t} else {\r\n  \t\treturn FALSE;\r\n  \t}\r\n  }\r\n<\/pre>\n<p>Here is a list of links that made getting the plugin working possible:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.symfony-project.org\/plugins\/sfGuardPlugin\">The official symfony plugin install guide page<\/a> on the<a href=\"http:\/\/www.symfony-project.org\/\"> symfony-project website<\/a>.<\/li>\n<li><a href=\"http:\/\/eatmymonkeydust.com\/2008\/07\/symfony-sfguarduser-remember-me-checkboxcookie-does-not-work\/\">Does your remember me cookie not work? <\/a><\/li>\n<li><a href=\"http:\/\/www.dahle-ethos.com\/blog\/?p=28\">Do you need to secure a module? And not the whole app?<\/a>\n<li><a href=\"http:\/\/www.jonathanwohl.com\/blog\/?p=5\">A great, short guide on security specific modules and actions<\/a><\/li>\n<li>If you need to <a href=\"http:\/\/www.matthewbull.net\/2008\/06\/29\/symfonys-sfguard-plugin-and-ldap\/\">link the sf_guard_user login table to your user account table, this blog post provides a clue<\/a>.<\/li>\n<p>Thank you to the symfony community on irc.freenode.net in #symfony. Thank you to <a href=\"http:\/\/www.sensiolabs.com\/\">Sensiolabs<\/a> and Sensio&#8217;s CEO, Fabien Potencier for writing symfony-1.1.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Like the verbally creative barfly, who is a dead ringer for a 21+ Juno, that you picked up during last call on a Friday night, symfony 1.1 starts to grow on you. Nevermind your friends, who found Erlang in some higher-scale, hipster, hippy hang out. They tell you it&#8217;s time to leave symfony 1.1. You&#8217;re [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,56,33],"tags":[391,113,112,110,109],"class_list":["post-116","post","type-post","status-publish","format-standard","hentry","category-how-to","category-php","category-webapps","tag-php","tag-sfguardauth","tag-sfguardplugin","tag-symfony","tag-symfony-11"],"_links":{"self":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/comments?post=116"}],"version-history":[{"count":0,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/posts\/116\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/media?parent=116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/categories?post=116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codebelay.com\/blog\/wp-json\/wp\/v2\/tags?post=116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}