2 votes

Comment réinitialiser le mot de passe manuellement en répondant aux questions de sécurité sans envoyer d'email (Laravel/Vuejs)

Je suis en train de développer une application de librairie simple avec un petit nombre d'utilisateurs pour laquelle l'envoi d'emails n'est pas nécessaire car elle sera implémentée dans le système local. Existe-t-il un moyen de personnaliser laravel-auth pour la fonction de réinitialisation du mot de passe en ajoutant quelques champs de questions de sécurité où l'utilisateur peut réinitialiser son mot de passe sans envoyer de liens de réinitialisation par email.

Toute forme d'aide sera très appréciée.

ici j'ai essayé le code ci-dessous mais id n'a pas fonctionné

Code dans web.php

Route::post('/main/checklogin', 'UserController@chekQuestions');

Code dans userContoller

 public function chekQuestions(Request $request)
    {
          $request->validate( [
         'email'    => 'required|string|email',
         'answerQuestionOne' => 'required|string|confirmed',
         'answerQuestionTwo'    => 'required|string'
      ] );
    $user = User::first();

        if($user->email == $request->email && $user->answerQuestionOne == $request->answerQuestionOne && $user->answerQuestionTwo == $request->answerQuestionTwo )
         {
            // $userEmail = DB::table( 'password_resets' )->where( 'token', $user->token );
            // return view('auth.password.reset',compact($userEmail));
            return view('auth.password.reset');
         }

           return response()->json( [
         'error'   => true,
         'message' => 'We cannot find a user with that Email Address'
      ], 404 );
    }

Code dans reset password.blade

    <div id="register" class="animate form registration_form">
      <section class="login_content">
      <form method="POST" action="{{ url('/main/checklogin') }}" >
                    @csrf
          <h3>            </h3>
          <div class="form-group has-feedback">
            <input id="email" type="email" placeholder=" " class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') }}" required autocomplete="email" autofocus>

                            @error('email')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
            <div class="form-control-feedback">
              <i class="fa fa-envelope-o text-muted"></i>
            </div>
          </div>
        <div>
           <input id="answerQuestionOne" placeholder="  " type="text"   class="form-control @error('answerQuestionOne') is-invalid @enderror" name="answerQuestionOne" value="{{ old('answerQuestionOne') }}" required autocomplete="answerQuestionOne" autofocus>

                            @error('answerQuestionOne')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
        </div>
        <div>
            <input id="answerQuestionTwo" placeholder="   " type="text" class="form-control @error('answerQuestionTwo') is-invalid @enderror" name="answerQuestionTwo" value="{{ old('answerQuestionTwo') }}" required autocomplete="answerQuestionTwo" autofocus>

                            @error('answerQuestionTwo')
                                <span class="invalid-feedback" role="alert">
                                    <strong>{{ $message }}</strong>
                                </span>
                            @enderror
        </div>

          <button type="submit" class="btn btn-default btn-block">  </button>

          <div class="clearfix"></div>
           <div class="separator">
            <p class="change_link">
              <a href="#signin" class="to_register">       </a>
            </p>

            <div class="clearfix"></div>
            <br />
        </form>
      </section>
    </div>

2voto

OmarSafi Points 168

Essayez ceci

Code dans le contrôleur

public function getview(Request $request)
{
    $user=new User();
      $anserone= $request->answerQuestionOne;
      $anstwo = $request->answerQuestionTwo;
      return view('auth.question',compact('user','anserone','anstwo'));
}

public function chekQuestions(Request $request)
{
    $this->validate($request, [
        'email' => 'required|string|email',
        'answerQuestionOne' => 'required',
        'answerQuestionTwo' => 'required'
    ]);

    $user = User::where('email', $request->email)->first();

    if ( $user == null) {
        //
        $user=new User();
        $user->email= $request->email;
        $anserone= $request->answerQuestionOne;
         $anstwo = $request->answerQuestionTwo;
        Session::flash('message', '   ');
        return view('auth.question',compact('user','anserone','anstwo'));

    }
       if ( $user->answerQuestionOne == null || $user->answerQuestionTwo == null) {
        //
        $user=new User();
        $user->email= $request->email;
        $anserone= $request->answerQuestionOne;
         $anstwo = $request->answerQuestionTwo;

        Session::flash('message4', '         ');
        return view('auth.question',compact('user','anserone','anstwo'));

    }
       if ($user->answerQuestionOne != $request->answerQuestionOne) {
            $anserone= $request->answerQuestionOne;
            $anstwo = $request->answerQuestionTwo;
            Session::flash('message2', '    ');
            return view('auth.question',compact('user','anserone','anstwo'));
    }
      if ( $user->answerQuestionTwo != $request->answerQuestionTwo) {
          $anstwo = $request->answerQuestionTwo;
          $anserone= $request->answerQuestionOne;

        Session::flash('message3', '    ');
            return view('auth.question',compact('user','anstwo','anserone'));
    }

    return view('auth.updatePassword',compact('user'));
}
public function updagePassword(Request $request)
{
    $this->validate($request, [
        'email' => 'required|string|email',
        'password' => 'required|min:8'
    ]);
    // $user = User::first();
    $user = User::where('email', $request->email)->first();
    if ( $user == null) {
        //
        $user=new User();
        $user->email= $request->email;
        // $anserone= $request->answerQuestionOne;
        //  $anstwo = $request->answerQuestionTwo;
        Session::flash('message', '   ');
             return view('auth.updatePassword',compact('user'));

    }

     if ($request->password_confirmation != $request->password) {
            Session::flash('message3', '   ');
             return view('auth.updatePassword',compact('user'));
    } 

         $user->where('email', $request->email)->update([
            'password' => Hash::make($request->password)
        ]);
        return redirect()->route('login');

}

**code in updatePassword.blade**

@extends('layouts.header')
 <body class="login">
    <div>
      <a class="hiddenanchor" id="signup"></a>
      <a class="hiddenanchor" id="signin"></a>
      <a class="hiddenanchor" id="reset"></a>

      <div class="login_wrapper">
          <section class="login_content">
          <form method="POST" action="{{route('update.question')}}" >
                        @csrf
             <h3>     </h3>
              <div class="form-group has-feedback">
              <input id="email" type="email" placeholder=" " class="form-control "name="email" value="{{$user->email}}" required autocomplete="email" autofocus>

                                 @if(Session::has('message'))
                           <p  class="bg-danger">{{session('message')}} </p>

                         @endif
                <div class="form-control-feedback">
                  <i class="fa fa-envelope-o text-muted"></i>
                </div>
              </div>

            <div>

                <input id="password" type="password" placeholder=" " class="form-control" name="password" required minlength="8">
                          {{-- <input id="answerQuestionOne" placeholder="   " type="text"   class="form-control" name="answerQuestionOne" value="{{$anserone}}"  required autocomplete="answerQuestionOne" autofocus> --}}
                                 @if(Session::has('message2'))
                           <p  class="bg-danger">{{session('message2')}} </p>

                         @endif
            </div>

            <div>
                <input id="password-confirm" type="password" placeholder="  "  class="form-control" name="password_confirmation"  minlength="4" required >
            {{-- <input id="answerQuestionTwo" placeholder="    " type="text" class="form-control " name="answerQuestionTwo" value="{{$anstwo}}" required autocomplete="answerQuestionTwo" autofocus> --}}
   @if(Session::has('message3'))
                           <p  class="bg-danger">{{session('message3')}} </p>

                         @endif
            </div>

              <button type="submit" class="btn btn-default btn-block">  </button>

              <div class="clearfix"></div>
               <div class="separator">
                {{-- <p class="change_link">
                  <a href="#signin" class="to_register">       </a>
                </p> --}}

                <div class="clearfix"></div>
                <br />
            </form>
          </section>
        </div>
        {{-- reset password via email --}}

      {{-- </div> --}}
    </div>
  </body>
</html>

**Code in question.blade**

@extends('layouts.header')
 <body class="login">
    <div>
      <a class="hiddenanchor" id="signup"></a>
      <a class="hiddenanchor" id="signin"></a>
      <a class="hiddenanchor" id="reset"></a>

      <div class="login_wrapper">
          <section class="login_content">
          <form method="POST" action="{{route('check.question')}}" >
                        @csrf
              <h3>            </h3>
    <div>    @if(Session::has('message4'))
                           <h4  class="bg-danger">{{session('message4')}} </h4>

                         @endif</div>
              <div class="form-group has-feedback">
              <input id="email" type="email" placeholder=" " class="form-control "name="email" value="{{$user->email}}" required autocomplete="email" autofocus>

                                 @if(Session::has('message'))
                           <p  class="bg-danger">{{session('message')}} </p>

                         @endif
                <div class="form-control-feedback">
                  <i class="fa fa-envelope-o text-muted"></i>
                </div>
              </div>
              <div>
                  <select 

                    style="margin-bottom:20px;width: 100%;padding: 7px; "
                  >
                    <option value selected>      </option>
                    <option>     </option>
                    <option>      </option>
                    <option>     </option>
                    <option>        </option>
                    <option>    </option>
                    <option>       </option>
                  </select>

              </div>
            <div>

                          <input id="answerQuestionOne" placeholder="   " type="text"   class="form-control" name="answerQuestionOne" value="{{$anserone}}"  required autocomplete="answerQuestionOne" autofocus>
                                 @if(Session::has('message2'))
                           <p  class="bg-danger">{{session('message2')}} </p>

                         @endif
            </div>
             <div>
                  <select  style="margin-bottom:20px;width: 100%;padding: 7px; ">
                    <option value selected>      </option>
                    <option>     </option>
                    <option>      </option>
                    <option>     </option>
                    <option>        </option>
                    <option>    </option>
                    <option>       </option>
                  </select>

              </div>
            <div>
            <input id="answerQuestionTwo" placeholder="    " type="text" class="form-control " name="answerQuestionTwo" value="{{$anstwo}}" required autocomplete="answerQuestionTwo" autofocus>
   @if(Session::has('message3'))
                           <p  class="bg-danger">{{session('message3')}} </p>

                         @endif
            </div>

              <button type="submit" class="btn btn-default btn-block">  </button>

              <div class="clearfix"></div>
               <div class="separator">
                {{-- <p class="change_link">
                  <a href="#signin" class="to_register">       </a>
                </p> --}}

                <div class="clearfix"></div>
                <br />
            </form>
          </section>
        </div>
        {{-- reset password via email --}}

      {{-- </div> --}}
    </div>
  </body>
</html>

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X