How to disable password reminder email in Laravel - laravel

I'd like the Password::remind method to respond with the token and not send email to the email address provided. Can I suppress/disable email?
help would be much appreciated.

I don't think you can, the best you can do is to make one yourself, using Laravel's way of doing it:
Create a new class:
<?php
use Illuminate\Auth\Reminders\DatabaseReminderRepository as DbRepository;
class Reminder {
public static function create($user)
{
$reminders = new DbRepository(DB::connection(), Config::get('auth.reminder.table'), Config::get('app.key'));
return $reminders->create( $user );
}
}
And use it
$user = User::find(2);
echo Reminder::create($user);
After that you can check your password_reminders table, you new token will be there:
select * from password_reminders;

Related

Pin Verification In Laravel

I'm a beginner. I have a pin field in my user database. I want users to verify the pin before they can access there profile. how can I do this any logic?
in livewire components
public function verify (){
$user = User::select('id')->where('pin',$pin)->first();
Auth::loginUsingId($user->id);
return redirect()->intended('/user');
}
in my livewire blade I will call the verify method in the form will this work
laravel login using pincode :check the following code example may be you get the hint how to implement that, in this example code pin authentication is done using JWT and then user is allowed to access to those specific routes.
$user = User::find($uid);
try {
if (!$token = JWTAuth::fromUser($user)) {
return $this->onUnauthorized();
}
} catch (JWTException $e) {
return $this->onJwtGenerationError();
}
For somereason if you dont want to use the above JWT method you can use this one. i'm sharing the code for an example from by program which may help you
$user = User::select('id')->where('pin',$pin)->first();
Auth::loginUsingId($user->id);
return redirect()->intended('/user');

problem in laravel route on tackling the response of payment gateway

I'm using laravel and integrate the payment gateway.when i send the post request then after success or cancellation ,it redirect the referece id like this
http://localhost/multi_vendor/user/paypal/return?flwref=FLW-MOCK-d4f7572650fbe61ecff7fb17a7129859&txref=rave-bxw7c98dymo8so0kwosco0wwscs8ogc
so how can tackle it in laravel?
I made route for this
Route::get('/paypal/return', 'User\PaypalController#payreturn')->name('user.payment.return');
You can create a route as you write above:-
Route::get('/paypal/return', 'User\PaypalController#payreturn')->name('user.payment.return');
Then in User\PaypalController Controller method payreturn, you can do as following:-
<?php
namespace App\Http\Controllers\User;
use Illuminate\Http\Request;
class PaypalController extends Controller
{
public function payreturn(Request $request)
{
//Here you can get the response request values
$ref = $request->flwref;
$TxRef = $request->txref;
}
}
I also didn't understand well your question, but let me try.
Possible appointments:
if your route is like localhost/multi_vendor/user/paypal/return, you must represent all steps in route file, something like Route::get('/multi_vendor/{user}/paypal/return,[...]). If you are already using somethink like it or a group with prefix, ignore it;
if you wish to redirect, you could use return redirect('yourCompleteUrl') in your controller or in route file;
if you wish to retrieave the parameters Tim Lewis anserwed what you need:
public function payreturn(Request $request)
{
$flref = $request->input('flref');
$txref = $request->input('txref');
}
#darnish manzoor just add your url callback rootverto verifycrsf token
if your redirection url is /ravecallback, just add it and it will stop giving you method not allowed
protected $except = [
'/ravecallback'
];

How to handle data before delete from model in Laravel?

I have the following method:
public function destroy($id)
{
$id = \JWTAuth::parseToken()->authenticate();
$offer = Offer::findOrFail($id);
$offer->delete();
return response()->json(["offer" => $offer]);
}
How handle data before deleting? I need to check if user has permit to delete data or not
When you use the authenticate() method, the user model is retrieved so it means the id you have is not an id but a User. Have you checked the documentation of JWT Because first and foremost you have to retrieve the user and this is sufficient:
$user = \JWTAuth::parseToken()->authenticate();
Then if you have a field for example in your users table to tell if the user have the right say admin which can be 1 or 0 then you can do the following:
if($user->admin == 1)
{
$offer = Offer::findOrFail(1); //say id
$offer->delete();
return response()->json(["offer" => $offer]);
}
return response()->json(['error' => 'you dont have the right to delete this'], 403);
Just a little scratch on the idea, but my best advice is to do some searches on how JWT is implemented, I am pretty sure you will find tons of them online.
I would recommend using the Model's delete event:
https://github.com/laravel/framework/blob/5.2/src/Illuminate/Database/Eloquent/Model.php#L1122
and handle it.
This will guarantee that if you use the delete method on a model, you always check permissions.

How to design controllers communication

Lets say I have UserControler that handles user creation deletion etc and Comments conntroler that handles comment's adding deleting modyfing etc.
What If my user wants to add a comment? Should the userController have addComment method? Or should I handle this in commentsController(if so how do I pass user data)?
Maybe I don't need commentsController at all?
How do I design it properly according to MVC(I am using laravel)?
You can always get the authenticated user info using these methods:
//Will return the authenticated User object via Guard Facade.
$user = \Auth::user();
//Will return the User Object that generated the resquest via Request facade.
$user = \Request::user();
If you set your route to something like this:
Route::get('posts/{posts}/comments/create', 'CommentsController#create');
Then you can create a button (i'll use bootstrap here and hipotetical ids) that points to:
Create
On your CommentsController you can have something like this:
public function create($post_id)
{
$user = .... (use one of the methods above);
$post = ... (get the post to be commented, if thats the case)
... Call the create comment function
return redirect(url('posts/9'));
}
Immediate answer would be CommentController , this is the controller that should add/delete/edit comments.
Can any one else add/delete/edit comments other than users? If yes, are they going to go into same business/domain object?
Lets say if you have User Comments and Customer Comments have separate Business/Domain comment objects , in this case you may have separate UserCommentsController and CustomerCommentsController.
And as #Arthur Samarcos suggested you can get user info.
In a case like this where each comment belongs to only one user, I would set that up in the comment controller because the user id is really just another attribute of that comment.
Additionally, I find it best to abstract this logic to a repository in the case you will need to eventually create a comment from another controller or somewhere else in your app. Maybe if the user takes some action you want to auto-generate comments when those actions are taken. The repository could look like this...
class CommentRepository {
protected $comment;
public function __construct(Comment $comment)
{
$this->comment = $comment;
}
public function newComment($user_id, $content)
{
$comment = $this->comment->newInstance();
$comment->user_id = $user_id;
$comment->content = $content;
$comment->save();
return $comment;
}
}
Then you'd inject that repository into your controller which would look something like this...
class CommentController extends BaseController {
protected $cr;
public function __construct(CommentRepository $cr)
{
$this->cr = $cr;
}
public function create()
{
$comment = $this->cr->newComment(Auth::user()->id, Input::get('content'));
return Redirect::route('comments.index');
}
}
There are a few benefits to this approach. One as I said earlier, it makes your code reusable and easy to understand. All you need to do is inject the repository into your controller where you need it. Two is it becomes much more testable.

magento pass variable from controller to another model

I want to send custom mail through smtp.For which I installed http://www.magentocommerce.com/magento-connect/aschroder-com-smtp-pro-email-free-and-easy-magento-emailing-for-smtp-gmail-or-google-apps-email.html.
Which works properly for every mail provided by magento as default.
Now since the admin is having mail Id of google apps , my custom mail is not received by admin.So for this reason I want to Integrate my controller with the sending mail function of ashrodder extension.
My Controller code:
$frm = 'mail#domainname.com';
$to = 'admin#domainname.com';
$subject = "UPDATE";
$mail = new Zend_Mail('utf-8');
$mail->setBodyHtml($message)
->setFrom($frm, 'Admin')
->addTo($to, 'Site Admin')
->setSubject($subject);
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Mail sent successfully.');
}
catch(Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send email.');
}
My question is simple : How should I pass [to,from,body] variable to any other model/controller ?
Please Help .Thanks in Advance
I think overriding the extensions controller would be the best solution.Check this link How to extend a controller

Resources