0

I am a novice web developer. I am following the password reset tutorial for laravel 5.1 found here

Currently the default view they are listing in their documentation asks the user to type his/her email into the form. I was wondering how I could just set the reset email using the users email I already have in my DB and posted to the URL the form below has.

I can get the logged in users email like this:

App\User::find(Auth::user()->id)->email

the form

<form method="POST" action="dashboard/password/email">
    {!! csrf_field() !!}

    @if (count($errors) > 0)
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    @endif

    <div>
        Email
        <input type="email" name="email" value="{{ old('email') }}">
        <!-- how can I just use the email I have in my DB instead of input-->
    </div>

    <div>
        <button type="submit">
            Send Password Reset Link
        </button>
    </div>
</form>

I know it must be quite simple, can anyone help me with this novice problem? Keep in mind that everything else about resetting the password is default Laravel solution from the documentation.

Thank you for any kind of help :)

EDIT!!!

when I set it to hidden like:

<input type="hidden" name="email" value="{{ App\User::find(Auth::user()->id)->email }}">

I get an error:

Swift_TransportException in AbstractSmtpTransport.php line 162:
Cannot send message without a sender address

So the form is not posting the email

DarkFeud
  • 181
  • 2
  • 16
  • If you check the generated HTML, is the value of the email input correct? – azeós Nov 24 '15 at 22:56
  • @azeós if I view source, then my email is present yes :) – DarkFeud Nov 24 '15 at 22:58
  • Did you set a `from` address in `config\mail.php`? – azeós Nov 24 '15 at 23:01
  • @azeós after setting the from Expected response code 250 but got code "530", with message "530 5.7.1 Authentication required " – DarkFeud Nov 24 '15 at 23:13
  • [SO question](http://stackoverflow.com/questions/29100877/trying-to-get-laravel-5-email-to-work), if it is a gmail account [Allow less secure apps](https://support.google.com/accounts/answer/6010255?hl=en). – azeós Nov 24 '15 at 23:17
  • 1
    bro, you are adding a database query that you don't need at all, you can get authenticated user's email like you get its id : `Auth::user()->email` and sorry i didn't get what you want to do with the form and the email – teeyo Nov 24 '15 at 23:17
  • alternatively to google, you could use [fakeSMTP](https://nilhcem.github.io/FakeSMTP/), it's less hassle. Just point your `.env` or `/config/mail.php` to localhost. – Bagus Tesa Nov 24 '15 at 23:23
  • 1
    @teeyo you are correct :) – DarkFeud Nov 24 '15 at 23:36
  • @Tezla will try it out – DarkFeud Nov 24 '15 at 23:38
  • @DarkFeud I see that you changed the action attribute in the form, did you change the route accordingly ? `dashboard/password/email` ? – teeyo Nov 24 '15 at 23:44
  • @teeyo I had a typo, changed it to match the route :) – DarkFeud Nov 25 '15 at 11:38
  • @azeós Ive gotten this error: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed and the only solution (https://github.com/PHPMailer/PHPMailer/issues/368) says that I might have server issues? I am using vagrant with homestead locally – DarkFeud Nov 25 '15 at 16:26
  • try to set `encryption=null` in `.env` file or set `\config\mail.php` on line `encryption` to null (or just ensure this one take from `.env` file). **note** this is for development - to make things simple, not for production. – Bagus Tesa Nov 25 '15 at 16:44
  • ps. alternatively you could enable SSL, look at [this stack overflow question](http://stackoverflow.com/questions/25558426/laravel-homestead-ssl-set-up/25761360#25761360). – Bagus Tesa Nov 25 '15 at 16:51
  • @Tezla how would you handle production then? – DarkFeud Nov 25 '15 at 20:35
  • @Tezla might be easier to change the password without the email :D – DarkFeud Nov 25 '15 at 20:44
  • well in production you should never leave password's blank or turning off ssl unless it's not worth to be intercepted midway. @DarkFeud, yes, it might work - use the admin thing, file a request and such. however it'll require the admin to check things out again and again. have you tried fakesmtp (if using the real smtp just too dificult)? – Bagus Tesa Nov 25 '15 at 22:37
  • @Tezla I have not yet tried fakesmtp. Was thinking of changing password directly on the webpage, but do not know how to compare new password and new password confirmed for example.... – DarkFeud Nov 26 '15 at 00:13
  • comparing `new password` with `new password confirmed` as simple as [compare two strings](http://php.net/manual/en/function.strcmp.php). – Bagus Tesa Nov 26 '15 at 00:34
  • @Tezla that is correct, but I am trying to overwrite the existing change password methods in Laravel 5.1 – DarkFeud Nov 26 '15 at 10:55

0 Answers0