summaryrefslogtreecommitdiff
path: root/demos/blog/protected/Pages/Users
diff options
context:
space:
mode:
Diffstat (limited to 'demos/blog/protected/Pages/Users')
-rw-r--r--demos/blog/protected/Pages/Users/EditUser.page31
-rw-r--r--demos/blog/protected/Pages/Users/EditUser.php38
-rw-r--r--demos/blog/protected/Pages/Users/NewUser.page47
-rw-r--r--demos/blog/protected/Pages/Users/NewUser.php31
-rw-r--r--demos/blog/protected/Pages/Users/ViewUser.page47
-rw-r--r--demos/blog/protected/Pages/Users/ViewUser.php41
6 files changed, 171 insertions, 64 deletions
diff --git a/demos/blog/protected/Pages/Users/EditUser.page b/demos/blog/protected/Pages/Users/EditUser.page
index 8c21fd50..0155dc26 100644
--- a/demos/blog/protected/Pages/Users/EditUser.page
+++ b/demos/blog/protected/Pages/Users/EditUser.page
@@ -1,14 +1,12 @@
-<com:TContent ID="Main">
-
-<h2>Update Profile</h2>
+<%@ Title="Edit Profile" %>
-<com:TValidationSummary Display="Dynamic" ValidationGroup="user" />
+<com:TContent ID="Main">
-<span class="input-label">Username</span>
-<br/>
-<com:TLabel ID="Username" />
+<h2>Update Profile: <com:TLabel ID="Username" /></h2>
-<br/>
+<com:TValidationSummary
+ Display="Dynamic"
+ ValidationGroup="user" />
<span class="input-label">Full name</span>
<br/>
@@ -26,7 +24,7 @@
RegularExpression="[\w\.]{6,16}"
Text="*"
ErrorMessage="Your password must contain only letters, digits and underscores, and it must contain at least 6 and at most 16 characters."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />
<br/>
@@ -40,7 +38,7 @@
Display="Dynamic"
Text="*"
ErrorMessage="Your password entries did not match."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error3" />
<br/>
@@ -52,23 +50,28 @@
ValidationGroup="user"
Text="*"
ErrorMessage="Please provide your email address."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />
<com:TEmailAddressValidator
ControlToValidate="Email"
ValidationGroup="user"
Display="Dynamic"
Text="*"
ErrorMessage="You entered an invalid email address."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error2" />
<br/>
<span class="input-label">Personal Website</span>
<br/>
-<com:TTextBox ID="Website" AutoTrim="true" />
+<com:TTextBox ID="Website" AutoTrim="true" Columns="40"/>
<br/>
+<br/>
-<com:TLinkButton Text="Save" ValidationGroup="user" OnClick="saveButtonClicked" />
+<com:TLinkButton
+ Text="Save"
+ ValidationGroup="user"
+ CssClass="link-button"
+ OnClick="saveButtonClicked" />
</com:TContent> \ No newline at end of file
diff --git a/demos/blog/protected/Pages/Users/EditUser.php b/demos/blog/protected/Pages/Users/EditUser.php
index e3efcfd1..73eef8bb 100644
--- a/demos/blog/protected/Pages/Users/EditUser.php
+++ b/demos/blog/protected/Pages/Users/EditUser.php
@@ -1,13 +1,39 @@
<?php
+/**
+ * EditUser class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * EditUser class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ */
class EditUser extends BlogPage
{
- public function getCurrentUser()
+ private $_userRecord=null;
+
+ public function onInit($param)
{
- if(($user=$this->DataAccess->queryUserByID($this->User->ID))!==null)
- return $user;
+ parent::onInit($param);
+ if(($id=$this->Request['id'])!==null)
+ {
+ $id=TPropertyValue::ensureInteger($id);
+ if(!$this->User->IsAdmin && $this->User->ID!==$id)
+ throw new BlogException(500,'profile_edit_disallowed',$id);
+ }
else
- throw new BlogException('xxx');
+ $id=$this->User->ID;
+ if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null)
+ throw new BlogException(500,'profile_id_invalid',$id);
}
public function onLoad($param)
@@ -15,7 +41,7 @@ class EditUser extends BlogPage
parent::onLoad($param);
if(!$this->IsPostBack)
{
- $userRecord=$this->getCurrentUser();
+ $userRecord=$this->_userRecord;
$this->Username->Text=$userRecord->Name;
$this->FullName->Text=$userRecord->FullName;
$this->Email->Text=$userRecord->Email;
@@ -27,7 +53,7 @@ class EditUser extends BlogPage
{
if($this->IsValid)
{
- $userRecord=$this->getCurrentUser();
+ $userRecord=$this->_userRecord;
if($this->Password->Text!=='')
$userRecord->Password=md5($this->Password->Text);
$userRecord->FullName=$this->FullName->Text;
diff --git a/demos/blog/protected/Pages/Users/NewUser.page b/demos/blog/protected/Pages/Users/NewUser.page
index eba2dcec..f096ffb1 100644
--- a/demos/blog/protected/Pages/Users/NewUser.page
+++ b/demos/blog/protected/Pages/Users/NewUser.page
@@ -1,35 +1,39 @@
+<%@ Title="Create New Account" %>
+
<com:TContent ID="Main">
<h2>Create New Account</h2>
-<com:TValidationSummary Display="Dynamic" ValidationGroup="NewUser" />
+<com:TValidationSummary
+ Display="Dynamic"
+ ValidationGroup="user" />
<span class="input-label">Username</span>
<br/>
<com:TTextBox ID="Username" />
<com:TRequiredFieldValidator
ControlToValidate="Username"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
Text="*"
ErrorMessage="Please choose a username."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />
<com:TRegularExpressionValidator
ControlToValidate="Username"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
RegularExpression="[\w]{3,16}"
Text="*"
ErrorMessage="Your username must contain only letters, digits and underscores, and it must contain at least 3 and at most 16 characters."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error2" />
<com:TCustomValidator
ControlToValidate="Username"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
OnServerValidate="checkUsername"
Text="*"
ErrorMessage="Sorry, your username is taken by someone else. Please choose another username."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error3" />
<br/>
@@ -44,19 +48,19 @@
<com:TTextBox ID="Password" TextMode="Password" />
<com:TRequiredFieldValidator
ControlToValidate="Password"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
Text="*"
ErrorMessage="Please choose a password."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />
<com:TRegularExpressionValidator
ControlToValidate="Password"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
RegularExpression="[\w\.]{6,16}"
Text="*"
ErrorMessage="Your password must contain only letters, digits and underscores, and it must contain at least 6 and at most 16 characters."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error2" />
<br/>
@@ -66,11 +70,11 @@
<com:TCompareValidator
ControlToValidate="Password"
ControlToCompare="Password2"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
Text="*"
ErrorMessage="Your password entries did not match."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error3" />
<br/>
@@ -79,26 +83,31 @@
<com:TTextBox ID="Email" />
<com:TRequiredFieldValidator
ControlToValidate="Email"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Text="*"
ErrorMessage="Please provide your email address."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error1" />
<com:TEmailAddressValidator
ControlToValidate="Email"
- ValidationGroup="NewUser"
+ ValidationGroup="user"
Display="Dynamic"
Text="*"
ErrorMessage="You entered an invalid email address."
- ControlCssClass="inputerror" />
+ ControlCssClass="input-error2" />
<br/>
<span class="input-label">Personal Website</span>
<br/>
-<com:TTextBox ID="Website" AutoTrim="true" />
+<com:TTextBox ID="Website" AutoTrim="true" Columns="40"/>
<br/>
+<br/>
-<com:TLinkButton Text="Register" ValidationGroup="NewUser" OnClick="createUser" />
+<com:TLinkButton
+ Text="Register"
+ ValidationGroup="user"
+ CssClass="link-button"
+ OnClick="createUser" />
</com:TContent> \ No newline at end of file
diff --git a/demos/blog/protected/Pages/Users/NewUser.php b/demos/blog/protected/Pages/Users/NewUser.php
index 166abf66..50a8100b 100644
--- a/demos/blog/protected/Pages/Users/NewUser.php
+++ b/demos/blog/protected/Pages/Users/NewUser.php
@@ -1,10 +1,33 @@
<?php
+/**
+ * NewUser class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * NewUser class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ */
class NewUser extends BlogPage
{
+ public function onInit($param)
+ {
+ if(!$this->User->IsAdmin && !TPropertyValue::ensureBoolean($this->Application->Parameters['MultipleUser']))
+ throw new BlogException(500,'newuser_registration_disallowed');
+ }
+
public function checkUsername($sender,$param)
{
- $username=$this->Username->Text;
+ $username=strtolower($this->Username->Text);
$param->IsValid=$this->DataAccess->queryUserByName($username)===null;
}
@@ -13,13 +36,17 @@ class NewUser extends BlogPage
if($this->IsValid)
{
$userRecord=new UserRecord;
- $userRecord->Name=$this->Username->Text;
+ $userRecord->Name=strtolower($this->Username->Text);
$userRecord->FullName=$this->FullName->Text;
$userRecord->Role=0;
$userRecord->Password=md5($this->Password->Text);
$userRecord->Email=$this->Email->Text;
$userRecord->CreateTime=time();
$userRecord->Website=$this->Website->Text;
+ if(TPropertyValue::ensureBoolean($this->Application->Parameters['AccountApproval']))
+ $userRecord->Status=UserRecord::STATUS_PENDING;
+ else
+ $userRecord->Status=UserRecord::STATUS_NORMAL;
$this->DataAccess->insertUser($userRecord);
$authManager=$this->Application->getModule('auth');
$authManager->login($this->Username->Text,$this->Password->Text);
diff --git a/demos/blog/protected/Pages/Users/ViewUser.page b/demos/blog/protected/Pages/Users/ViewUser.page
index 2dba6b77..faae720b 100644
--- a/demos/blog/protected/Pages/Users/ViewUser.page
+++ b/demos/blog/protected/Pages/Users/ViewUser.page
@@ -1,21 +1,40 @@
+<%@ Title="View User Profile" %>
+
<com:TContent ID="Main">
<h2>User Profile</h2>
-Username: <%= $this->CurrentUser->Name %>
-<br/>
-
-Full name: <%= $this->CurrentUser->FullName %>
-<br/>
-
-Email: <%= $this->CurrentUser->Email %>
+<table class="profile-table">
+<tr>
+ <td class="profile-table-label">Username</td>
+ <td class="profile-table-value"><%= $this->Profile->Name %></td>
+</tr>
+<tr>
+ <td class="profile-table-label">Full name</td>
+ <td class="profile-table-value"><%= htmlentities($this->Profile->FullName,ENT_QUOTES,'UTF-8') %></td>
+</tr>
+<tr>
+ <td class="profile-table-label">Email</td>
+ <td class="profile-table-value"><%= $this->Profile->Email %></td>
+</tr>
+<tr>
+ <td class="profile-table-label">Role</td>
+ <td class="profile-table-value"><%= $this->Profile->Role===0? 'Normal user':'Administrator' %></td>
+</tr>
+<tr>
+ <td class="profile-table-label">Website</td>
+ <td class="profile-table-value"><%= htmlentities($this->Profile->Website,ENT_QUOTES,'UTF-8') %></td>
+</tr>
+<tr>
+ <td class="profile-table-label">Member since</td>
+ <td class="profile-table-value"><%= date('l, F j, Y',$this->Profile->CreateTime) %></td>
+</tr>
+</table>
<br/>
-
-Privilege: <%= $this->CurrentUser->Role===0? 'User':'Administrator' %>
-<br/>
-
-Personal website: <%= $this->CurrentUser->Website %>
-<br/>
-
+<com:THyperLink
+ Text="Update"
+ NavigateUrl=<%= $this->Service->constructUrl('Users.EditUser',array('id'=>$this->Profile->ID)) %>
+ Visible=<%= $this->User->IsAdmin || $this->Profile->ID===$this->User->ID %>
+ CssClass="link-button" />
</com:TContent> \ No newline at end of file
diff --git a/demos/blog/protected/Pages/Users/ViewUser.php b/demos/blog/protected/Pages/Users/ViewUser.php
index 3485f56b..453ae349 100644
--- a/demos/blog/protected/Pages/Users/ViewUser.php
+++ b/demos/blog/protected/Pages/Users/ViewUser.php
@@ -1,18 +1,41 @@
<?php
+/**
+ * ViewUser class file
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ */
+/**
+ * ViewUser class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2006 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ */
class ViewUser extends BlogPage
{
- private $_currentUser=null;
+ private $_userRecord=null;
- public function getCurrentUser()
+ public function onInit($param)
{
- if($this->_currentUser===null)
- {
- $id=TPropertyValue::ensureInteger($this->Request['id']);
- if(($this->_currentUser=$this->DataAccess->queryUserByID($id))===null)
- throw new BlogException('xxx');
- }
- return $this->_currentUser;
+ parent::onInit($param);
+ if(($id=$this->Request['id'])!==null)
+ $id=TPropertyValue::ensureInteger($id);
+ else
+ $id=$this->User->ID;
+ if(($this->_userRecord=$this->DataAccess->queryUserByID($id))===null)
+ throw new BlogException(500,'profile_id_invalid',$id);
+ $this->_userRecord->Email=strtr(strtoupper($this->_userRecord->Email),array('@'=>' at ','.'=>' dot '));
+ }
+
+ public function getProfile()
+ {
+ return $this->_userRecord;
}
}