Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
services
t3o sites
voting.typo3.org
extensions
election
Commits
949e70f3
Commit
949e70f3
authored
Dec 23, 2015
by
Oliver Eglseder
Browse files
[TASK] Send out invitations to the electors
parent
29c34c1d
Changes
8
Hide whitespace changes
Inline
Side-by-side
Classes/Controller/FeElectionController.php
0 → 100644
View file @
949e70f3
<?php
namespace
TYPO3\Election\Controller
;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use
TYPO3\CMS\Extbase\Mvc\Controller\ActionController
;
use
TYPO3\Election\Domain\Model\ElectionInvitation
;
/**
* Class FeElectionController
*/
class
FeElectionController
extends
ActionController
{
const
CONTROLLER_NAME
=
'FeElection'
;
const
ACTION_VOTE
=
'vote'
;
/**
* @var \TYPO3\CMS\Extbase\Security\Cryptography\HashService
* @inject
*/
protected
$hashService
=
null
;
/**
* @param ElectionInvitation $electionInvitation
* @param string $hmac
*/
public
function
voteAction
(
ElectionInvitation
$electionInvitation
,
$hmac
)
{
$saltedEmail
=
$electionInvitation
->
getSecret
()
.
$electionInvitation
->
getElector
()
->
getEmail
();
if
(
$this
->
hashService
->
validateHmac
(
$saltedEmail
,
$hmac
))
{
\
TYPO3\CMS\Extbase\Utility\DebuggerUtility
::
var_dump
(
'hmac valid'
,
__CLASS__
.
'@'
.
__LINE__
,
20
);
}
else
{
\
TYPO3\CMS\Extbase\Utility\DebuggerUtility
::
var_dump
(
'hmac invalid'
,
__CLASS__
.
'@'
.
__LINE__
,
20
);
}
die
;
}
/**
* @return string
*/
public
static
function
getActionsForPluginConfiguration
()
{
return
implode
(
','
,
[
self
::
ACTION_VOTE
]);
}
}
Classes/Domain/Model/ElectionCircular.php
View file @
949e70f3
<?php
namespace
TYPO3\Election\Domain\Model
;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use
TYPO3\CMS\Core\TimeTracker\TimeTracker
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder
;
use
TYPO3\CMS\Extbase\Object\ObjectManager
;
use
TYPO3\CMS\Extbase\Security\Cryptography\HashService
;
use
TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
;
use
TYPO3\Election\Controller\FeElectionController
;
/**
* Class ElectionCircular
...
...
@@ -87,20 +95,28 @@ class ElectionCircular extends AbstractEntity
*/
public
function
getDummyBody
()
{
$elector
=
new
Elector
();
$elector
->
setFirstName
(
'Kasper'
);
$elector
->
setLastName
(
'Skårhøj'
);
$elector
->
setGender
(
Elector
::
GENDER_MALE
);
$elector
->
setEmail
(
'kasper@typo3.org'
);
return
$this
->
getRenderedBody
(
$elector
);
$dummyElector
=
new
Elector
();
$dummyElector
->
setFirstName
(
'Kasper'
);
$dummyElector
->
setLastName
(
'Skårhøj'
);
$dummyElector
->
setGender
(
Elector
::
GENDER_MALE
);
$dummyElector
->
setEmail
(
'kasper@typo3.org'
);
$dummyElectionInvitation
=
new
ElectionInvitation
();
$dummyElectionInvitation
->
setElector
(
$dummyElector
);
$dummyElectionInvitation
->
_setProperty
(
'uid'
,
9999999
);
$dummyElectionInvitation
->
setSecret
(
'foooBAAAAArrrrr'
);
$dummyConfiguration
=
new
Configuration
();
$dummyConfiguration
->
setPluginPid
(
1
);
return
$this
->
getRenderedBody
(
$dummyConfiguration
,
$dummyElectionInvitation
);
}
/**
* @param Elector $elector
* @param Configuration $configuration
* @param ElectionInvitation $electionInvitation
* @return string
*/
public
function
getRenderedBody
(
Elector
$elector
)
public
function
getRenderedBody
(
Configuration
$configuration
,
ElectionInvitation
$electionInvitation
)
{
$elector
=
$electionInvitation
->
getElector
();
return
str_replace
(
[
'{elector.salutation}'
,
...
...
@@ -118,19 +134,57 @@ class ElectionCircular extends AbstractEntity
$elector
->
getLastName
(),
$elector
->
getFullName
(),
$elector
->
getEmail
(),
$this
->
getLink
(
$
elector
),
$this
->
getLink
(
$
configuration
,
$electionInvitation
),
],
$this
->
body
);
}
/**
* @param Elector $elector
* @param Configuration $configuration
* @param ElectionInvitation $electionInvitation
* @return string
* @throws \TYPO3\CMS\Core\Error\Http\ServiceUnavailableException
* @throws \TYPO3\CMS\Extbase\Security\Exception\InvalidArgumentForHashGenerationException
*/
protected
function
getLink
(
Elector
$elector
)
protected
function
getLink
(
Configuration
$configuration
,
ElectionInvitation
$electionInvitation
)
{
return
'sakdjfhlkasdjhf'
;
$objectManager
=
GeneralUtility
::
makeInstance
(
ObjectManager
::
class
);
$hashService
=
$objectManager
->
get
(
HashService
::
class
);
if
(
!
isset
(
$GLOBALS
[
'TT'
]))
{
$GLOBALS
[
'TT'
]
=
GeneralUtility
::
makeInstance
(
TimeTracker
::
class
);
}
if
(
!
isset
(
$GLOBALS
[
'TSFE'
]))
{
$GLOBALS
[
'TSFE'
]
=
GeneralUtility
::
makeInstance
(
TypoScriptFrontendController
::
class
,
$GLOBALS
[
'TYPO3_CONF_VARS'
],
$configuration
->
getPluginPid
(),
0
);
$GLOBALS
[
'TSFE'
]
->
config
=
[
'config'
=>
[]];
$GLOBALS
[
'TSFE'
]
->
initFEuser
();
$GLOBALS
[
'TSFE'
]
->
fetch_the_id
();
$GLOBALS
[
'TSFE'
]
->
initTemplate
();
}
$uriBuilder
=
$objectManager
->
get
(
UriBuilder
::
class
);
$uriBuilder
->
setTargetPageUid
(
$configuration
->
getPluginPid
());
$uriBuilder
->
setCreateAbsoluteUri
(
true
);
$uriBuilder
->
setUseCacheHash
(
false
);
$uriBuilder
->
uriFor
(
FeElectionController
::
ACTION_VOTE
,
[
'electionInvitation'
=>
$electionInvitation
,
'hmac'
=>
$hashService
->
generateHmac
(
$electionInvitation
->
getSecret
()
.
$electionInvitation
->
getElector
()
->
getEmail
()
),
],
FeElectionController
::
CONTROLLER_NAME
,
'election'
,
'pi1'
);
return
$uriBuilder
->
buildFrontendUri
();
}
/**
...
...
Classes/Domain/Model/ElectionInvitation.php
View file @
949e70f3
...
...
@@ -34,6 +34,11 @@ class ElectionInvitation extends AbstractEntity
*/
protected
$elector
=
null
;
/**
* @var bool
*/
protected
$success
=
false
;
/**
* @return string
*/
...
...
@@ -81,4 +86,20 @@ class ElectionInvitation extends AbstractEntity
{
$this
->
elector
=
$elector
;
}
/**
* @return boolean
*/
public
function
isSuccess
()
{
return
$this
->
success
;
}
/**
* @param boolean $success
*/
public
function
setSuccess
(
$success
)
{
$this
->
success
=
$success
;
}
}
Classes/Domain/Repository/ElectionInvitationRepository.php
View file @
949e70f3
...
...
@@ -21,4 +21,11 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
*/
class
ElectionInvitationRepository
extends
Repository
{
/**
*
*/
public
function
persistAll
()
{
$this
->
persistenceManager
->
persistAll
();
}
}
Classes/Service/ElectionInvitationService.php
View file @
949e70f3
...
...
@@ -14,6 +14,7 @@ namespace TYPO3\Election\Service;
* The TYPO3 project - inspiring people to share!
*/
use
TYPO3\CMS\Core\Mail\MailMessage
;
use
TYPO3\CMS\Core\Utility\GeneralUtility
;
use
TYPO3\Election\Domain\Model\Configuration
;
use
TYPO3\Election\Domain\Model\ElectionCircular
;
...
...
@@ -50,6 +51,37 @@ class ElectionInvitationService
$electionInvitation
->
setElectionCircular
(
$electionCircular
);
$electionInvitation
->
setSecret
(
GeneralUtility
::
getRandomHexString
(
mt_rand
(
180
,
220
)));
$this
->
electionInvitationRepository
->
add
(
$electionInvitation
);
$this
->
electionInvitationRepository
->
persistAll
();
$electionInvitation
->
setSuccess
(
$this
->
sendElectionInvitation
(
$configuration
,
$electionInvitation
));
$this
->
electionInvitationRepository
->
update
(
$electionInvitation
);
$this
->
electionInvitationRepository
->
persistAll
();
}
}
/**
* @param Configuration $configuration
* @param ElectionInvitation $electionInvitation
* @return bool
*/
protected
function
sendElectionInvitation
(
Configuration
$configuration
,
ElectionInvitation
$electionInvitation
)
{
$mail
=
GeneralUtility
::
makeInstance
(
MailMessage
::
class
);
$electionCircular
=
$electionInvitation
->
getElectionCircular
();
$elector
=
$electionInvitation
->
getElector
();
$mail
->
setSubject
(
$electionCircular
->
getSubject
());
$mail
->
setFrom
([
$configuration
->
getFromEmail
()
=>
$configuration
->
getFromName
()]);
if
(
$configuration
->
isDebug
())
{
$mail
->
setTo
([
$configuration
->
getTestEmail
()
=>
$elector
->
getFullName
()]);
}
else
{
$mail
->
setTo
([
$elector
->
getEmail
()
=>
$elector
->
getFullName
()]);
}
$mail
->
setBody
(
$electionCircular
->
getRenderedBody
(
$configuration
,
$electionInvitation
));
return
$mail
->
send
()
===
1
;
}
}
ext_localconf.php
View file @
949e70f3
...
...
@@ -7,13 +7,16 @@ if (!defined('TYPO3_MODE')) {
\
TYPO3\CMS\Extbase\Utility\ExtensionUtility
::
registerTypeConverter
(
\
TYPO3\Election\Property\TypeConverter\UploadedFileReferenceConverter
::
class
);
\
TYPO3\CMS\Extbase\Utility\ExtensionUtility
::
configurePlugin
(
'TYPO3.election'
,
'pi1'
,
array
(
'FeDashboard'
=>
'index'
,
\
TYPO3\Election\Controller\FeElectionController
::
CONTROLLER_NAME
=>
\
TYPO3\Election\Controller\FeElectionController
::
getActionsForPluginConfiguration
(),
),
array
(
'FeDashboard'
=>
'index'
,
\
TYPO3\Election\Controller\FeElectionController
::
CONTROLLER_NAME
=>
\
TYPO3\Election\Controller\FeElectionController
::
getActionsForPluginConfiguration
(),
)
);
ext_tables.sql
View file @
949e70f3
...
...
@@ -152,6 +152,7 @@ CREATE TABLE tx_election_domain_model_electioninvitation (
secret
VARCHAR
(
255
)
DEFAULT
''
NOT
NULL
,
election_circular
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
elector
INT
(
11
)
unsigned
DEFAULT
'0'
NOT
NULL
,
success
TINYINT
(
4
)
unsigned
DEFAULT
'0'
NOT
NULL
,
PRIMARY
KEY
(
uid
),
KEY
parent
(
pid
)
...
...
ext_typoscript_setup.txt
View file @
949e70f3
...
...
@@ -166,6 +166,7 @@ config.tx_extbase.persistence.classes {
tableName = tx_election_domain_model_electioninvitation
columns {
secret.mapOnProperty = secret
success.mapOnProperty = success
election_circular {
mapOnProperty = electionCircular
config {
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment