[DEV-146] resend verification email backend (#1049)

* add path resend signup token

* add ruby tests
This commit is contained in:
Guillermo Giuliana 2021-10-08 19:07:14 -03:00 committed by GitHub
parent 5d4fe0250b
commit c64f1f1ea6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 105 additions and 1 deletions

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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'

View File

@ -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