Archived
1
0
Fork 0

Added user profile

This commit is contained in:
Fredric N 2010-09-22 22:22:50 +02:00
parent 49ecfc9fbd
commit d3966e2daa
9 changed files with 193 additions and 10 deletions

View file

@ -66,7 +66,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$view->headScript()->appendFile('http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
Zend_Locale::setDefault('sv_SE');
return $view;
}
@ -106,7 +105,9 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
$router = $this->getResource('front')->getRouter();
/*
* Default routes to the default module
*/
$router->addRoute('default', new Zend_Controller_Router_Route(':lang/:controller/:action',
array(
'lang' => 'sv',
@ -116,8 +117,13 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
)
));
/*
* This route allows direct access to IndexController
* without specifying "index" as controller.
*
* Allowed actions need to be specified!
*/
$router->addRoute('index', new Zend_Controller_Router_Route(
':lang/:action',
array(
@ -125,9 +131,17 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
'module' => 'default',
'controller' => 'index',
'action' => 'index'
),
array(
'action' => '(about)'
)
));
/*
* Route to the blog module
* TODO: This prob. needs changing.
*/
$router->addRoute('blog', new Zend_Controller_Router_Route(
':lang/blog/:action/:id',
array(
@ -136,9 +150,12 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
'controller' => 'index',
'action' => 'latest',
'id' => ''
),
array(
'lang' => '(en|sv)'
)
));
$router->addRoute('portfolio', new Zend_Controller_Router_Route(
':lang/portfolio/:action',
array(
@ -148,6 +165,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
'action' => 'index'
)
));
$router->addRoute('admin', new Zend_Controller_Router_Route(
':lang/admin/:action',

View file

@ -3,6 +3,13 @@ blog = blog
about = om fiktiv
example = "Det här är ett exempel på %s och %s"
profile information = "profil information"
user information = "användarinformation"
change password = "ändra lösenord"
firstname = förnamn
lastname = efternamn
email = e-post
password = lösenord
login = logga in

View file

@ -97,4 +97,18 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract
return false;
}
/**
* Change password
*/
public function changePassword($userId, $password)
{
return $this->_dbTable->update(
array(
'password' => hash('sha256',$password)
),
$this->_dbTable->getAdapter()->quoteInto('id = ?',$userId)
);
}
}

View file

@ -115,4 +115,19 @@ class User extends Fiktiv_Model_Abstract
{
return '(' . __CLASS__ . '){' . $this->_email . ' ' . $this->_firstName . ' ' . $this->_lastName . '}';
}
/**
* Convert object to array
*/
public function toArray()
{
return array(
'id' => $this->_id,
'email' => $this->_email,
'firstName' => $this->_firstName,
'lastName' => $this->_lastName,
'isDeleted' => $this->_isDeleted,
'regDate' => $this->_regDate
);
}
}

View file

@ -0,0 +1,100 @@
<?php
class ProfileController extends Fiktiv_Controller_Action
{
public function indexAction()
{
$form = $this->view->form = new Zend_Form();
$form->addElement('text', 'email', array(
'label' => 'u:email',
'validators' => array(new Zend_Validate_EmailAddress())
));
$form->addElement('text', 'firstName', array(
'label' => 'u:firstname',
'validators' => array(new Zend_Validate_Alpha())
));
$form->addElement('text', 'lastName', array(
'label' => 'u:lastname',
'validators' => array(new Zend_Validate_Alpha())
));
$form->addElement('password', 'password', array(
'label' => 'u:password',
'validators' => array(new Zend_Validate_Alnum())
));
$form->addElement('password', 'passwordConfirm', array(
'label' => 'u:confirm password',
'validators' => array(new Zend_Validate_Alnum())
));
$form->addElement('Submit', 'save', array(
'label' => 'u:save'
));
$form->addDisplayGroup(
array(
'email',
'firstName',
'lastName'
),
'partOne',
array(
'legend' => 'u:user information'
)
);
$form->addDisplayGroup(
array(
'password',
'passwordConfirm'
),
'partTwo',
array(
'legend' => 'u:change password'
)
);
$form->addDisplayGroup(
array(
'save'
),
'partThree'
);
if ($this->_request->isPost()) {
$data = $this->_request->getPost();
if ($data['password'] !== $data['passwordConfirm']) {
if (!empty($data['password']))
$this->view->messages = 'passwords dont match';
} else {
if ($this->dataService->User->changePassword(Zend_Auth::getInstance()->getIdentity()->id, $data['password']))
$this->view->messages = 'Lösenordet är ändrat!';
unset($data['password']);
}
unset($data['passwordConfirm']);
unset($data['save']);
$this->dataService->User->update($data, 'id = '.Zend_Auth::getInstance()->getIdentity()->id);
}
$user = $this->dataService->User->findById(Zend_Auth::getInstance()->getIdentity()->id);
$form->populate($user->toArray());
}
}

View file

@ -0,0 +1,12 @@
<h1><?=$this->translate('u:profile') ?></h1>
<?php
if (!empty($this->messages))
echo '<p class="red">' . $this->messages . '</p>';
?>
<p>Lite text</p>
<h3><?=$this->translate('u:profile information') ?></h3>
<?=$this->form ?>

View file

@ -21,4 +21,10 @@ abstract class Fiktiv_Model_Mapper_DbTableAbstract
throw new Fiktiv_Exception('Invalid database table supplied to ' . __CLASS__);
}
}
public function update($data, $where)
{
return $this->_dbTable->update($data, $where);
}
}

View file

@ -37,21 +37,27 @@ abstract class Fiktiv_Translate_Adapter extends Zend_Translate_Adapter
*/
protected function transform($flag, $text)
{
$encoding = mb_detect_encoding($text);
switch ($flag) {
case 'u':
return ucfirst($text);
return mb_strtoupper(mb_substr($text, 0, 1, $encoding), $encoding) . mb_substr($text, 1, strlen($text), $encoding);
break;
case 'uw':
return ucwords($text);
$split = mb_split(' ', $text);
foreach ($split as &$word) {
$word = mb_strtoupper(mb_substr($word, 0, 1, $encoding), $encoding) . mb_substr($word, 1, strlen($word), $encoding);
}
return join(' ', $split);
break;
case 'ua':
return strtoupper($text);
return mb_strtoupper($text, $encoding);
break;
case 'l':
return strtolower($text[0]);
return mb_strtolower(mb_substr($text, 0, 1, $encoding), $encoding) . mb_substr($text, 1, strlen($text), $encoding);
break;
case 'la':
return strtolower($text);
return mb_strtolower($text, $encoding);
break;
}
}

View file

@ -11,14 +11,19 @@ class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract
'controller' => 'auth'
);
$prefix = '';
if ($auth->hasIdentity()) {
$options['action'] = 'logout';
$display = 'u:logout';
$prefix = $auth->getIdentity()->firstName.' (<a href="'.$this->view->url(array('controller' => 'profile'), 'default').'">Profile</a>) ';
} else {
$options['action'] = 'login';
$display = 'u:login';
}
return '<a href="' . $this->view->url($options, 'auth') . '">' . $this->view->translate($display) . '</a>';
return $prefix.'<a href="' . $this->view->url($options, 'auth') . '">' . $this->view->translate($display) . '</a>';
}
}