12
Mar
Posted by Chris Hartjes in Uncategorized. 5 Comments
My in-box is filling up with rejection emails from various places because some asshole spammer decided to use my domain name to send their spam. Trust me, there’s only three addresses that send out mail from littlehart.net and HolliscezanneMorse is not one of them.
My apologies to anyone who’s gotten spam from someone claiming to be at the littlehart.net domain. It isn’t me.
Article Tags >>
spam
27
Feb
Posted by Chris Hartjes in Uncategorized. 6 Comments
I’m sitting in the Orlando airport at this ungodly hour waiting for a flight to Memphis as part of an Orlando -> Memphis -> Toronto trip back from my two days at the Newspaper Association of America conference. I was there with my employer to help start promoting the project I’ve been working on. It was an interesting show, and I had a great time in the booth hanging out and talking with Ken Zajac from The Sports Network and Digger Turnbull from Fantasy Sports Services. It was fun huddling around Digger’s computer listening to the latest moves during the NHL’s trading deadline day.
Anyway, enough geeking out about my sports fetish. Work took up a lot of my time this last 2 weeks getting ready for the demo, so my posting has suffered a bit. Here are some of the things I’ve been thinking about.:
- more and more messages about using the CakePHP Auth component on the mailing list
- I will be doing some Python work later this week on a utility to rip through some of our archived XML documents at work and do some search-and-replace ninja work.
- Investing in using jQuery for work has made for some super-quick integration of some new features. It took me under half-an-hour from the first search in google to get an autocomplete plugin for jQuery working. Now *that* is rapid development
- Despite my best efforts I can’t get vim setup and working the way I want. Sorry Kevin, TextMate is just the best one for me, and Komodo when I need to break out the Xdebug guns
- I’m going to put together a post (and contribute the same info to the CakePHP Cookbook) on my experiences with custom pagination usage with Cake, since I had to hack something together for recent changes I’ve been working on for the IBL website
Anyway, enough talking. It’s way too early to do this sort of nonsense (can’t believe I have coherent thoughts at 5:30AM) and it’s close to boarding time. See you on the other side…
Article Tags >>
CakePHP ||
Chris' Brain ||
Sportso
22
Jan
Posted by Chris Hartjes in Uncategorized. 26 Comments
I got a question in the comments about my previous post on simple user registration about how to do some of the necessary validation for registration in the model. I thought I'd show some code I did to do exactly that.
The key to all this stuff is using a second form field for doing the validation. Here's some sample code for you, based on the latest straight-from-svn version of Cake PHP 1.2 (r6402)
PHP:
-
<?php
-
-
/**
-
* Class used for user authentication on the league website
-
*
-
*/
-
-
class User extends AppModel
-
{
-
var $name = 'User';
-
-
-
'id' =>
array('rule' =>
'blank',
-
'on' => 'create'),
-
'username' =>
array('rule' =>
'alphanumeric',
-
'required' => true,
-
'message' => 'Please enter a username'),
-
'password' =>
array('rule' =>
array('confirmPassword',
'password'),
-
'message' => 'Passwords do not match'),
-
'password_confirm' =>
array('rule' =>
'alphanumeric',
-
'required' => true)
-
);
-
-
function confirmPassword($data) {
-
$valid = false;
-
-
if ($data['password'] == Security::hash(Configure::read('Security.salt') . $this->data['User']['password_confirm'])) {
-
$valid = true;
-
}
-
-
return $valid;
-
}
-
-
}
-
?>
So, let's talk about what's in there.
- make sure that the username is alphanumeric and has been entered
- make sure the password exists and run the custom validation function 'confirmPassword' on the data being posted in
- make sure that our confirm password field exists and is alphanumeric
The only tricky thing when I made this was figuring out how to compare the two password fields, and where to get the proper hashing from. Initially I thought that I could somehow import the Auth component in there but a quick chat with gwoo showed me how stupid that was when I could just duplicate how the component itself is hashing the password field. That's what is going in with the use of Security::hash(...).
Hope that helps.
Article Tags >>
auth ||
CakePHP
11
Jan
Posted by Chris Hartjes in Uncategorized. 9 Comments
A work project is getting close to 0.1 status. Pretty underwhelming, I know. One of the last 'milestones' for 0.1 is taking these wonderful XML documents that my web app creates (and stores in eXist and sends them to an internal web service that reads in the XML and breaks it apart for use by a wide variety of other company applications. This web service will accept documents via an HTTP PUT (you know, GET, POST and it's neglected siblings PUT and DELETE) so I dug around a bit on the web (ignoring one cranky co-worker's complaints that real programmers read RFC's, or at least *know* what an RFC is) and put together some code
PHP:
-
function _publish($service, $doc) {
-
-
-
'method' => 'PUT'));
-
-
$fp =
fopen($service,
'rb',
false,
$context);
-
-
-
if ($response === false) {
-
return false;
-
}
-
-
// Pull out the status code from the header
-
-
preg_match_all("/HTTP\/1\.[1|0]\s(\d{3})/",
$metaData['wrapper_data'][0],
$matches);
-
$code =
end($matches[1]);
-
-
if ($code == 200) {
-
return true;
-
} else {
-
return false;
-
}
-
}
The only tricky thing here really is the use of the end function to grab that last match of the status codes. I got the code for doing the preg_match from this site and it seems to work just fine. The reason to use end(...) as far as I can tell is to make sure that I only get the last match of the group. Neat little trick and the link I posted demonstrates it.
I'm also quite proud that it's cURL free, as cURL seems to be the first option that most people use when doing this kind of thing. There is some existing code that is using cURL that I *might* refactor to use the streams-driven stuff that I've been playing with.
Article Tags >>
http-put ||
PHP
2
Jan
Posted by Chris Hartjes in Uncategorized. No Comments
While speaking with nate last night via IM, he told me about the latest set of changes for CakePHP 1.2. There is simply just too much to mention, so I suggest heading on over to the brand-spanking-new CakePHP home page and checking out the changelog. There's a lot in there, but take the time to go through it. Besides, you might find that a particular bug that had been bothering you has been fixed.
My own modest contribution to the latest release was contributing some work in the 'bake' utility to allow you to select what database configuration you wanted to use (it was hard-coded before), and allowing you to bake a plugin (which is sort of like a stand-alone module within an application. Yes, there were a few tweaks afterwards by gwoo but he told me (or maybe lied to me to soothe my ego) that a lot of my code was still in there.
So, CakePHP 1.2 stable looks like it's getting closer and closer, so don't be afraid to move from 1.1 to 1.2. The improvements are worth it as 1.2.x is probably the most stable piece of "alpha" or "beta" software I've come across.
Article Tags >>
CakePHP ||
PHP
Recent Comments