Как сбросить пароль вручную, ответив на секретные вопросы, не отправляя электронное письмо (Laravel / Vuejs) - PullRequest
2 голосов
/ 23 марта 2020

В настоящее время я занимаюсь разработкой простого приложения Bookstore с несколькими пользователями, для которого отправка электронных писем не требуется, поскольку оно будет реализовано в локальной системе, поэтому есть ли способ настроить laravel -auth для функции сброса пароля с помощью добавив несколько полей с вопросами безопасности, где пользователь может сбросить свой пароль без отправки ссылок для сброса по электронной почте.

Любая помощь будет высоко оценена.

здесь я попробовал приведенный ниже код, но идентификатор не работает

Код в сети. php

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

Код в 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 );
    }

Код при сбросе пароля. Блейд

    <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>

1 Ответ

2 голосов
/ 26 апреля 2020

Попробуйте это

Код в контроллере

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>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...