How to reset passwords in Laravel 5? - laravel

I am working on a project using Laravel 5 and I am trying to figure out how to reset passwords. I know the migration for the password resets is already there but I remember there was a ReminderController in Laravel 4 which I could generate but I cannot find the same in Laravel 5.
I am sure that Laravel 5 ships with a password reset mechanism but I cannot exactly figure out where to send the request and the method which handles sending the emails?
I can find the views and the migration but can anyone help me find the controller method and route. If anyone can provide me with a tutorial, I could work with that too.

Laravel also includes an
Auth\PasswordController 
that contains the logic necessary to reset user passwords. We've even provided views to get you started! The views are located in the
resources/views/auth 
directory. You are free to modify these views as you wish to suit your own application's design.
Your user will receive an e-mail with a link that points to the 
getReset method
of the
PasswordController.
This method will render the password reset form and allow users to reset their passwords. After the password is reset, the user will automatically be logged into the application and redirected to /home. You can customize the post-reset redirect location by defining a redirectTo property on the PasswordController:
protected $redirectTo = '/dashboard';
Source

Related

Laravel Multihauth: To be or Not to Be?

I am building an app and will need multi auth to works well. First, users that will log as employees using table users with email and password. I´m using Voyager as backend and using roles and permissions. So far, so good. Now I have another kind of user: they are registered on an ERP and I reach then via WS using CPF (like the social-secure number) and password stored in ERP. Then I get then and record at a table all the data I need. It is working well as good. Well, was working. For those users, I used the API route, just not to make a mess on my web routes file. Yesterday I ran PHP artisan make:auth and that´s when things start to get crazy.
Every axios call now returns me an 'unauthorized' message cause, obviously, they´re not authenticated.
What would be better?
Refactory Users login to use CPF instead of email and give a new role for those others API guys and make then pass trough web.php file like everybody?
Use a multiauth package?
Or anything else?
Please, help!
To me, a user is a user. It seems to be a common thing that if an application has more than one “type” of user, that developers instantly start creating multiple Eloquent models, then guards, then controllers, then views, and so on; and then find themselves in a mess when they need a route that can be accessed by more than one type of user.
Instead, elevate “type” to its own model and add it as a relation to your User model. If a user can only be of one type, then make it a one-to-many relation. If a user can have many roles, then make it a belongs-to-many relation. You then use authorization to determine whether a user can access a route based on the role(s) they have.

Laravel 5.1 How to build forgot password functionality

I am using laravel 5.1 and I do not know how I should built in the functionality that a user can reset his / her password.
Typing the mail address and getting a route to reset and submit a new password.
I could not find a good tutorial for this purpose so I ask here.
You can make use of laravel authentication - reset password feature for that. The document is self-explanatory.

Changing default functionality in ion auth

I need to change some default functionality of ion auth once a new user has been created by an admin.
The scenario is like so...
Admin creates the user account.
Activation email is sent to the user.
Clicking the link sends the user to the set password page.
Upon setting a password, the user is activated and can log in.
Currently I haven't found a way to define the activation link once ion auth calls the register function and the email is sent. It's set to auth/activate.
The options I see are as follows...
Redefine the behaviour of Auth/activate(). Is this recommended though? Should I be touching the methods in the Auth controller?
Turn off $config['email_activation'] and handle everything myself.
Somehow changing the default controller/method behaviour to handle the activation of the user.
What do people usually do in this situation? Which is best practice?
Ok, after much searching I was reading through https://github.com/benedmunds/CodeIgniter-Ion-Auth/blob/2/libraries/Ion_auth.php and noticed the email message being generated was being sent to an email_template (in the view), which I had forgot to check. The activate.tpl.php is where you can find the code that generates the path to the Auth controller.
<?php
echo sprintf(lang('email_activate_subheading'), anchor('auth/activate/'. $id .'/'. $activation, lang('email_activate_link')));
?>
Now I can just easily change the controller path, it makes sense to write my own controller.

modify auth code of laravel 5 as per my list of requirements

I have a old database on which I want to use new Laravel 5.2, i want to change its User Authentication code to my requirements like - its tablename, username field(its not a email field), its password and also need to stop laravel from encrypting the password as the password are not encrypted in the database, also I need to remove features like remember me option, register new users ... Can anyone please help/guide me.
password from users and database are one and the same - laravel shall not encrypt the password string.
I am trying to succeed in all the above things together past 2 days now. if one thing is rectify I goof up with another. specially in case of password checking - currently any / wrong password will also be allowed as a user - only username needs to be correct.
Thanx in advance.
I assume that you're using AuthController class that Laravel provides, your user model class is called User and you're using Eloquent user provider as it's the default one.
In order to change the name of the table that stores users you need add the following to your User class:
protected $table = 'your_table';
If you want to change the column that is used to login users from email to another column, you need to add the following code to your AuthController:
protected $username = 'username';
Registration won't be available to your users if you don't define routes for those actions so no need to disable that.
In order to disable remember-me functionality you need to override setRememberToken() of your User model and make it empty. This way remember-me token won't be saved for that user which will prevent user from logging-in automatically:
public setRememberToken() {}

Login automatically after registration using tank_auth for codeigniter

After reading a lot of answers here on what is the best authentication out there for codeigniter, I decided to use tank_auth.
It seems to be the best authentication for codeigniter.
However, I have some few questions regarding on how I can integrate it successfully on my site. I am currently building a hotel reservation system. So some functionality of tank_auth needs to be modified to suit my needs.
So how can I, after registration, login the user automatically without requiring him/her to activate his/her account. Is there a configuration to disable the "activation process". If yes, where can I find it? If no, is it a big modification to the code if I remove the activation process?
On the auth.php code I tried to comment the following code to remove the activation process but seems it does not work:
} elseif ($this->tank_auth->is_logged_in(FALSE)) { // logged in, not activated
redirect('/auth/send_again/');
That code only works when the user account exists but is not activated. it then resends an activation email...
Look at the register part of the library and set the login session parameters to be true ie parameters that sets login to be true and then direct to the protected area!

Resources