Skip to content

Commit

Permalink
add email form in account-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
kokspflanze committed Nov 6, 2015
1 parent 06ab787 commit 2fa42af
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 43 deletions.
7 changes: 4 additions & 3 deletions config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
},
],
'invokables' => [
'small_user_service' => 'PServerCMS\Service\User',
'pserver_mail_service' => 'PServerCMS\Service\Mail',
'pserver_download_service' => 'PServerCMS\Service\Download',
'pserver_server_info_service' => 'PServerCMS\Service\ServerInfo',
Expand All @@ -115,7 +114,6 @@
'pserver_playerhistory_service' => 'PServerCMS\Service\PlayerHistory',
'pserver_donate_service' => 'PServerCMS\Service\Donate',
'pserver_cachinghelper_service' => 'PServerCMS\Service\CachingHelper',
'payment_api_log_service' => 'PServerCMS\Service\PaymentNotify',
'pserver_user_block_service' => 'PServerCMS\Service\UserBlock',
'pserver_secret_question' => 'PServerCMS\Service\SecretQuestion',
'pserver_log_service' => 'PServerCMS\Service\Logs',
Expand All @@ -124,6 +122,9 @@
'pserver_login_history_service' => 'PServerCMS\Service\LoginHistory',
'pserver_coin_service' => 'PServerCMS\Service\Coin',
'pserver_timer_service' => 'PServerCMS\Service\Timer',
'pserver_add_email_service' => 'PServerCMS\Service\AddEmail',
'small_user_service' => 'PServerCMS\Service\User',
'payment_api_log_service' => 'PServerCMS\Service\PaymentNotify',
'payment_api_ip_service' => 'PServerCMS\Service\Ip',
'zfcticketsystem_ticketsystem_service' => 'PServerCMS\Service\TicketSystem',
],
Expand Down Expand Up @@ -179,7 +180,7 @@
'p-server-cms/navigation' => __DIR__ . '/../view/helper/navigation.phtml',
],
'template_path_stack' => [
__DIR__ . '/../view',
'p-server-cms' =>__DIR__ . '/../view',
],
],
// Placeholder for console routes
Expand Down
21 changes: 18 additions & 3 deletions src/PServerCMS/Controller/AccountController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

namespace PServerCMS\Controller;

use PServerCMS\Helper\HelperForm;
use PServerCMS\Helper\HelperService;
use PServerCMS\Helper\HelperServiceLocator;
use PServerCMS\Service;
use Zend\Mvc\Controller\AbstractActionController;

class AccountController extends AbstractActionController
{
use HelperServiceLocator, HelperService;
use HelperServiceLocator, HelperForm, HelperService;

const ERROR_NAME_SPACE = 'pserver-user-account-error';
const SUCCESS_NAME_SPACE = 'pserver-user-account-success';
Expand All @@ -19,7 +20,7 @@ public function indexAction()
/** @var \PServerCMS\Entity\UserInterface $user */
$user = $this->getUserService()->getAuthService()->getIdentity();

$form = $this->getUserService()->getChangePwdForm();
$form = $this->getChangePwdForm();
$elements = $form->getElements();
foreach ($elements as $element) {
if ($element instanceof \Zend\Form\Element) {
Expand All @@ -36,15 +37,24 @@ public function indexAction()
$inGamePasswordForm = clone $form;
$formChangeIngamePwd = $inGamePasswordForm->setWhich('ingame');

$addEmailForm = null;
if (!$user->getEmail()) {
$addEmailForm = $this->getAddEmailForm();
}

/** @var \Zend\Http\Request $request */
$request = $this->getRequest();
if (!$request->isPost()) {
return [
'changeWebPwdForm' => $formChangeWebPwd,
'changeIngamePwdForm' => $formChangeIngamePwd,
'addEmailForm' => $addEmailForm,
'messagesWeb' => $this->flashmessenger()->getMessagesFromNamespace(self::SUCCESS_NAME_SPACE . 'Web'),
'messagesInGame' => $this->flashmessenger()->getMessagesFromNamespace(self::SUCCESS_NAME_SPACE . 'InGame'),
'messagesAddEmail' => $this->flashmessenger()->getMessagesFromNamespace(self::SUCCESS_NAME_SPACE . 'AddEmail'),
'errorsWeb' => $this->flashmessenger()->getMessagesFromNamespace(self::ERROR_NAME_SPACE . 'Web'),
'errorsInGame' => $this->flashmessenger()->getMessagesFromNamespace(self::ERROR_NAME_SPACE . 'InGame')
'errorsInGame' => $this->flashmessenger()->getMessagesFromNamespace(self::ERROR_NAME_SPACE . 'InGame'),
'errorsAddEmail' => $this->flashmessenger()->getMessagesFromNamespace(self::ERROR_NAME_SPACE . 'AddEmail'),
];

}
Expand All @@ -63,4 +73,9 @@ public function indexAction()
return $this->redirect()->toUrl($this->url()->fromRoute('PServerCMS/user'));
}

public function addEmailAction()
{
return $this->redirect()->toRoute('PServerCMS/user', ['action' => 'index']);
}

}
60 changes: 30 additions & 30 deletions src/PServerCMS/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public function registerAction()

//if already login, redirect to success page
if ($this->getUserService()->getAuthService()->hasIdentity()) {
return $this->redirect()->toRoute( $this->getLoggedInRoute() );
return $this->redirect()->toRoute($this->getLoggedInRoute());
}

$form = $this->getUserService()->getRegisterForm();

$request = $this->getRequest();
if ($request->isPost()) {
$user = $this->getUserService()->register( $this->params()->fromPost() );
$user = $this->getUserService()->register($this->params()->fromPost());
if ($user) {
return $this->redirect()->toRoute( 'small-user-auth', ['action' => 'register-done']);
return $this->redirect()->toRoute('small-user-auth', ['action' => 'register-done']);
}
}

Expand All @@ -52,24 +52,24 @@ public function registerDoneAction()
*/
public function registerConfirmAction()
{
$codeRoute = $this->params()->fromRoute( 'code' );
$codeRoute = $this->params()->fromRoute('code');

$userCode = $this->getCode4Data( $codeRoute, UserCodes::TYPE_REGISTER );
$userCode = $this->getCode4Data($codeRoute, UserCodes::TYPE_REGISTER);
if (!$userCode) {
return $this->forward()->dispatch( 'PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
return $this->forward()->dispatch('PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
}

$user = $this->getUserService()->registerGameWithSamePassword( $userCode );
$user = $this->getUserService()->registerGameWithSamePassword($userCode);

$form = $this->getUserService()->getPasswordForm();
$form = $this->getUserService()->getPasswordForm();
$request = $this->getRequest();
if ($request->isPost() || $user) {
if (!$user) {
$user = $this->getUserService()->registerGameWithOtherPw( $this->params()->fromPost(), $userCode );
$user = $this->getUserService()->registerGameWithOtherPw($this->params()->fromPost(), $userCode);
}
if ($user) {
//$this->getUserService()->doAuthentication($user);
return $this->redirect()->toRoute( $this->getLoggedInRoute() );
return $this->redirect()->toRoute($this->getLoggedInRoute());
}
}

Expand All @@ -80,16 +80,16 @@ public function registerConfirmAction()

public function ipConfirmAction()
{
$code = $this->params()->fromRoute( 'code' );
$code = $this->params()->fromRoute('code');

$oCode = $this->getCode4Data( $code, UserCodes::TYPE_CONFIRM_COUNTRY );
$oCode = $this->getCode4Data($code, UserCodes::TYPE_CONFIRM_COUNTRY);
if (!$oCode) {
return $this->forward()->dispatch( 'PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
return $this->forward()->dispatch('PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
}

$user = $this->getUserService()->countryConfirm( $oCode );
$user = $this->getUserService()->countryConfirm($oCode);
if ($user) {
return $this->redirect()->toRoute( 'small-user-auth', ['action' => 'ip-confirm-done']);
return $this->redirect()->toRoute('small-user-auth', ['action' => 'ip-confirm-done']);
}

return [];
Expand All @@ -107,9 +107,9 @@ public function pwLostAction()

$request = $this->getRequest();
if ($request->isPost()) {
$user = $this->getUserService()->lostPw( $this->params()->fromPost() );
$user = $this->getUserService()->lostPw($this->params()->fromPost());
if ($user) {
return $this->redirect()->toRoute( 'small-user-auth', ['action' => 'pw-lost-done']);
return $this->redirect()->toRoute('small-user-auth', ['action' => 'pw-lost-done']);
}
}

Expand All @@ -125,19 +125,19 @@ public function pwLostDoneAction()

public function pwLostConfirmAction()
{
$code = $this->params()->fromRoute( 'code' );
$code = $this->params()->fromRoute('code');

$codeEntity = $this->getCode4Data( $code, UserCodes::TYPE_LOST_PASSWORD );
$codeEntity = $this->getCode4Data($code, UserCodes::TYPE_LOST_PASSWORD);
if (!$codeEntity) {
return $this->forward()->dispatch( 'PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
return $this->forward()->dispatch('PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
}
$form = $this->getUserService()->getPasswordForm();
$form->addSecretQuestion( $codeEntity->getUser() );
$form->addSecretQuestion($codeEntity->getUser());
$request = $this->getRequest();
if ($request->isPost()) {
$user = $this->getUserService()->lostPwConfirm( $this->params()->fromPost(), $codeEntity );
$user = $this->getUserService()->lostPwConfirm($this->params()->fromPost(), $codeEntity);
if ($user) {
return $this->redirect()->toRoute( 'small-user-auth', ['action' => 'pw-lost-confirm-done']);
return $this->redirect()->toRoute('small-user-auth', ['action' => 'pw-lost-confirm-done']);
}
}

Expand All @@ -148,16 +148,16 @@ public function pwLostConfirmAction()

public function secretLoginAction()
{
$code = $this->params()->fromRoute( 'code' );
$code = $this->params()->fromRoute('code');

$codeEntity = $this->getCode4Data( $code, UserCodes::TYPE_SECRET_LOGIN );
$codeEntity = $this->getCode4Data($code, UserCodes::TYPE_SECRET_LOGIN);
if (!$codeEntity) {
return $this->forward()->dispatch( 'PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
return $this->forward()->dispatch('PServerCMS\Controller\Auth', ['action' => 'wrong-code']);
}
$this->getUserService()->doAuthentication($codeEntity->getUser());
$this->getUserCodesService()->deleteCode($codeEntity);

return $this->redirect()->toRoute( $this->getLoggedInRoute() );
return $this->redirect()->toRoute($this->getLoggedInRoute());
}

public function pwLostConfirmDoneAction()
Expand All @@ -170,12 +170,12 @@ public function wrongCodeAction()
return [];
}

protected function getCode4Data( $code, $type )
protected function getCode4Data($code, $type)
{
$entityManager = $this->getEntityManager();
/** @var $repositoryCode \PServerCMS\Entity\Repository\UserCodes */
$repositoryCode = $entityManager->getRepository( $this->getEntityOptions()->getUserCodes() );
$codeEntity = $repositoryCode->getData4CodeType( $code, $type );
$repositoryCode = $entityManager->getRepository($this->getEntityOptions()->getUserCodes());
$codeEntity = $repositoryCode->getData4CodeType($code, $type);

return $codeEntity;
}
Expand Down
6 changes: 3 additions & 3 deletions src/PServerCMS/Controller/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public function downloadAction()
*/
public function pageAction()
{
$type = $this->params()->fromRoute( 'type' );
$pageInfo = $this->getPageInfoService()->getPage4Type( $type );
$type = $this->params()->fromRoute('type');
$pageInfo = $this->getPageInfoService()->getPage4Type($type);
if (!$pageInfo) {
return $this->redirect()->toRoute( 'PServerCMS' );
return $this->redirect()->toRoute('PServerCMS');
}

return [
Expand Down
62 changes: 62 additions & 0 deletions src/PServerCMS/Form/AddEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php


namespace PServerCMS\Form;


use Zend\Form\Element;
use ZfcBase\Form\ProvidesEventsForm;

class AddEmail extends ProvidesEventsForm
{

/**
* AddEmail constructor.
*/
public function __construct()
{

parent::__construct();

$this->add([
'type' => 'Zend\Form\Element\Csrf',
'name' => 'eugzhoe45gh3o49ug2wrtu7gz50'
]);

$this->add([
'name' => 'email',
'options' => [
'label' => 'Email',
],
'attributes' => [
'placeholder' => 'Email',
'class' => 'form-control',
'type' => 'email'
],
]);
$this->add([
'name' => 'emailVerify',
'options' => [
'label' => 'Email Verify',
],
'attributes' => [
'placeholder' => 'Email Verify',
'class' => 'form-control',
'type' => 'email'
],
]);

$submitElement = new Element\Button('submit');
$submitElement
->setLabel('Submit')
->setAttributes([
'class' => 'btn btn-primary',
'type' => 'submit',
]);

$this->add($submitElement, [
'priority' => -100,
]);

}
}
Loading

0 comments on commit 2fa42af

Please sign in to comment.