Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
latoilescoute-dev
scoodle
Commits
87205958
Commit
87205958
authored
Feb 21, 2018
by
Simon LEBLANC
Committed by
Thomas Citharel
Feb 21, 2018
Browse files
Allow setting SMTP config
Signed-off-by:
Thomas Citharel
<
tcit@tcit.fr
>
parent
7e12443b
Changes
9
Hide whitespace changes
Inline
Side-by-side
action/add_comment.php
View file @
87205958
...
...
@@ -42,7 +42,7 @@ $is_admin = false;
$logService
=
new
LogService
();
$pollService
=
new
PollService
(
$connect
,
$logService
);
$inputService
=
new
InputService
();
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
$notificationService
=
new
NotificationService
(
$mailService
);
$securityService
=
new
SecurityService
();
...
...
action/send_edit_link_by_email_action.php
View file @
87205958
...
...
@@ -28,7 +28,7 @@ include_once __DIR__ . '/../app/inc/init.php';
$logService
=
new
LogService
();
$sessionService
=
new
SessionService
();
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
$pollService
=
new
PollService
(
$connect
,
$logService
);
$result
=
false
;
...
...
@@ -91,4 +91,4 @@ $smarty->error_reporting = E_ALL & ~E_NOTICE;
$response
=
[
'result'
=>
$result
,
'message'
=>
$message
];
echo
json_encode
(
$response
);
\ No newline at end of file
echo
json_encode
(
$response
);
adminstuds.php
View file @
87205958
...
...
@@ -49,7 +49,7 @@ $logService = new LogService();
$pollService
=
new
PollService
(
$connect
,
$logService
);
$adminPollService
=
new
AdminPollService
(
$connect
,
$pollService
,
$logService
);
$inputService
=
new
InputService
();
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
$notificationService
=
new
NotificationService
(
$mailService
);
/* PAGE */
...
...
app/classes/Framadate/Services/MailService.php
View file @
87205958
...
...
@@ -10,21 +10,26 @@ class MailService {
private
$smtp_allowed
;
private
$smtp_options
=
[];
private
$logService
;
function
__construct
(
$smtp_allowed
)
{
function
__construct
(
$smtp_allowed
,
$smtp_options
=
[]
)
{
$this
->
logService
=
new
LogService
();
$this
->
smtp_allowed
=
$smtp_allowed
;
if
(
true
===
is_array
(
$smtp_options
))
{
$this
->
smtp_options
=
$smtp_options
;
}
}
public
function
isValidEmail
(
$email
)
{
return
filter_var
(
$email
,
FILTER_VALIDATE_EMAIL
);
}
function
send
(
$to
,
$subject
,
$body
,
$msgKey
=
null
)
{
public
function
send
(
$to
,
$subject
,
$body
,
$msgKey
=
null
)
{
if
(
$this
->
smtp_allowed
===
true
&&
$this
->
canSendMsg
(
$msgKey
))
{
$mail
=
new
PHPMailer
(
true
);
$
mail
->
isSMTP
(
);
$
this
->
configureMailer
(
$mail
);
// From
$mail
->
FromName
=
NOMAPPLICATION
;
...
...
@@ -60,7 +65,7 @@ class MailService {
}
}
function
canSendMsg
(
$msgKey
)
{
public
function
canSendMsg
(
$msgKey
)
{
if
(
$msgKey
===
null
)
{
return
true
;
}
...
...
@@ -70,5 +75,28 @@ class MailService {
}
return
!
isset
(
$_SESSION
[
self
::
MAILSERVICE_KEY
][
$msgKey
])
||
time
()
-
$_SESSION
[
self
::
MAILSERVICE_KEY
][
$msgKey
]
>
self
::
DELAY_BEFORE_RESEND
;
}
/**
* Configure the mailer with the options
*
* @param PHPMailer $mailer
*/
private
function
configureMailer
(
PHPMailer
$mailer
)
{
$mailer
->
isSMTP
();
$available_options
=
[
'host'
=>
'Host'
,
'auth'
=>
'SMTPAuth'
,
'username'
=>
'Username'
,
'password'
=>
'Password'
,
'secure'
=>
'SMTPSecure'
,
'port'
=>
'Port'
,
];
foreach
(
$available_options
as
$config_option
=>
$mailer_option
)
{
if
(
true
===
isset
(
$this
->
smtp_options
[
$config_option
])
&&
false
===
empty
(
$this
->
smtp_options
[
$config_option
]))
{
$mailer
->
{
$mailer_option
}
=
$this
->
smtp_options
[
$config_option
];
}
}
}
}
\ No newline at end of file
app/inc/config.template.php
View file @
87205958
...
...
@@ -89,6 +89,14 @@ const TIME_EDIT_LINK_EMAIL = 60;
$config
=
[
/* general config */
'use_smtp'
=>
true
,
// use email for polls creation/modification/responses notification
'smtp_options'
=>
[
'host'
=>
'localhost'
,
// SMTP server (you could add many servers (main and backup for example) : use ";" like separator
'auth'
=>
false
,
// Enable SMTP authentication
'username'
=>
''
,
// SMTP username
'password'
=>
''
,
// SMTP password
'secure'
=>
''
,
// Enable encryption (false, tls or ssl)
'port'
=>
25
,
// TCP port to connect to
],
'tracking_code'
=>
''
,
// add HTML code to every page, useful for tools like Piwik
/* home */
'show_what_is_that'
=>
true
,
// display "how to use" section
...
...
@@ -98,5 +106,5 @@ $config = [
'default_poll_duration'
=>
180
,
// default values for the new poll duration (number of days).
/* create_classic_poll.php */
'user_can_add_img_or_link'
=>
true
,
// user can add link or URL when creating his poll.
'markdown_editor_by_default'
=>
true
// The markdown editor for the description is enabled by default
'markdown_editor_by_default'
=>
true
,
// The markdown editor for the description is enabled by default
];
create_classic_poll.php
View file @
87205958
...
...
@@ -29,7 +29,7 @@ include_once __DIR__ . '/app/inc/init.php';
/*---------*/
$logService
=
new
LogService
();
$pollService
=
new
PollService
(
$connect
,
$logService
);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
$purgeService
=
new
PurgeService
(
$connect
,
$logService
);
if
(
is_file
(
'bandeaux_local.php'
))
{
...
...
@@ -44,7 +44,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
$smarty
->
assign
(
'error'
,
__
(
'Error'
,
'You haven\'t filled the first section of the poll creation.'
));
$smarty
->
display
(
'error.tpl'
);
exit
;
}
}
// Min/Max archive date
$min_expiry_time
=
$pollService
->
minExpiryDate
();
$max_expiry_time
=
$pollService
->
maxExpiryDate
();
...
...
create_date_poll.php
View file @
87205958
...
...
@@ -30,7 +30,7 @@ include_once __DIR__ . '/app/inc/init.php';
/*---------*/
$logService
=
new
LogService
();
$pollService
=
new
PollService
(
$connect
,
$logService
);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
$purgeService
=
new
PurgeService
(
$connect
,
$logService
);
$inputService
=
new
InputService
();
...
...
find_polls.php
View file @
87205958
...
...
@@ -4,16 +4,16 @@
* is not distributed with this file, you can obtain one at
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.txt
*
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Raphal DROZ
* Authors of STUdS (initial project): Guilhem BORGHESI (borghesi@unistra.fr) and Rapha
ë
l DROZ
* Authors of Framadate/OpenSondage: Framasoft (https://github.com/framasoft)
*
* =============================
*
* Ce logiciel est rgi par la licence CeCILL-B. Si une copie de cette licence
* Ce logiciel est r
é
gi par la licence CeCILL-B. Si une copie de cette licence
* ne se trouve pas avec ce fichier vous pouvez l'obtenir sur
* http://www.cecill.info/licences/Licence_CeCILL-B_V1-fr.txt
*
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Raphal DROZ
* Auteurs de STUdS (projet initial) : Guilhem BORGHESI (borghesi@unistra.fr) et Rapha
ë
l DROZ
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
*/
...
...
@@ -28,7 +28,7 @@ include_once __DIR__ . '/app/inc/init.php';
/* -------- */
$logService
=
new
LogService
();
$pollService
=
new
PollService
(
$connect
,
$logService
);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
/* PAGE */
/* ---- */
...
...
studs.php
View file @
87205958
...
...
@@ -57,7 +57,7 @@ $comments = [];
$logService
=
new
LogService
();
$pollService
=
new
PollService
(
$connect
,
$logService
);
$inputService
=
new
InputService
();
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]
,
$config
[
'smtp_options'
]
);
$notificationService
=
new
NotificationService
(
$mailService
);
$securityService
=
new
SecurityService
();
$sessionService
=
new
SessionService
();
...
...
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