public function sendResetLinkEmail(Request $request)
 {
     $this->validate($request, ['email' => 'required|email|exists:users,email']);
     $email = $request->input('email');
     $user = User::where('email', $email)->first();
     $user->status = 'new';
     $user->save();
     $activator = AccountActivation::create(['delivered_to' => $email, 'active' => true, 'destination' => 'email', 'source' => 'forgot']);
     $activator->renew();
     $activator->send();
     return redirect(url('/code/verify'));
 }
 public function store(RegisterUserRequest $request)
 {
     $user = User::where('email', $request->input('email'))->first();
     if ($user == null) {
         $user = User::create($request->all());
         $user->status = 'new';
         $user->password = bcrypt('sample');
         $user->save();
         $activator = AccountActivation::create(['delivered_to' => $user->email, 'active' => true, 'destination' => 'email', 'source' => 'admin']);
         $activator->renew();
         $activator->send();
     }
     return redirect(url('/super/admin/all'));
 }
 public function resetFirstTimePassword(Request $request)
 {
     $this->validate($request, ['password' => 'confirmed|min:6|same:password_confirmation']);
     $token = $request->input('token');
     $email = $request->input('email');
     $activator = AccountActivation::where('code', $token)->valid()->for($email)->latest();
     if (!isset($activator)) {
         return redirect('/');
     }
     $user = User::where('email', $email)->first();
     $user->password = bcrypt($request->input('password'));
     $user->status = 'active';
     $user->save();
     $activator->deactivate();
     if (Auth::attempt(['email' => $user->email, 'password' => $request->input('password')])) {
         return redirect(url('/home'));
     } else {
         return redirect(url('/auth/login'));
     }
 }
 public function verifyToken($token)
 {
     $activator = AccountActivation::where('code', $token)->valid()->first();
     if (isset($activator)) {
         $dest = $activator->delivered_to;
         if ($activator->destination == 'email') {
             $user = User::where('email', $dest)->first();
         } else {
             $user = User::where('phone', $dest)->first();
         }
         if (isset($user)) {
             //$activator->deactivate();
             return view('auth.passwords.firstTimePassword', compact('dest', 'token'));
         } else {
             if ($activator->destination == 'email') {
                 return redirect(url('register'))->withInput(['email' => $dest]);
             } else {
                 return redirect(url('register'))->withInput(['phone' => $dest]);
             }
         }
     } else {
         return redirect(url('/'));
     }
 }