From 1f2bb263c1df2bc3ab7274dde02522bfb710146d Mon Sep 17 00:00:00 2001
From: "qiang.xue"
Date: Tue, 7 Oct 2008 03:02:58 +0000
Subject: [PATCH] Added CAPTCHA to application generated by yiic webapp
---
CHANGELOG | 1 +
.../protected/controllers/UserController.php | 28 +++++++++++++++++++
.../webapp/protected/views/user/login.php | 13 +++++++++
3 files changed, 42 insertions(+)
diff --git a/CHANGELOG b/CHANGELOG
index f2fd06213..04880238a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
Version 1.0b To be released
===========================
- Added CWebServiceAction.serviceOptions
+- Added CAPTCHA to application generated by yiic webapp
Version 1.0a October 5, 2008
=============================
diff --git a/framework/cli/views/webapp/protected/controllers/UserController.php b/framework/cli/views/webapp/protected/controllers/UserController.php
index a5291e33b..619de793a 100644
--- a/framework/cli/views/webapp/protected/controllers/UserController.php
+++ b/framework/cli/views/webapp/protected/controllers/UserController.php
@@ -2,6 +2,20 @@
class UserController extends CController
{
+ /**
+ * Declares class-based actions.
+ */
+ public function actions()
+ {
+ return array(
+ // captcha action renders the CAPTCHA image
+ 'captcha'=>array(
+ 'class'=>'CCaptchaAction',
+ 'backColor'=>0xEBF4FB,
+ ),
+ );
+ }
+
/**
* Displays a login form to login a user.
*/
@@ -41,6 +55,7 @@ class LoginForm extends CFormModel
public $username;
public $password;
public $rememberMe;
+ public $verifyCode;
/**
* Declares the validation rules.
@@ -51,10 +66,23 @@ class LoginForm extends CFormModel
{
return array(
array('username, password', 'required'),
+ array('verifyCode', 'captcha', 'allowEmpty'=>!extension_loaded('gd')),
array('password', 'authenticate'),
);
}
+ /**
+ * Declares attribute labels.
+ * If not declared here, an attribute would have a label
+ * the same as the attribute name with the first letter in upper case.
+ */
+ public function attributeLabels()
+ {
+ return array(
+ 'verifyCode'=>'Verification Code',
+ );
+ }
+
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
diff --git a/framework/cli/views/webapp/protected/views/user/login.php b/framework/cli/views/webapp/protected/views/user/login.php
index 51e8fd246..d6006afd9 100644
--- a/framework/cli/views/webapp/protected/views/user/login.php
+++ b/framework/cli/views/webapp/protected/views/user/login.php
@@ -18,6 +18,19 @@ Hint: You may login with demo/demo.
+
+
+
+
+ widget('CCaptcha'); ?>
+
+
+
+
Please enter the letters as they are shown in the image above.
+
Letters are not case-sensitive.
+
+
+
Remember me next time