Snippets - Little bits of code to make you happy
-
SnippetsUsing a Password Validator
18 October 2010 | |
TweetThe Password Validator allows you to set particular criteria for your members passwords. For example if you wanted to have a minimum length of 8 characters and contain lowercase and uppercase characters, well that's a simple case of adding a couple of lines to your _config.php file!
Continue reading... -
SnippetsSet the Redirect after a successful Member Login
31 May 2010 | | | Supports v2.4, v2.3
TweetThe Member system that comes with SilverStripe offers substantial control over your site's authentication capabilities. It often requires the developer to build out or extend most common functionality to websites. This is great in that you are never "stuck" with the out-of-the-box offerings, but as any SS dev knows you end up with a little bag of Member tricks that gets used across many projects. Presented here is one that I use often.
Continue reading... -
SnippetsPreventing malicious SQL injections
12 March 2010 | | | Supports v2.4, v2.3
Tweet
PHP has a very shallow learning curve, it's free and anyone can have a go at making a website by following a few tutorials and implementing their experience with other languages. However, coding for the web can be a risky business, especially with dynamic websites that take some kind of user (or external) input and use that to get data from a database.
Continue reading... -
SnippetsHide pages in Sitetree that a user can't edit
15 September 2009 | | | Supports v2.4, v2.3
Tweet Sometimes you want to hide pages in the Sitetree that members logged into the CMS don't have permission to edit. This is really simple in because they already have a css style applied to them you can just hide that class. You need to include this snippet in your typography.css file so that it is included in the CMS. Continue reading... -
SnippetsHow to access your admin account when you've forgotten the password
22 August 2009 | |
Tweet I managed to forget my admin password and found quite a few ways to unlock an SS install. I originally thought about poking around the database and changing the hashes myself. After reviewing the Security and password encryption code, I would recommend against doing that. SilverStripe uses salted SHA1 encryption which is no fun to try and create yourself. Also you'd have to update multiple tables to get the password changed. Luckily the SS Core team has included multiple features for accomplishing this. The options below assume you have access to your webserver to use some PHP code. Continue reading... -
SnippetsRemoving an Item From the Main CMS Menu
3 July 2009 | |
TweetIf you want to remove an item from the CMSTopMenu without making it inaccessible you can add this line to your _config.php file:
CMSMenu::remove_menu_item('SecurityAdmin');Continue reading... -
SnippetsUsing canCreate(), canEdit(), canDelete() and canPublish() to manage page type permissions
23 June 2009 | | | Supports v2.4, v2.3
TweetOften you will want to control which users can create, edit, delete and publish certain page types. For example you may only want high level users to be able to create ContactPage page types, or prevent low level users from deleting HomePage page types. This can easily be achieved by adding these functions to the page type model (usually just before getCMSFields()). Then within the function you can define conditionals which decide whether to return true or false.
Continue reading... -
SnippetsCreate and use a Permission code
18 April 2009 | | | Supports v2.4, v2.3
TweetHave you wanted to add an extra permission code that you can add to groups and then use that to test whether a particular user has that permission? Here's how it's done. The permission code it self is added via the Controller class, then you use a permission check anywhere in your site code to check the current user. Like so:
Continue reading...