(Guillermo) path-user-edit and mailsender [skip ci]
This commit is contained in:
parent
4943a5eb94
commit
54da0699dd
|
@ -4,6 +4,8 @@ include 'user/signup.php';
|
||||||
include 'user/logout.php';
|
include 'user/logout.php';
|
||||||
include 'user/recover-password.php';
|
include 'user/recover-password.php';
|
||||||
include 'user/send-recover-password.php';
|
include 'user/send-recover-password.php';
|
||||||
|
include 'user/edit-password.php';
|
||||||
|
include 'user/edit-email.php';
|
||||||
|
|
||||||
$userControllers = new ControllerGroup();
|
$userControllers = new ControllerGroup();
|
||||||
$userControllers->setGroupPath('/user');
|
$userControllers->setGroupPath('/user');
|
||||||
|
@ -13,5 +15,8 @@ $userControllers->addController(new SignUpController);
|
||||||
$userControllers->addController(new LogoutController);
|
$userControllers->addController(new LogoutController);
|
||||||
$userControllers->addController(new SendRecoverPasswordController);
|
$userControllers->addController(new SendRecoverPasswordController);
|
||||||
$userControllers->addController(new RecoverPasswordController);
|
$userControllers->addController(new RecoverPasswordController);
|
||||||
|
$userControllers->addController(new EditPassword);
|
||||||
|
$userControllers->addController(new EditEmail);
|
||||||
|
|
||||||
|
|
||||||
$userControllers->finalize();
|
$userControllers->finalize();
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
use Respect\Validation\Validator as DataValidator;
|
||||||
|
|
||||||
|
class EditEmail extends Controller{
|
||||||
|
const PATH = '/edit-email';
|
||||||
|
|
||||||
|
public function validations() {
|
||||||
|
return [
|
||||||
|
'permission' => 'user',
|
||||||
|
'requestData' => [
|
||||||
|
'newEmail' => [
|
||||||
|
'validation' => DataValidator::email(),
|
||||||
|
'error' => ERRORS::INVALID_EMAIL
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
public function handler() {
|
||||||
|
$newEmail = Controller::request('newEmail');
|
||||||
|
$user = Controller::getLoggedUser();
|
||||||
|
$oldEmail = $user->email;
|
||||||
|
$user->email = $newEmail;
|
||||||
|
$user->store();
|
||||||
|
|
||||||
|
$mailSender = new MailSender();
|
||||||
|
$mailSender->setTemplate('USER_EDIT_EMAIL', [
|
||||||
|
'to'=>$oldEmail,
|
||||||
|
'newemail'=>$user->email,
|
||||||
|
'name'=>$user->name
|
||||||
|
]);
|
||||||
|
$mailSender->send();
|
||||||
|
|
||||||
|
Response::respondSuccess();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
<?php
|
||||||
|
use Respect\Validation\Validator as DataValidator;
|
||||||
|
|
||||||
|
class EditPassword extends Controller {
|
||||||
|
const PATH = '/edit-password';
|
||||||
|
|
||||||
|
public function validations() {
|
||||||
|
return [
|
||||||
|
'permission' => 'user',
|
||||||
|
'requestData' => [
|
||||||
|
'newPassword' => [
|
||||||
|
'validation' => DataValidator::length(5, 200),
|
||||||
|
'error' => ERRORS::INVALID_PASSWORD
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handler() {
|
||||||
|
$oldPassword = Controller::request('oldPassword');
|
||||||
|
$newPassword = Controller::request('newPassword');
|
||||||
|
$user = Controller::getLoggedUser() ;
|
||||||
|
|
||||||
|
if (Hashing::verifyPassword($oldPassword, $user->password)) {
|
||||||
|
$user->password = Hashing::hashPassword($newPassword);
|
||||||
|
$user->store();
|
||||||
|
|
||||||
|
$mailSender = new MailSender();
|
||||||
|
$mailSender->setTemplate('USER_EDIT_PASSWORD', [
|
||||||
|
'to'=>$user->email,
|
||||||
|
'name'=>$user->name
|
||||||
|
]);
|
||||||
|
$mailSender->send();
|
||||||
|
|
||||||
|
Response::respondSuccess();
|
||||||
|
} else{
|
||||||
|
Response::respondError(ERRORS::INVALID_OLD_PASSWORD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -12,4 +12,5 @@ class ERRORS {
|
||||||
const INVALID_DEPARTMENT = 'Invalid department';
|
const INVALID_DEPARTMENT = 'Invalid department';
|
||||||
const INVALID_TICKET = 'Invalid ticket';
|
const INVALID_TICKET = 'Invalid ticket';
|
||||||
const INIT_SETTINGS_DONE = 'Settings already initialized';
|
const INIT_SETTINGS_DONE = 'Settings already initialized';
|
||||||
|
const INVALID_OLD_PASSWORD = 'Invalid old password';
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,26 @@ class InitialMails {
|
||||||
'subject' => 'Registrado {{to}} - OpenSupports',
|
'subject' => 'Registrado {{to}} - OpenSupports',
|
||||||
'body' => file_get_contents('data/mail-templates/user-signup-es.html')
|
'body' => file_get_contents('data/mail-templates/user-signup-es.html')
|
||||||
]
|
]
|
||||||
|
],
|
||||||
|
'USER_EDIT_PASSWORD' => [
|
||||||
|
'en' => [
|
||||||
|
'subject' => 'Password edited - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-edit-password-en.html')
|
||||||
|
],
|
||||||
|
'es' => [
|
||||||
|
'subject' => 'Contraseña a sido cambiada - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-edit-password-es.html')
|
||||||
|
]
|
||||||
|
],
|
||||||
|
'USER_EDIT_EMAIL' => [
|
||||||
|
'en' => [
|
||||||
|
'subject' => 'Email edited - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-edit-email-en.html')
|
||||||
|
],
|
||||||
|
'es' => [
|
||||||
|
'subject' => 'Tu correo electronico a sido cambiada - OpenSupports',
|
||||||
|
'body' => file_get_contents('data/mail-templates/user-edit-email-es.html')
|
||||||
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Hi {{name}} , OpenSupports' team wanna tell you that you email has been changed to {{newemail}}
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Hola {{name}} el equipo de OpenSupports te informa que tu correo electronico ha sido cambiado a {{newemail}}
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Hello {{name}} , OpenSupports' team wanna tell you that your password has been changed
|
||||||
|
</div>
|
|
@ -0,0 +1,3 @@
|
||||||
|
<div>
|
||||||
|
Hola , {{name}} el equipo de OpenSupports te informa que tu contraseña ha sido cambiada
|
||||||
|
</div>
|
|
@ -1,4 +1,4 @@
|
||||||
<div>
|
<div>
|
||||||
Bienvenido, {{name}} a nuestro centro de soporte,
|
Bienvenido, {{name}} a nuestro centro de soporte,
|
||||||
su email es {{to}}
|
tu email es {{to}}
|
||||||
</div>
|
</div>
|
|
@ -7,9 +7,9 @@ class MailSender {
|
||||||
$this->mailOptions['from'] = Setting::getSetting('no-reply-email')->value;
|
$this->mailOptions['from'] = Setting::getSetting('no-reply-email')->value;
|
||||||
|
|
||||||
$this->mailOptions['smtp-host'] = Setting::getSetting('smtp-host')->value;
|
$this->mailOptions['smtp-host'] = Setting::getSetting('smtp-host')->value;
|
||||||
$this->mailOptions['smtp-port'] = Setting::getSetting('smtp-host')->value;
|
$this->mailOptions['smtp-port'] = Setting::getSetting('smtp-port')->value;
|
||||||
$this->mailOptions['smtp-user'] = Setting::getSetting('smtp-host')->value;
|
$this->mailOptions['smtp-user'] = Setting::getSetting('smtp-user')->value;
|
||||||
$this->mailOptions['smtp-pass'] = Setting::getSetting('smtp-host')->value;
|
$this->mailOptions['smtp-pass'] = Setting::getSetting('smtp-pass')->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setTemplate($type, $config) {
|
public function setTemplate($type, $config) {
|
||||||
|
|
Loading…
Reference in New Issue