[DEV-146] resend verification email backend (#1049)
* add path resend signup token * add ruby tests
This commit is contained in:
parent
5d4fe0250b
commit
c64f1f1ea6
|
@ -24,6 +24,7 @@ $userControllers->addController(new DisableUserController);
|
|||
$userControllers->addController(new EditCustomFieldsController);
|
||||
$userControllers->addController(new EditSupervisedListController);
|
||||
$userControllers->addController(new GetSupervisedTicketController);
|
||||
$userControllers->addController(new ResendEmailTokenController);
|
||||
|
||||
$userControllers->addController(new ResendInviteUserController);
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
use Respect\Validation\Validator as DataValidator;
|
||||
|
||||
/**
|
||||
* @api {post} /user/resend-email-token Resend user sign up token
|
||||
* @apiVersion 4.9.0
|
||||
*
|
||||
* @apiName Resend user sign up token
|
||||
*
|
||||
* @apiGroup User
|
||||
*
|
||||
* @apiDescription This path resends token to signed up user.
|
||||
*
|
||||
* @apiPermission user
|
||||
*
|
||||
* @apiParam {email} email email of the signed up user.
|
||||
*
|
||||
* @apiUse NO_PERMISSION
|
||||
* @apiUse INVALID_EMAIL
|
||||
*
|
||||
* @apiSuccess {Object} data Empty object
|
||||
*
|
||||
*/
|
||||
|
||||
class ResendEmailTokenController extends Controller {
|
||||
const PATH = '/resend-email-token';
|
||||
const METHOD = 'POST';
|
||||
|
||||
public function validations() {
|
||||
return [
|
||||
'permission' => 'any',
|
||||
'requestData' => [
|
||||
'email' => [
|
||||
'validation' => DataValidator::email(),
|
||||
'error' => ERRORS::INVALID_EMAIL
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function handler() {
|
||||
$userEmail = Controller::request('email');
|
||||
|
||||
$user = User::getDataStore($userEmail, 'email');
|
||||
|
||||
if (!$user->verificationToken || !$user->email) {
|
||||
throw new RequestException(ERRORS::NO_PERMISSION);
|
||||
}
|
||||
|
||||
if(MailSender::getInstance()->isConnected()) {
|
||||
$this->resendTokenMail($user);
|
||||
}
|
||||
|
||||
Response::respondSuccess();
|
||||
}
|
||||
|
||||
public function resendTokenMail($user) {
|
||||
$mailSender = MailSender::getInstance();
|
||||
|
||||
$mailSender->setTemplate(MailTemplate::USER_SIGNUP, [
|
||||
'to' => $user->email,
|
||||
'name' => $user->name,
|
||||
'url' => Setting::getSetting('url')->getValue(),
|
||||
'verificationToken' => $user->verificationToken
|
||||
]);
|
||||
|
||||
$mailSender->send();
|
||||
}
|
||||
}
|
|
@ -80,6 +80,7 @@ require './user/edit-supervised-list.rb'
|
|||
require './user/get-supervised-tickets.rb'
|
||||
require './system/apikey-permissions.rb'
|
||||
require './system/get-stats.rb'
|
||||
require './user/resend-email-token.rb'
|
||||
require './user/invite.rb'
|
||||
require './user/resend-invite-user.rb'
|
||||
require './staff/resend-invite-staff.rb'
|
|
@ -0,0 +1,33 @@
|
|||
describe '/user/resend-email-token' do
|
||||
|
||||
request('/user/logout')
|
||||
|
||||
it 'should fail is data is wrong' do
|
||||
result = request('/user/resend-email-token', {
|
||||
email: 'thisemaildoesnotexists@hotmail.com'
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail')
|
||||
(result['message']).should.equal('NO_PERMISSION')
|
||||
|
||||
user = $database.getRow('user', '1' , 'id')
|
||||
|
||||
result = request('/user/resend-email-token', {
|
||||
email: user['email']
|
||||
})
|
||||
|
||||
(result['status']).should.equal('fail')
|
||||
(result['message']).should.equal('NO_PERMISSION')
|
||||
end
|
||||
=begin
|
||||
it 'should resend email' do
|
||||
Scripts.createUser('usertobetestedbyresendemail@os4.com')
|
||||
|
||||
result = request('/user/resend-email-token', {
|
||||
email: 'usertobetestedbyresendemail@hotmail.com'
|
||||
})
|
||||
|
||||
(result['message']).should.equal('success')
|
||||
end
|
||||
=end
|
||||
end
|
Loading…
Reference in New Issue