Welcome email with create password link in laravel7 - laravel

I'm creating an one form where the admin register the new users and then an email is sent to this new user with a welcome message and a link to create a new password.
This last part I'm having problems as I can't find info on how to generate the token and the link.
This link should redirect the user to a create password page, which is different than the reset password.
Thanks !
Below is my add user controller:
public function contactSave(Request $request)
{
$token = $request->_token;
$user= new User;
$user->name = $request->name;
$user->email = $request->email;
$user->password = $password;
$user->save();
if($user->id)
{
$CustomerContact= new CustomerContact;
// $CustomerContact->name = $request->name;
// $CustomerContact->email = $request->email;
$CustomerContact->phone = $request->phone;
$CustomerContact->address = $request->address;
$CustomerContact->user_id = $user->id;
$CustomerContact->country_id = $request->country;
$CustomerContact->state_id = $request->state;
$CustomerContact->comment = $request->comment;
$CustomerContact->organization = $request->organization;
$CustomerContact->captcha = $request->captcha;
$CustomerContact->save();
$details = [
'title' => 'Hi '.$request->name.'',
'body' => 'Your account has been created successfully. Request you set your password with this link',
// 'link' => URL::route('password/reset/'.$token)
];
\Mail::to($request->email)->send(new \App\Mail\ContactMail($details));
}
return redirect('contacts')->with('success', 'User created successfully.');
}
Current I am just sending mail to user mail id. I am not getting how to send password reset (password set link) url into that mail.
On that link click forgeot password form open and user can reset there passowrd.
Anyone idea then let me know.

Related

update data to database laragon using api

I want to update data to the database in ionic. how to make the data update. Here what I tried. I try using postmen to post the api and it appear success but the data does not change.
in api.php
public function update (Request $request)
{
$id = $request->id;
$medname = $request->medname;
$price = $request->price;
$stock = $request->stock;
$medno = $request->medno;
$ingredient = $request->ingredient;
$description = $request->description;
$addinfo = $request->addinfo;
AddMedicine:: where('medname',$medname)->update([
'id' =>$id,
'medname'=>$medname,
'price'=>$price,
'stock'=>$stock,
'medno'=>$medno,
'ingredient'=>$ingredient,
'description'=>$description,
'addinfo'=>$addinfo,
]);
$msg = "Data Updated";
$datamsg = response()->json([
'success' => $msg
]);
return $datamsg->content();
}
route
Route::put('/update','ApiController#update');
Are you sure use PUT request ? Because need to CSRF token please inspect
https://stackoverflow.com/questions/30756682/laravel-x-csrf-token-mismatch-with-postman

Voyager - Can we send e-mail when admin add user?

I am trying send information e-mail to user when admin add user. But i don't know how can i intervene the Userpage in Adminpanel?
For example: Welcome "$user->name", your username is "$user->username" and your password is "$user->password".
I think about a lot. But can't progress. Still can not send any email. Do we have a way to make this e-mailing system easier in voyager tables?
edit: Added Registercontroller
public function register(Request $request)
{
$this->validation($request);
$customer = new Customer();
$customer->name = $request->name;
$customer->surname = $request->surname;
$customer->phone = $request->phone;
$customer->email = $request->email;
$customer->password = bcrypt($request->password);
$customer->description = $request->password;
$customer->save();
Auth::guard('customer')->login($customer);
Session::flash('success', __('messages.success'));
return redirect('/');
edit: Added CustomerObserve.php
<?php
namespace App\Helper\Observers;
use App\Customer;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Mail;
class CustomerObserve implements ShouldQueue
{
public function created()
{
$customer = Customer::latest();
Mail::send('user_login_informations', ['customer' => $customer], function($message) use($customer) {
$message->to($customer->email, $customer->name)
->subject('account update');
})->delay(30);
}
}
create an email template in view folder
email.blade.php
#section('content')
<h2>Hello {{ ucfirst($customer->name) }},</h2>
<p>
Your email '{{ $customer->email }}' and password {{ $customer->password }}.
</p>
#stop
Reviewer controller
$this->validation($request);
$customer = new Customer();
$customer->name = $request->name;
$customer->surname = $request->surname;
$customer->phone = $request->phone;
$customer->email = $request->email;
$customer->password = bcrypt($request->password);
$customer->description = $request->password;
$customer->save();
Auth::guard('customer')->login($customer);
Session::flash('success', __('messages.success'));
Mail::send('email', ['customer' => $customer], function($message) use($customer) {
$message->to($customer->email, $customer->name)
->subject('account update');
});
return redirect('/');

Update user avatar profil Laravel 4.2

I have a little problem about update avatar pic of my user.
I have a polymorph relation table for Image and when i update info of my user profile and upload new avatar in my DB he create a new entry and not updated the current id of my table Images.
Table Images Id|path|Imageable_id|imageable_type|created_at
My UsersController method update
public function update($id){
$rules =[
/*'lastname' => 'min:3|string',
'firstname' => 'min:3|string',
'username'=> 'min:4|unique:users',
'mail' => ' email|unique:users',
'birthday' => 'date_format:d-m-Y|before:today',
'country'=>'min:3',
'type_street'=>'min:3',
'number'=>'min:1|numeric',
'street'=>'min:4|string',
'complementary_street'=>'min:2|string',
'town'=>'min:2|string',
'zip'=>'min:4|numeric',
'phone_home'=>'min:10|numeric',
'phone_mobile'=>'min:10|numeric',
'image_path'=>'image|max:1000|mimes:jpeg,jpg,png',*/
];
$validator = Validator::make(Input::all(),$rules);
if($validator->fails()){
return Redirect::to('/profil/'.$id)
->with('alert_error','Merci de corriger les erreurs');
}else{
$user = User::find($id);
$user->lastname = Input::get('lastname');
$user->firstname = Input::get('firstname');
$user->username = Input::get('username');
$user->mail = Input::get('mail');
$user->birthday = Input::get('birthday');
$user->adresse->type_street = Input::get('type_street');
$user->adresse->number = Input::get('number');
$user->adresse->street = Input::get('street');
$user->adresse->complementary_street = Input::get('complementary_street');
$user->adresse->town = Input::get('town');
$user->adresse->zip = Input::get('zip');
$user->adresse->country = Input::get('country');
$user->adresse->phone_home = Input::get('phone_home');
$user->adresse->phone_mobile = Input::get('phone_mobile');
if(Input::hasFile('avatar')){
$avatar = Image::find($id);
$file = Input::file('avatar');
$name = time().'-'.$file->getClientOriginalName();
$file = $file->move('img/avatar/', $name);
$input['path'] = 'img/avatar/'.$name;
$input['imageable_id'] = $user->id;
$input['imageable_type'] = 'User';
$avatar = new Image($input);
$avatar->save();
}
$user->adresse->save();
return Redirect::to('/profil/'.$id)
->with('alert_success','Modification sauvegardé avec succès');
}
}
Can you help me for this feature i don't understand why no updated of current id of my entry and create new One .
Thank's
You're overwriting your find $avatar = Image::find($id); with a new instance $avatar = new Image($input);

Joomla 2.5+: Creating an Account and Log in within the same Controller Call

I have created a from with a user registration. When processing the form within the controller, I want the user to be logged in afterwards. Account creation works fine, but logging right afterwards fails:
function processForm($username,$first_name,$last_name,$email,$password,$groups) {
jimport('joomla.user.helper');
$app = JFactory::getApplication('site');
$user = new JUser();
$b= array();
$user->bind($b);
$user->username = $username;
$user->name = $first_name." ".$last_name;
$user->set('id',0);
$date =date("Y-m-d H:i:s");
$user->set('registerDate', $date);
$user->email = $email;
$user->set('password',JUserHelper::getCryptedPassword($password,JUserHelper::getSalt()));
$user->set('block', '0');
$user->save();
foreach ($groups as $group) {
JUserHelper::addUserToGroup($user->id, $group);
}
$app->login(array("username"=>$username,"password"=>$password));
}
Any idea?

parameter mismatch,pattern is a string while replacement is an array

Trying to resend login details to a user through his mail.what I want to do is after the user has click on the forgotten password link, a form is displayed requesting for his email to be posted.after the email has been posted, I check if the email corresponds to an email in the users table and send details.
Here's my controller:
public function postResendPassword()
{
$posted = Input::get();
$email = $posted['email'];
$user = User::where('email', '=', $email)->first();
$user_password= $user->password_confirmation;
$user_username = $user->username;
$user_email = $user->email;
$to = $user->email;
$subject = " login details request";
$message =
<h3>login details</h3>
email : $user_email
login password : $user_password
regards;
mail($to, $subject, $message);
}
how do I go about this and fix this error

Resources