diff --git a/AlterTable.sql b/AlterTable.sql new file mode 100644 index 00000000..7b5da54e --- /dev/null +++ b/AlterTable.sql @@ -0,0 +1,15 @@ +ALTER TABLE users ADD `usr_password_salt` varchar(100) DEFAULT NULL COMMENT 'dynamicSalt', + +INSERT INTO `users` VALUES (2,'stoyan','50f2405710d1ea8a0e6a0d6b4471586c','stoyan@hotmail.com',NULL,NULL,1,NULL,NULL,NULL,'eqwe3213'); + +string to encripting: aFGQ475SDsdfsaf2342passwordeqwe3213 + +ALTER TABLE users ADD `usr_registration_date` DATETIME DEFAULT NULL COMMENT 'Registration moment'; +ALTER TABLE users ADD `usr_registration_token` varchar(100) DEFAULT NULL COMMENT 'unique id sent by e-mail'; + +ALTER TABLE users ADD `usr_email_cofirmed` tinyint(1) NOT NULL COMMENT 'e-mail confirmed by user'; + +=========== Error and correction =============================================== +ALTER TABLE users ADD `usr_email_cofirmed` tinyint(1) NOT NULL COMMENT 'e-mail confirmed by user'; + +ALTER TABLE users CHANGE `usr_email_cofirmed` `usr_email_confirmed` tinyint(1) NOT NULL COMMENT 'e-mail confirmed by user'; \ No newline at end of file diff --git a/composer.autoload.coolcsn.json.dist b/composer.autoload.coolcsn.json.dist new file mode 100644 index 00000000..dae72ed7 --- /dev/null +++ b/composer.autoload.coolcsn.json.dist @@ -0,0 +1,29 @@ +{ + "name": "zendframework/skeleton-application", + "description": "Skeleton Application for ZF2", + "license": "BSD-3-Clause", + "keywords": [ + "framework", + "zf2" + ], + "homepage": "http://framework.zend.com/", + "minimum-stability": "alpha", + "repositories": [ + { + "type": "composer", + "url": "http://packages.zendframework.com/" + } + ], + "require": { + "php": ">=5.3.3", + "zendframework/zendframework": "2.*", + "zendframework/zendservice-recaptcha": "2.*", + "doctrine/common": ">=2.1", + "doctrine/doctrine-orm-module": "0.*" + }, + "autoload": { + "psr-0": { + "CsnBase\\": "vendor/coolcsn/csn-base/src/" + } + } +} \ No newline at end of file diff --git a/composer.doctrineODM.dist b/composer.doctrineODM.dist new file mode 100644 index 00000000..6b91046d --- /dev/null +++ b/composer.doctrineODM.dist @@ -0,0 +1,25 @@ +{ + "name": "zendframework/skeleton-application", + "description": "Skeleton Application for ZF2", + "license": "BSD-3-Clause", + "keywords": [ + "framework", + "zf2" + ], + "homepage": "http://framework.zend.com/", + "minimum-stability": "alpha", + "repositories": [ + { + "type": "composer", + "url": "http://packages.zendframework.com/" + } + ], + "require": { + "php": ">=5.3.3", + "zendframework/zendframework": "2.*", + "zendframework/zendservice-recaptcha": "2.*", + "doctrine/common": ">=2.1", + "doctrine/doctrine-orm-module": "0.*", + "doctrine/doctrine-mongo-odm-module": "dev-master" + } +} \ No newline at end of file diff --git a/config/application.config.php b/config/application.config.php index bc1811b4..ffcdd35c 100644 --- a/config/application.config.php +++ b/config/application.config.php @@ -35,6 +35,7 @@ 'KrasimirTsvetanov', 'Fmi', 'Auth', + 'CsnBase', // This is also a library. Can be used without adding it as a module in composer.json: "autoload": {"psr-0": {"CsnBase\\": "vendor/coolcsn/csn-base/src/"}} ), 'module_listener_options' => array( 'config_glob_paths' => array( diff --git a/config/autoload/mail.config.local.php.dist b/config/autoload/mail.config.local.php.dist new file mode 100644 index 00000000..ad062db9 --- /dev/null +++ b/config/autoload/mail.config.local.php.dist @@ -0,0 +1,16 @@ + array( + 'transport' => array( + 'options' => array( + 'host' => 'smtp.gmail.com', + 'connection_class' => 'plain', + 'connection_config' => array( + 'username' => 'example@example.org', + 'password' => '', + 'ssl' => 'tls' + ), + ), + ), + ), +); \ No newline at end of file diff --git a/module/Auth/Module.php b/module/Auth/Module.php index 7cf58caa..ca24c8d8 100644 --- a/module/Auth/Module.php +++ b/module/Auth/Module.php @@ -1,6 +1,17 @@ array( + // For Yable data Gateway + 'Auth\Model\UsersTable' => function($sm) { + $tableGateway = $sm->get('UsersTableGateway'); + $table = new UsersTable($tableGateway); + return $table; + }, + 'UsersTableGateway' => function ($sm) { + $dbAdapter = $sm->get('Zend\Db\Adapter\Adapter'); + $resultSetPrototype = new ResultSet(); + $resultSetPrototype->setArrayObjectPrototype(new Auth()); // Notice what is set here + return new TableGateway('users', $dbAdapter, null, $resultSetPrototype); + }, + // Add this for SMTP transport + 'mail.transport' => function (ServiceManager $serviceManager) { + $config = $serviceManager->get('Config'); + $transport = new Smtp(); + $transport->setOptions(new SmtpOptions($config['mail']['transport']['options'])); + return $transport; + }, + ), + ); + } } \ No newline at end of file diff --git a/module/Auth/config/module.config.php b/module/Auth/config/module.config.php index 9d6204a3..010130d8 100644 --- a/module/Auth/config/module.config.php +++ b/module/Auth/config/module.config.php @@ -4,6 +4,7 @@ 'controllers' => array( 'invokables' => array( 'Auth\Controller\Index' => 'Auth\Controller\IndexController', + 'Auth\Controller\Registration' => 'Auth\Controller\RegistrationController', ), ), 'router' => array( @@ -23,10 +24,11 @@ 'default' => array( 'type' => 'Segment', 'options' => array( - 'route' => '/[:controller[/:action]]', + 'route' => '/[:controller[/:action[/:id]]]', 'constraints' => array( 'controller' => '[a-zA-Z][a-zA-Z0-9_-]*', 'action' => '[a-zA-Z][a-zA-Z0-9_-]*', + 'id' => '[a-zA-Z0-9_-]*', ), 'defaults' => array( ), diff --git a/module/Auth/src/Auth/Controller/RegistrationController.php b/module/Auth/src/Auth/Controller/RegistrationController.php new file mode 100644 index 00000000..ba56f816 --- /dev/null +++ b/module/Auth/src/Auth/Controller/RegistrationController.php @@ -0,0 +1,290 @@ +get('submit')->setValue('Register'); + + $request = $this->getRequest(); + if ($request->isPost()) { + $form->setInputFilter(new RegistrationFilter($this->getServiceLocator())); + $form->setData($request->getPost()); + if ($form->isValid()) { + $data = $form->getData(); + $data = $this->prepareData($data); + $auth = new Auth(); + $auth->exchangeArray($data); +/* + // this is replaced by + // 1) Manualy composing (wiring) the objects + $dbAdapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter'); + $resultSetPrototype = new \Zend\Db\ResultSet\ResultSet(); + $resultSetPrototype->setArrayObjectPrototype(new \Auth\Model\Auth()); + $tableGateway = new \Zend\Db\TableGateway\TableGateway('users', $dbAdapter, null, $resultSetPrototype); + $usersTable = new \Auth\Model\UsersTable($tableGateway); + // $usersTable->saveUser($auth); + // $user7 = $usersTable->getUser(7); + + $rowset = $tableGateway->select(array('usr_id' => 7)); + $user7 = $rowset->current(); + + echo '
';
+				var_dump($user7);
+				echo '
'; +*/ + // OR + // 2) Using the service Locator + $this->getUsersTable()->saveUser($auth); + + $this->sendConfirmationEmail($auth); + $this->flashMessenger()->addMessage($auth->usr_email); + return $this->redirect()->toRoute('auth/default', array('controller'=>'registration', 'action'=>'registration-success')); + } + } + return new ViewModel(array('form' => $form)); + } + + public function registrationSuccessAction() + { + $usr_email = null; + $flashMessenger = $this->flashMessenger(); + if ($flashMessenger->hasMessages()) { + foreach($flashMessenger->getMessages() as $key => $value) { + $usr_email .= $value; + } + } + return new ViewModel(array('usr_email' => $usr_email)); + } + + public function confirmEmailAction() + { + $token = $this->params()->fromRoute('id'); + $viewModel = new ViewModel(array('token' => $token)); + try { + $user = $this->getUsersTable()->getUserByToken($token); + $usr_id = $user->usr_id; + $this->getUsersTable()->activateUser($usr_id); + } + catch(\Exception $e) { + $viewModel->setTemplate('auth/registration/confirm-email-error.phtml'); + } + return $viewModel; + } + + public function forgottenPasswordAction() + { + $form = new ForgottenPasswordForm(); + $form->get('submit')->setValue('Send'); + $request = $this->getRequest(); + if ($request->isPost()) { + $form->setInputFilter(new ForgottenPasswordFilter($this->getServiceLocator())); + $form->setData($request->getPost()); + if ($form->isValid()) { + $data = $form->getData(); + $usr_email = $data['usr_email']; + $usersTable = $this->getUsersTable(); + $auth = $usersTable->getUserByEmail($usr_email); + $password = $this->generatePassword(); + $auth->usr_password = $this->encriptPassword($this->getStaticSalt(), $password, $auth->usr_password_salt); +// $usersTable->changePassword($auth->usr_id, $password); +// or + $usersTable->saveUser($auth); + $this->sendPasswordByEmail($usr_email, $password); + $this->flashMessenger()->addMessage($usr_email); + return $this->redirect()->toRoute('auth/default', array('controller'=>'registration', 'action'=>'password-change-success')); + } + } + return new ViewModel(array('form' => $form)); + } + + public function passwordChangeSuccessAction() + { + $usr_email = null; + $flashMessenger = $this->flashMessenger(); + if ($flashMessenger->hasMessages()) { + foreach($flashMessenger->getMessages() as $key => $value) { + $usr_email .= $value; + } + } + return new ViewModel(array('usr_email' => $usr_email)); + } + + public function prepareData($data) + { + $data['usr_active'] = 0; + $data['usr_password_salt'] = $this->generateDynamicSalt(); + $data['usr_password'] = $this->encriptPassword( + $this->getStaticSalt(), + $data['usr_password'], + $data['usr_password_salt'] + ); + $data['usrl_id'] = 2; + $data['lng_id'] = 1; +// $data['usr_registration_date'] = date('Y-m-d H:i:s'); + $date = new \DateTime(); + $data['usr_registration_date'] = $date->format('Y-m-d H:i:s'); + $data['usr_registration_token'] = md5(uniqid(mt_rand(), true)); // $this->generateDynamicSalt(); +// $data['usr_registration_token'] = uniqid(php_uname('n'), true); + $data['usr_email_confirmed'] = 0; + return $data; + } + + public function generateDynamicSalt() + { + $dynamicSalt = ''; + for ($i = 0; $i < 50; $i++) { + $dynamicSalt .= chr(rand(33, 126)); + } + return $dynamicSalt; + } + + public function getStaticSalt() + { + $staticSalt = ''; + $config = $this->getServiceLocator()->get('Config'); + $staticSalt = $config['static_salt']; + return $staticSalt; + } + + public function encriptPassword($staticSalt, $password, $dynamicSalt) + { + return $password = md5($staticSalt . $password . $dynamicSalt); + } + + public function generatePassword($l = 8, $c = 0, $n = 0, $s = 0) { + // get count of all required minimum special chars + $count = $c + $n + $s; + $out = ''; + // sanitize inputs; should be self-explanatory + if(!is_int($l) || !is_int($c) || !is_int($n) || !is_int($s)) { + trigger_error('Argument(s) not an integer', E_USER_WARNING); + return false; + } + elseif($l < 0 || $l > 20 || $c < 0 || $n < 0 || $s < 0) { + trigger_error('Argument(s) out of range', E_USER_WARNING); + return false; + } + elseif($c > $l) { + trigger_error('Number of password capitals required exceeds password length', E_USER_WARNING); + return false; + } + elseif($n > $l) { + trigger_error('Number of password numerals exceeds password length', E_USER_WARNING); + return false; + } + elseif($s > $l) { + trigger_error('Number of password capitals exceeds password length', E_USER_WARNING); + return false; + } + elseif($count > $l) { + trigger_error('Number of password special characters exceeds specified password length', E_USER_WARNING); + return false; + } + + // all inputs clean, proceed to build password + + // change these strings if you want to include or exclude possible password characters + $chars = "abcdefghijklmnopqrstuvwxyz"; + $caps = strtoupper($chars); + $nums = "0123456789"; + $syms = "!@#$%^&*()-+?"; + + // build the base password of all lower-case letters + for($i = 0; $i < $l; $i++) { + $out .= substr($chars, mt_rand(0, strlen($chars) - 1), 1); + } + + // create arrays if special character(s) required + if($count) { + // split base password to array; create special chars array + $tmp1 = str_split($out); + $tmp2 = array(); + + // add required special character(s) to second array + for($i = 0; $i < $c; $i++) { + array_push($tmp2, substr($caps, mt_rand(0, strlen($caps) - 1), 1)); + } + for($i = 0; $i < $n; $i++) { + array_push($tmp2, substr($nums, mt_rand(0, strlen($nums) - 1), 1)); + } + for($i = 0; $i < $s; $i++) { + array_push($tmp2, substr($syms, mt_rand(0, strlen($syms) - 1), 1)); + } + + // hack off a chunk of the base password array that's as big as the special chars array + $tmp1 = array_slice($tmp1, 0, $l - $count); + // merge special character(s) array with base password array + $tmp1 = array_merge($tmp1, $tmp2); + // mix the characters up + shuffle($tmp1); + // convert to string for output + $out = implode('', $tmp1); + } + + return $out; + } + + public function getUsersTable() + { + if (!$this->usersTable) { + $sm = $this->getServiceLocator(); + $this->usersTable = $sm->get('Auth\Model\UsersTable'); + } + return $this->usersTable; + } + + public function sendConfirmationEmail($auth) + { + // $view = $this->getServiceLocator()->get('View'); + $transport = $this->getServiceLocator()->get('mail.transport'); + $message = new Message(); + $this->getRequest()->getServer(); //Server vars + $message->addTo($auth->usr_email) + ->addFrom('praktiki@coolcsn.com') + ->setSubject('Please, confirm your registration!') + ->setBody("Please, click the link to confirm your registration => " . + $this->getRequest()->getServer('HTTP_ORIGIN') . + $this->url()->fromRoute('auth/default', array( + 'controller' => 'registration', + 'action' => 'confirm-email', + 'id' => $auth->usr_registration_token))); + $transport->send($message); + } + + public function sendPasswordByEmail($usr_email, $password) + { + $transport = $this->getServiceLocator()->get('mail.transport'); + $message = new Message(); + $this->getRequest()->getServer(); //Server vars + $message->addTo($usr_email) + ->addFrom('praktiki@coolcsn.com') + ->setSubject('Your password has been changed!') + ->setBody("Your password at " . + $this->getRequest()->getServer('HTTP_ORIGIN') . + ' has been changed. Your new password is: ' . + $password + ); + $transport->send($message); + } +} \ No newline at end of file diff --git a/module/Auth/src/Auth/Form/ForgottenPasswordFilter.php b/module/Auth/src/Auth/Form/ForgottenPasswordFilter.php new file mode 100644 index 00000000..65508df7 --- /dev/null +++ b/module/Auth/src/Auth/Form/ForgottenPasswordFilter.php @@ -0,0 +1,29 @@ +add(array( + 'name' => 'usr_email', + 'required' => true, + 'validators' => array( + array( + 'name' => 'EmailAddress' + ), + array( + 'name' => 'Zend\Validator\Db\RecordExists', + 'options' => array( + 'table' => 'users', + 'field' => 'usr_email', + 'adapter' => $sm->get('Zend\Db\Adapter\Adapter'), + ), + ), + ), + )); + } +} \ No newline at end of file diff --git a/module/Auth/src/Auth/Form/ForgottenPasswordForm.php b/module/Auth/src/Auth/Form/ForgottenPasswordForm.php new file mode 100644 index 00000000..0b5511a4 --- /dev/null +++ b/module/Auth/src/Auth/Form/ForgottenPasswordForm.php @@ -0,0 +1,32 @@ +setAttribute('method', 'post'); + + $this->add(array( + 'name' => 'usr_email', + 'attributes' => array( + 'type' => 'email', + ), + 'options' => array( + 'label' => 'E-mail', + ), + )); + + $this->add(array( + 'name' => 'submit', + 'attributes' => array( + 'type' => 'submit', + 'value' => 'Go', + 'id' => 'submitbutton', + ), + )); + } +} \ No newline at end of file diff --git a/module/Auth/src/Auth/Form/RegistrationFilter.php b/module/Auth/src/Auth/Form/RegistrationFilter.php new file mode 100644 index 00000000..2d8df8ea --- /dev/null +++ b/module/Auth/src/Auth/Form/RegistrationFilter.php @@ -0,0 +1,101 @@ +add(array( + 'name' => 'usr_name', + 'required' => true, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'encoding' => 'UTF-8', + 'min' => 1, + 'max' => 100, + ), + ), + array( + 'name' => 'Zend\Validator\Db\NoRecordExists', + 'options' => array( + 'table' => 'users', + 'field' => 'usr_name', + 'adapter' => $sm->get('Zend\Db\Adapter\Adapter'), + ), + ), + ), + )); + + $this->add(array( + 'name' => 'usr_email', + 'required' => true, + 'validators' => array( + array( + 'name' => 'EmailAddress' + ), + array( + 'name' => 'Zend\Validator\Db\NoRecordExists', + 'options' => array( + 'table' => 'users', + 'field' => 'usr_email', + 'adapter' => $sm->get('Zend\Db\Adapter\Adapter'), + ), + ), + ), + )); + + $this->add(array( + 'name' => 'usr_password', + 'required' => true, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'encoding' => 'UTF-8', + 'min' => 6, + 'max' => 12, + ), + ), + ), + )); + + $this->add(array( + 'name' => 'usr_password_confirm', + 'required' => true, + 'filters' => array( + array('name' => 'StripTags'), + array('name' => 'StringTrim'), + ), + 'validators' => array( + array( + 'name' => 'StringLength', + 'options' => array( + 'encoding' => 'UTF-8', + 'min' => 6, + 'max' => 12, + ), + ), + array( + 'name' => 'Identical', + 'options' => array( + 'token' => 'usr_password', + ), + ), + ), + )); + } +} \ No newline at end of file diff --git a/module/Auth/src/Auth/Form/RegistrationForm.php b/module/Auth/src/Auth/Form/RegistrationForm.php new file mode 100644 index 00000000..52f41859 --- /dev/null +++ b/module/Auth/src/Auth/Form/RegistrationForm.php @@ -0,0 +1,71 @@ +setAttribute('method', 'post'); + + $this->add(array( + 'name' => 'usr_name', + 'attributes' => array( + 'type' => 'text', + ), + 'options' => array( + 'label' => 'Username', + ), + )); + + $this->add(array( + 'name' => 'usr_email', + 'attributes' => array( + 'type' => 'email', + ), + 'options' => array( + 'label' => 'E-mail', + ), + )); + + $this->add(array( + 'name' => 'usr_password', + 'attributes' => array( + 'type' => 'password', + ), + 'options' => array( + 'label' => 'Password', + ), + )); + + $this->add(array( + 'name' => 'usr_password_confirm', + 'attributes' => array( + 'type' => 'password', + ), + 'options' => array( + 'label' => 'Confirm Password', + ), + )); + + $this->add(array( + 'type' => 'Zend\Form\Element\Captcha', + 'name' => 'captcha', + 'options' => array( + 'label' => 'Please verify you are human', + 'captcha' => new \Zend\Captcha\Figlet(), + ), + )); + + $this->add(array( + 'name' => 'submit', + 'attributes' => array( + 'type' => 'submit', + 'value' => 'Go', + 'id' => 'submitbutton', + ), + )); + } +} \ No newline at end of file diff --git a/module/Auth/src/Auth/Model/Auth.php b/module/Auth/src/Auth/Model/Auth.php index d1767f05..214ec8c1 100644 --- a/module/Auth/src/Auth/Model/Auth.php +++ b/module/Auth/src/Auth/Model/Auth.php @@ -5,9 +5,43 @@ use Zend\InputFilter\InputFilter; use Zend\InputFilter\InputFilterAwareInterface; use Zend\InputFilter\InputFilterInterface; - +// the object will be hydrated by Zend\Db\TableGateway\TableGateway class Auth implements InputFilterAwareInterface { + public $usr_id; + public $usr_name; + public $usr_password; + public $usr_email; + public $usrl_id; + public $lng_id; + public $usr_active; + public $usr_question; + public $usr_answer; + public $usr_picture; + public $usr_password_salt; + public $usr_registration_date; + public $usr_registration_token; + public $usr_email_confirmed; + + // ArrayObject, or at least implement exchangeArray. For Zend\Db\ResultSet\ResultSet to work + public function exchangeArray($data) + { + $this->usr_id = (!empty($data['usr_id'])) ? $data['usr_id'] : null; + $this->usr_name = (!empty($data['usr_name'])) ? $data['usr_name'] : null; + $this->usr_password = (!empty($data['usr_password'])) ? $data['usr_password'] : null; + $this->usr_email = (!empty($data['usr_email'])) ? $data['usr_email'] : null; + $this->usrl_id = (!empty($data['usrl_id'])) ? $data['usrl_id'] : null; + $this->lng_id = (!empty($data['lng_id'])) ? $data['lng_id'] : null; + $this->usr_active = (isset($data['usr_active'])) ? $data['usr_active'] : null; + $this->usr_question = (!empty($data['usr_question'])) ? $data['usr_question'] : null; + $this->usr_answer = (!empty($data['usr_answer'])) ? $data['usr_answer'] : null; + $this->usr_picture = (!empty($data['usr_picture'])) ? $data['usr_picture'] : null; + $this->usr_password_salt = (!empty($data['usr_password_salt'])) ? $data['usr_password_salt'] : null; + $this->usr_registration_date = (!empty($data['usr_registration_date'])) ? $data['usr_registration_date'] : null; + $this->usr_registration_token = (!empty($data['usr_registration_token'])) ? $data['usr_registration_token'] : null; + $this->usr_email_confirmed = (isset($data['usr_email_confirmed'])) ? $data['usr_email_confirmed'] : null; + } + protected $inputFilter; public function setInputFilter(InputFilterInterface $inputFilter) diff --git a/module/Auth/src/Auth/Model/UsersTable.php b/module/Auth/src/Auth/Model/UsersTable.php new file mode 100644 index 00000000..8ab52543 --- /dev/null +++ b/module/Auth/src/Auth/Model/UsersTable.php @@ -0,0 +1,100 @@ +tableGateway = $tableGateway; + } + + public function fetchAll() + { + $resultSet = $this->tableGateway->select(); + return $resultSet; + } + + public function getUser($usr_id) + { + $usr_id = (int) $usr_id; + $rowset = $this->tableGateway->select(array('usr_id' => $usr_id)); + $row = $rowset->current(); + if (!$row) { + throw new \Exception("Could not find row $id"); + } + return $row; + } + + public function getUserByToken($token) + { + $rowset = $this->tableGateway->select(array('usr_registration_token' => $token)); + $row = $rowset->current(); + if (!$row) { + throw new \Exception("Could not find row $token"); + } + return $row; + } + + public function activateUser($usr_id) + { + $data['usr_active'] = 1; + $data['usr_email_confirmed'] = 1; + $this->tableGateway->update($data, array('usr_id' => (int)$usr_id)); + } + + public function getUserByEmail($usr_email) + { + $rowset = $this->tableGateway->select(array('usr_email' => $usr_email)); + $row = $rowset->current(); + if (!$row) { + throw new \Exception("Could not find row $usr_email"); + } + return $row; + } + + public function changePassword($usr_id, $password) + { + $data['password'] = $password; + $this->tableGateway->update($data, array('usr_id' => (int)$usr_id)); + } + + public function saveUser(Auth $auth) + { + // for Zend\Db\TableGateway\TableGateway we need the data in array not object + $data = array( + 'usr_name' => $auth->usr_name, + 'usr_password' => $auth->usr_password, + 'usr_email' => $auth->usr_email, + 'usrl_id' => $auth->usrl_id, + 'lng_id' => $auth->lng_id, + 'usr_active' => $auth->usr_active, + 'usr_question' => $auth->usr_question, + 'usr_answer' => $auth->usr_answer, + 'usr_picture' => $auth->usr_picture, + 'usr_password_salt' => $auth->usr_password_salt, + 'usr_registration_date' => $auth->usr_registration_date, + 'usr_registration_token'=> $auth->usr_registration_token, + 'usr_email_confirmed' => $auth->usr_email_confirmed, + ); + + $usr_id = (int)$auth->usr_id; + if ($usr_id == 0) { + $this->tableGateway->insert($data); + } else { + if ($this->getUser($usr_id)) { + $this->tableGateway->update($data, array('usr_id' => $usr_id)); + } else { + throw new \Exception('Form id does not exist'); + } + } + } + + public function deleteUser($id) + { + $this->tableGateway->delete(array('usr_id' => $usr_id)); + } +} \ No newline at end of file diff --git a/module/Auth/view/auth/registration/confirm-email-error.phtml b/module/Auth/view/auth/registration/confirm-email-error.phtml new file mode 100644 index 00000000..76abe382 --- /dev/null +++ b/module/Auth/view/auth/registration/confirm-email-error.phtml @@ -0,0 +1 @@ +

An error occured during activation of your account! Please, try again later.

\ No newline at end of file diff --git a/module/Auth/view/auth/registration/confirm-email.phtml b/module/Auth/view/auth/registration/confirm-email.phtml new file mode 100644 index 00000000..86c463dc --- /dev/null +++ b/module/Auth/view/auth/registration/confirm-email.phtml @@ -0,0 +1 @@ +

Thank you! Yor registration has been confirmed.

\ No newline at end of file diff --git a/module/Auth/view/auth/registration/forgotten-password.phtml b/module/Auth/view/auth/registration/forgotten-password.phtml new file mode 100644 index 00000000..f29efec6 --- /dev/null +++ b/module/Auth/view/auth/registration/forgotten-password.phtml @@ -0,0 +1,11 @@ +

Please fill the form and hit the button.

+form; +$form->setAttribute('action', $this->url('auth/default', array('controller' => 'registration', 'action' => 'forgotten-password'))); +$form->prepare(); + +echo $this->form()->openTag($form); +echo $this->formRow($form->get('usr_email')); +echo $this->formSubmit($form->get('submit')); +echo $this->form()->closeTag(); +?> \ No newline at end of file diff --git a/module/Auth/view/auth/registration/index.phtml b/module/Auth/view/auth/registration/index.phtml new file mode 100644 index 00000000..5eb63493 --- /dev/null +++ b/module/Auth/view/auth/registration/index.phtml @@ -0,0 +1,15 @@ +

Registration

+form; +$form->setAttribute('action', $this->url('auth/default', array('controller' => 'registration', 'action' => 'index'))); +$form->prepare(); + +echo $this->form()->openTag($form); +echo $this->formRow($form->get('usr_name')); +echo $this->formRow($form->get('usr_email')); +echo $this->formRow($form->get('usr_password')); +echo $this->formRow($form->get('usr_password_confirm')); +echo $this->formRow($form->get('captcha')); +echo $this->formSubmit($form->get('submit')); +echo $this->form()->closeTag(); +?> \ No newline at end of file diff --git a/module/Auth/view/auth/registration/password-change-success.phtml b/module/Auth/view/auth/registration/password-change-success.phtml new file mode 100644 index 00000000..203cc9ed --- /dev/null +++ b/module/Auth/view/auth/registration/password-change-success.phtml @@ -0,0 +1 @@ +

translate('An e-mail with your new password has been sent to %s. Please, check your inbox!'), $usr_email);?>

\ No newline at end of file diff --git a/module/Auth/view/auth/registration/registration-success.phtml b/module/Auth/view/auth/registration/registration-success.phtml new file mode 100644 index 00000000..dd9c8c6f --- /dev/null +++ b/module/Auth/view/auth/registration/registration-success.phtml @@ -0,0 +1 @@ +

translate('An e-mail has been sent to %s. Please, check your inbox and confirm your registration!'), $usr_email);?>

\ No newline at end of file diff --git a/module/CsnBase/Module.php b/module/CsnBase/Module.php new file mode 100644 index 00000000..febcd216 --- /dev/null +++ b/module/CsnBase/Module.php @@ -0,0 +1,16 @@ + array( + 'namespaces' => array( + __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, + ), + ), + ); + } +} diff --git a/module/CsnBase/src/CsnBase/Zend/Validator/ConfirmPassword.php b/module/CsnBase/src/CsnBase/Zend/Validator/ConfirmPassword.php new file mode 100644 index 00000000..c3a01599 --- /dev/null +++ b/module/CsnBase/src/CsnBase/Zend/Validator/ConfirmPassword.php @@ -0,0 +1,7 @@ +