FosUserBundle: password reset request link is sent instead of resetting link - php

I am trying to send email with password reset link. This is my method:
public function sendPasswordResettingEmail(User $user){
$url = $this->router->generate('fos_user_resetting_reset',
array('token' => $user->getConfirmationToken()), UrlGenerator::ABSOLUTE_URL);
$html = $this->templating->render('CoreBundle:Email:password_reset.email.twig', array(
'user' => $user,
'confirmationUrl' => $url
));
$message = \Swift_Message::newInstance()
->setContentType('text/html')
->setSubject('Password reset')
->setFrom(array(self::EMAIL_FROM => 'App'))
->setTo($user->getEmail())
->setBody($html);
$this->service->get('mailer')->send($message);
}
But I get email with
http://127.0.0.1:8000/resetting/request
link, which takes me to a form asking for email or username. I need to submit my email address again to get resetting
http://127.0.0.1:8000/resetting/reset
link.
Is it possible to get reset link and skip request step? because I am already providing user parameter to method.

Related

Laravel how to pass the name of the user when I sent the forgot password function

I want to make my mail more detailed when the user has sent a forgot password reset link to his/her email. This is the sample of the picture when receiving a reset password link.
I want to add some details here that the Hello should be Hello! (user name here)
Here is the code that I added in my SendsPasswordResetEmails.php
public function sendResetLinkEmail(Request $request)
{
$this->validateEmail($request);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$response = $this->broker()->sendResetLink(
$request->only('email')
);
$applicant_name = Applicant::where('email', $request->email)->get()->value('name');
return $response == Password::RESET_LINK_SENT
? $this->sendResetLinkResponse($response)
: $this->sendResetLinkFailedResponse($request, $response);
}
and it should pass the data to app\Notifications\ApplicantResetPasswordNotification.php
public function toMail($notifiable)
{
return (new MailMessage)
->from('vcc3dummy#gmail.com', 'CCV3')
->greeting('Hello! Applicant Name') // Applicant name pass here
->line('You are receiving this email because we received a password request for your account.')
->action('Click here to Reset Password', route('applicant.reset', $this->token))
->line('If you did not reset your password, no further action is required.');
}
Looking for help on how to pass the data or how to query it.
Would appreciate if someone could help me
Thanks in advance.
In your ApplicationResetPasswordNotification.php you can use the $notifiable variable as follows:
public function toMail($notifiable)
{
return (new MailMessage)
->from('vcc3dummy#gmail.com', 'CCV3')
->greeting('Hello!' . $notifiable->name) // Applicant name
...
}
Please mark as answer if that works for you!
This is the another way to send the mail in laravel -
Put that data you want to use/show in email template.
$data = [
'email' => $email,
'remember_token' => $remember_token,
'name' => $applicant_name
];
Mail::send('emails/forgotmail', $data, function ($message) use ($data) {
$message->from('youremail#gmail.com');
$message->to( $data['email'] )->subject('Forgot Password Link');
});
Where as 'email/forgotmail' is in 'resources/views/email/forgotmail.blade.php' that you have to create. So that here you can put your email template over here and make use of $data in it .

No method matching arguments: java.lang.String, java.util.HashMap XMLRPC infusionsoft

I am developing code that sends an email from our website through Infusionsoft API & XMLRPC.
Here my code:
$email = $user_rec['email'];
$contactID=$user_rec['client_infusionid'];
echo $contactID;
$Subject = 'Your reset password request at GIC Deal Finders';
$From = $this->GetFromAddress();
$link = 'http://dashboard.gicdealfinders.info/resetpwd.php?email='.
urlencode($email).'&code='.
urlencode($this->GetResetPasswordCode($email));
$htmlBody ='Hello '.$user_rec["name"].'<br/><br/>'.
'There was a request to reset your password at GIC Deal Finders<br/>'.
'Please click the link below to complete the request: <br/>'.$link.'<br/><br/>'.
'<br/>'.
'Regards,<br/>'.
'Toyin Dawodu, MBA<br/>'.
'Founder and Chief Relationship Officer';
$clients = new xmlrpc_client("https://ze214.infusionsoft.com/api/xmlrpc");
$clients->return_type = "phpvals";
$clients->setSSLVerifyPeer(FALSE);
###Build a Key-Value Array to store a contact###
$emailI = array(
'contactList' => $contactID,
'fromAddress' => $From,
'toAddress' => $email,
'ccAddresses' => 'admin#gicdealfinders.info',
'bccAddresses' =>'abhilashrajr.s#gmail.com',
'contentType' => 'HTML',
'subject' => $Subject,
'htmlBody' => $htmlBody,
'textBody' => 'test');
//$check=$myApp->sendEmail($clist,"Test#test.com","~Contact.Email~", "","","Text","Test Subject","","This is the body");
###Set up the call###
$calls = new xmlrpcmsg("APIEmailService.sendEmail", array(
php_xmlrpc_encode($this->infusion_api), #The encrypted API key
php_xmlrpc_encode($emailI) #The contact array
));
###Send the call###
$results = $clients->send($calls);
//$conID = $results->value();
/*###Check the returned value to see if it was successful and set it to a variable/display the results###*/
if(!$results->faultCode()) {
return true;
} else {
print $results->faultCode() . "<BR>";
print $results->faultString() . "<BR>";
return false;
}
The captured error shows:
-1
No method matching arguments: java.lang.String, java.util.HashMap
Can anyone check my code and show me a way to fix it?
As the returned error says, the wrong parameters are sent to Infusionsoft API.
The list of acceptable parameters is provided in Infusionsoft API documentation.
First of all, you need to add your API key as the first value in $emailI array.
Also, Infusionsoft API expects the second parameter to be a list of Contact IDs, which means the second parameter $contactID must be sent from php side as an array.
The following code shows the fixes:
$emailI = array(
'yourApiKey',
array($contactID),
$From,
$email,
'admin#gicdealfinders.info',
'abhilashrajr.s#gmail.com',
'HTML',
$Subject,
$htmlBody,
'test'
);
$calls = new xmlrpcmsg(
"APIEmailService.sendEmail",
array_map('php_xmlrpc_encode', $emailI)
);
Please also notice, that if you have more then just one or two Infusionsoft API calls in your code, it's advisable to use API Helper Libraries. Also you may find another wrappers for Infusionsoft API at github.com if current official Helper Libraries don't work for you.

Laravel : Password reset email check against user

I have the following code to send the password reset email to the users email which is working:
$response = $this->passwords->sendResetLink($request->only('email'),function($message)
{
$message->subject('Password Reminder');
});
What i want is that user should write their username instead of email, And i will check the email against that username , And will send the email.So i came up with this idea.
$usernameToEmail = User::where('name','=', Input::get('username'))->first();
$response = $this->passwords->sendResetLink(['name' => $usernameToEmail],function($message)
{
$message->subject('Password Reminder');
});
Which is not working also.
Am i missing something ?
You're close, but your $usernameToEmail variable contains a User object, not an email string. Most likely you just need to add a method to your chain:
$usernameToEmail = User::where('name','=', Input::get('username'))->first()->email;

Laravel 5 login authenication issue

I have an issue with user authentication. I can create a new user and use laravel's Hash::make command to encrypt the password which all appears to be working correctly see database record below :
Now for the login script. I did a dump die on the $input and confirmed it has the post data from the login form inside it.
Code :
public function CheckLogin()
{
$input = Request::all();
// create our user data for the authentication
$userdata = array(
'Email' => $input['email'],
'Password' => $input['password']
);
// attempt to do the login
if (Auth::attempt($userdata)) {
// if(Auth::attempt(['Email' => $input['email'], 'Password' =>$input['password'], 'ArchivedOn' => null])){
//return redirect()->intended('devices');
return redirect()->intended('devices');
} else {
$err = 'Login Failed Please check credentials and try again.';
return view('welcome', compact('err'));
}
}
The Auth::attempt appears to always return false as it always re-directs to the welcome page with the error message I specified.
I expectect I am missing something obvious but I thought I would ask for a fresh pair of eyes on this as I can't see the problem.
Your userdata should be:-
$userdata = array(
'Email' => $input['email'],
'password' => $input['password']
);
Note: You need to write Password 's p character in small letter. You can change email with Email or Username whatever name you want but password must be 'password'.
Check this link for more detail.

Send link with variable using Zend_Mail

I am triyng to send a email with a link when the user complete registration.
The link should have a variable $id with the id of the user.
I tried different things but my link always appear as
http://localhost/users-data/activate/.php?id=>
I am using Zend_Mail.
What I am trying to do, is for example: send to user id =1 a link http://localhost/users-data/activate1. For then I can take the last number of url, which should correspond to id, and set the status to this user in my activate script.
Could you show me what I doing wrong?
This is my registerAction
public function registerAction()
{
// action body
$request = $this->getRequest();
$form = new Application_Form_UsersData();
if ($this->getRequest()->isPost()) {
if ($form->isValid($request->getPost())) {
$comment = new Application_Model_UsersData($form->getValues());
$mapper = new Application_Model_UsersDataMapper();
$mapper->save($comment);
// send email
$id = $comment -> getId();
$formValues = $this->_request->getParams();
$mail = new Application_Model_Mail();
$mail->sendActivationEmail($formValues['email'], $id,$formValues['name']);
$this->_redirect('/users-data/regsuccess');
}
}
$this->view->form = $form;
}
This is my Application_Model_Mail
class Application_Model_Mail
{
public function sendActivationEmail($email, $id,$name)
{
require_once('Zend/Mail/Transport/Smtp.php');
require_once 'Zend/Mail.php';
$config = array('auth' => 'login',
'username' => '*******#gmail.com',
'password' => '******',
'port' => '587',
'ssl' => 'tls');
$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com',$config);
Zend_Mail::setDefaultTransport($tr);
$mail = new Zend_Mail();
$mail->setBodyText('Please click the following link to activate your account '
. '<a http://localhost/users-data/activate/.php?id='.$id.'>'.$id.'</a>')
->setFrom('admin#yourwebsite.com', 'Website Name Admin')
->addTo($email, $name)
->setSubject('Registration Success at Website Name')
->send($tr);
}
}
You go from $request to $_request. The latter is not defined anywhere, so its values are null.
Try this
$mail->setBodyHtml("Please click the following link to activate your".
"account<a href='http://localhost/users-data/activate.php?id=$id'>$id</a>")
The HTML link you create is incorrect:
'<a http://localhost/users-data/activate/.php?id='.$id.'>'
In HTML, a valid link is (note the href attribute):
...
So your script should construct the link like this:
'<a href="http://localhost/users-data/activate/.php?id='.$id.'">'
Also, I suppose http://localhost/users-data/activate/.php is not what you want: your script has probably a name before the php extension.

Categories