Whmcs auto auth - whmcs

We are currently using auto auth and we have the method below to log in the user automatically using there email, the problem is when the email has a plus sign it will not login automatically.
/**
* #param $email Clients Email Address to Login
* #param string $goto is a url endpoint where you want to redirect the user
*/
public static function autoLoginUser( $email, $goto = 'index.php?m=dashboard' )
{
global $CONFIG;
/**
* Define WHMCS url and AuthKey from confguration.php
*/
$whmcsurl = $CONFIG['SystemURL'] . "/dologin.php";
$autoauthkey = "Our auth key is here"; //$autoauthkey from configuration.php
$timestamp = time(); //Get current timestamp
$hash = sha1($email . $timestamp . $autoauthkey); //Generate Hash
/**
* Generate AutoAuth URL & Redirect
*/
$url = $whmcsurl . "?email=$email&timestamp=$timestamp&hash=$hash&goto=" . urlencode($goto);
header("Location: $url");
exit;
}
Does anyone have tried this before? Having a normal email address works perfectly but on email that contains plus sign it won't log the user automatically.

I don't know why it was not documented in whmcs but the work around we manage to have is encode the email like the following code
/**
* #param $email Clients Email Address to Login
* #param string $goto is a url endpoint where you want to redirect the user
*/
public static function autoLoginUser( $email, $goto = 'index.php?m=dashboard' )
{
global $CONFIG;
/**
* Define WHMCS url and AuthKey from confguration.php
*/
$whmcsurl = $CONFIG['SystemURL'] . "/dologin.php";
$autoauthkey = "Our auth key is here"; //$autoauthkey from configuration.php
$timestamp = time(); //Get current timestamp
$hash = sha1($email . $timestamp . $autoauthkey); //Generate Hash
$email =
/**
* Generate AutoAuth URL & Redirect
*/
$url = $whmcsurl . "?email=".urlencode($email)."&timestamp=$timestamp&hash=$hash&goto=" . urlencode($goto);
header("Location: $url");
exit;
}

Related

Symfony 4 API Rest PUT : Map data to database entity

I'm a begginer in Symfony 4 and I'm developing an API Rest. I want to create a PUT resource that can handle many update cases.
In my case, I have a user with many properties but I will take an example with 3 properties to keep things simple :
User {
username,
email,
password
}
My PUT resource can be called in order to update Username, update Email or update Password. For example, to update Username, the user of my API will send a PUT request with only username :
{
username: "New username"
}
Same for email and password, he will only send the property he wants to change.
My problem is in my Controller, I have to do things like this :
/**
* #Rest\Put("/user/{id}")
* #param Request $request
* #return View
*/
public function putUserRequest(Request $request)
{
$userId = $request->get('id');
$user = $this->doctrine->getRepository(User::class)->findOneBy('id' => $userId);
$userFromRequest = $this->serializer->deserialize($request->getContent(), User::class, 'json');
if ($userFromRequest->getUsername() != NULL) {
$user->setUsername($userFromRequest->getUsername())
}
if ($userFromRequest->getEmail() != NULL) {
$user->setEmail($userFromRequest->getEmail())
}
if ($userFromRequest->getPassword() != NULL) {
$user->setPassword($userFromRequest->getPassword())
}
// ...
}
In my example I have only 3 properties, but imagine when I have 30 properties.
With Symfony 3 I used forms to validate / save my datas :
$form->submit($request->request->all(), $clearMissing);
Where $clearMissing is false to keep datas not provided by the user of my API. I can't find a way to do it with serializer but I guess I'm doing things wrong.
Thanks.
If I understand correctly, You can use the validator Component like this :
/**
* #Rest\Put("/user/{id}")
* #param Request $request
* #return View
*/
public function putUserRequest(User $user, Request $request, ValidatorInterface $validator)
{
$data = $request->getContent();
$this->serializer->deserialize($data, User::class, 'json', ['object_to_populate' => $user]);
//At this moment, the data you sent is merged with your user entity
/** #var ConstraintViolationList $errors */
$errors = $validator->validate($user, null ,['groups' => 'user_update']);
if (count($errors) > 0) {
//return json reponse with formated errors;
}
//if ok $entityManager->flush() and Response Json with serialization group;
...
}
In your user class :
class User implements UserInterface
{
/**
* #Assert\Email(groups={"user_create", "user_update"})
*/
private $email;
/**
* #Assert\NotBlank(groups={"user_create", "user_update"})
* #Assert\Length(min=7, groups={"user_create", "user_update"})
*/
private $password;
/**
* #Assert\Length(min=2, groups={"user_create", "user_update"} )
*/
private $username;
}
Related Validator component documentation : https://symfony.com/doc/current/validation/groups.html
You can also check this project : https://github.com/attineos/relation-deserializer

TYPO3 authenticating user failing using SaltedPasswordsUtility

I want to authenticate a custom FrontendUser via my REST-API in a Controller. I tried to hash the password with SaltedPasswordsUtility using this guide.
I get every request a different hash from the same password. I assume this is because the salt is not consistent.
How can I compare the plain text password to the password hash in the database or is there an entirely other way to achieve the same?
My code so far is:
/**
* action check
*
* #param string $username
* #param string $password
* #return string
*/
public function checkAction(string $username, string $password)
{
$user = $this->userRepository->findOneByUsername($username);
$saltedPassword = '';
if (\TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled('FE')) {
$objSalt = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance(NULL);
if (is_object($objSalt)) {
$saltedPassword = $objSalt->getHashedPassword($password);
}
}
echo $saltedPassword;
echo "<br>";
$saltedPassword = $user->getPassword();
// keeps status if plain-text password matches given salted user password hash
$success = FALSE;
if (\TYPO3\CMS\Saltedpasswords\Utility\SaltedPasswordsUtility::isUsageEnabled('FE')) {
$objSalt = \TYPO3\CMS\Saltedpasswords\Salt\SaltFactory::getSaltingInstance($saltedPassword);
if (is_object($objSalt)) {
$success = $objSalt->checkPassword($password, $saltedPassword);
}
}
echo $saltedPassword;
return "";
}
The code is woking. I messed up setting a faulty password for the test user in the backend.

go to my route after authentication when I use middleware in laravel

I have this route in web.php (laravel 5.4)
Route::get('/sample', function (App\User $user) {
return "inja sampleee";
})->middleware('auth:api');
I want after when user enter /sample path in browser Beginning login user then show massage "this is sampleee". but by this code after authentication go to the way that define in handle methods Middleware. how can return to what I want in my route that define in my route.
I changed App\Http\Middleware\RedirectIfAuthenticated.php is it correct file?
I added return $next($request); after // return redirect('/home'); line.
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* #param \Illuminate\Http\Request $request
* #param \Closure $next
* #param string|null $guard
* #return mixed
*/
public function handle($request, Closure $next, $guard = null)
{
if (Auth::guard($guard)->check()) {
// return redirect('/home');
return $next($request);
}
return $next($request);
}
}

SMS Integration with Magento API

I am using Magento 1.8.1 and I want to integrate SMS with our store.
I have an API URL of SMS but don't know how and where to put that URL in Magento.
They provide me this code:
<?php
class sendsms
{
private $api_url;
private $time;
private $unicode;
private $working_key;
private $start;
private $sender_id;
public $api;
public $wk;
public $sid;
public $to;
/**function to set the working key
*
* #param string_type $wk:helps to change the working_key
*/
function setWorkingKey($wk)
{
$this->working_key=$wk;
}
/**function to set sender id
*
* #param string_type $sid:helps to change sender_id
*/
function setSenderId($sid)
{
$this->sender_id=$sid;
}
/**function to set API url
*
* #param string_type $apiurl:it is used to set api url
*/
function setapiurl($apiurl)
{ $this->api=$apiurl;
$a=strtolower(substr($apiurl,0,7));
if ($a=="http://") //checking if already contains http://
{
$api_url=substr($apiurl,7,strlen($apiurl));
$this->api_url=$api_url;
$this->start="http://";
}
elseif ($a=="https:/") //checking if already contains htps://
{
$api_url=substr($apiurl,8,strlen($apiurl));
$this->api_url=$api_url;
$this->start="https://";
}
else {
$this->api_url=$apiurl;
$this->start="http://";
}
}
/** function to intialize constructor
*
* #param string_type $wk: it is working_key
* #param string_type $sd: it is sender_id
* #param string_type $apiurl: it is api_url
* used for intializing the parameter
*/
function __construct($apiurl,$wk,$sd)
{
$this->setWorkingKey($wk);
$this->setSenderId($sd);
$this->setapiurl($apiurl);
}
/**
* function to send sms
*
*/
function send_sms($to,$message,$dlr_url,$type="xml")
{
$this->process_sms($to,$message,$dlr_url,$type="xml",$time="null",$unicode="null");
}
/**
* function to schedule sms
*
*/
function schedule_sms($to,$message,$dlr_url,$type="xml",$time)
{
$this->process_sms($to,$message,$dlr_url,$type="xml",$time,$unicode='');
}
/**
* function to send unicode message
*/
function unicode_sms($to,$message,$dlr_url,$type="xml",$unicode)
{
$this->process_sms($to,$message,$dlr_url,$type="xml",$time='',$unicode);
}
/**
* function to send out sms
* #param string_type $to : is mobile number where message needs to be send
* #param string_type $message :it is message content
* #param string_type $dlr_url: it is used for delivering report to client
* #param string_type $type: type in which report is delivered
* #return output $this->api=$apiurl;
*/
function process_sms($to,$message,$dlr_url="",$type="xml",$time='',$unicode='')
{
$message=urlencode($message);
$this->to=$to;
$to=substr($to,-10) ;
$arrayto=array("9", "8" ,"7");
$to_check=substr($to,0,1);
if(in_array($to_check, $arrayto))
$this->to=$to;
else echo "invalid number";
if($time=='null')
$time='';
else
$time="&time=$time";
if($unicode=='null')
$unicode='';
else
$unicode="&unicode=$unicode";
$url="$this->start$this->api_url/web2sms.php?workingkey=$this->working_key&sender=$this->sender_id&to=$to&message=$message&type=$type&dlr_url=$dlr_url$time$unicode";
$this->execute($url);
}
/**
* function to check message delivery status
* string_type $mid : it is message id
*/
function messagedelivery_status($mid)
{
$url="$this->start$this->api_url/status.php?workingkey=$this->working_key&messageid=$mid";
$this->execute($url);
}
/**
* function to check group message delivery
* string_type $gid: it is group id
*/
function groupdelivery_status($gid)
{
$url="$this->start$this->api_url/groupstatus.php?workingkey=$this->working_key&messagegid=$gid";
$this->execute($url);
}
/**
* function to request to clent url
*/
function execute($url)
{
$ch=curl_init();
// curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output=curl_exec($ch);
curl_close($ch);
echo $output;
return $output;
}
}
I am new to Magento, so please help me with the API integration.
For SMS Integration you need to decide what event you want to handle.
Magento Events List are available here.
After it you need to create observer for choosen event.
An Observer is an event handler. It listens to any event it is attached to and accordingly reacts to the event.
Your SMS API should be usen in observer. ( It is method in PHP class. )
For creating observer in Magento you need to read this documentation.

Sending email to GMail with Zend_Mail

I'm developing a webapp which has to send mail, I'm using the basic mail router (which is sendmail if I'm not wrong) with the following interface class :
class My_Mail_Interface
{
protected $_defaultCharset = 'utf-8';
public function __construct() {
$this->init();
}
public function init() {
}
/**
* Send the email
* #param string $from the sender address
* #param string $to the receiver address
* #param string $subject the subject
* #param string $bodyHtml the HTML message
* #param string $bodyText the text message
* #param string $sender the sender label
* #param string $receiver the receiver label
* #return void
*/
public function send($from, $to, $subject, $bodyHtml = NULL, $bodyText = NULL, $sender = NULL, $receiver = NULL) {
if (!isset($sender)) {
$sender = $from;
}
if (!isset($receiver)) {
$receiver = $to;
}
$mail = $this->_getNewMail();
$mail->setFrom($from, $sender);
$mail->addTo($to, $receiver);
$mail->setSubject($subject);
$mail->setBodyHtml($bodyHtml);
$mail->setBodyText($bodyText);
$mail->send();
}
/**
* Get a new mail object
* #return Zend_Mail
*/
protected function _getNewMail() {
return new Zend_Mail($this->_defaultCharset);
}
}
It works fine when it's about sending email to a Yahoo address but it fails when sending email to a GMail one. I plan to move to mail services like SendGrid in the future, but for test purpose using this configuration shouldn't be a problem. Is there a point I'm missing or has GMail becomed SPAM paranoiac ?