Esempio n. 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $dt = Carbon::now('Asia/Colombo');
     $spams = spam::get();
     foreach ($spams as $spam) {
         $dt2 = new Carbon($spam->updated_at, 'Asia/Colombo');
         $val = $dt2->diffInMinutes($dt);
         if ($val > 6) {
             $spam->delete();
         }
     }
     $this->info('spam table cleard!');
 }
Esempio n. 2
0
 /**
  * Take All JSON Post Requset and process them
  *  Tasks
  *	 1. Reset Passwords
  *	 2. Login
  *	 3. Send Emails when Password is resetted
  *
  * @return Response, Views
  **/
 public function inputs()
 {
     $user = user::where('id', Session::get('userid'))->first();
     if (!is_null($user)) {
         return Redirect::to('home');
     }
     if (Request::get('formname') == "reset") {
         /**
          *
          *	Account Recovery
          *
          */
         $email = Request::get('email');
         $user = null;
         if ($this->regex($email, "TP")) {
             $user = user::where('tp', "+94" . $email)->first();
         } elseif ($this->regex($email, "EMAIL")) {
             $user = user::where('email', $email)->first();
         } else {
             return "notfound";
         }
         if (is_null($user)) {
             return "notfound";
         } else {
             $pass = Str::random(10);
             $user->password = md5($pass);
             if ($user->save()) {
                 try {
                     Mail::send('mailtemplate/passwordreset', ['name' => $user->name, 'pass' => $pass], function ($m) use($user) {
                         $m->from('*****@*****.**', 'Daemon');
                         $m->to($user->email, $user->name)->subject('New Password!');
                     });
                 } catch (Exception $e) {
                 }
                 return "ok";
             } else {
                 return "Check the Email Settings or your internet connection";
             }
         }
     } elseif (Request::get('formname') == "loginFrom") {
         /**
          *
          *	User Login
          *
          */
         $keepme = Request::get('keepme');
         $email = Request::get('email_login');
         $password = md5(Request::get('password_login'));
         $user = null;
         $ip = $this->getRealIpAddr();
         $retry = spam::where('ip', '=', $ip)->first();
         if (is_null($retry)) {
             $retry = new spam();
             $retry->ip = $ip;
             $retry->retry = 1;
             $retry->save();
         } else {
             if ($retry->retry > 6) {
                 return view('login')->with('fail', 3);
             } else {
                 $count = $retry->retry;
                 $count++;
                 $retry->retry = $count;
                 $retry->save();
             }
         }
         if ($this->regex($email, "EMAIL")) {
             $user = user::where('email', $email)->where('password', '=', $password)->where('active', '=', 1)->first();
         } elseif ($this->regex($email, "TP")) {
             $user = user::where('tp', "+94" . $email)->where('password', '=', $password)->where('active', '=', 1)->first();
         }
         if (is_null($user)) {
             return view('login')->with('fail', 1)->with('emails', $email);
         } else {
             Session::put('userid', $user->id);
             Session::put('user', $user);
             if ($user->level >= 2) {
                 $doctor = Doctor::where('email', '=', $user->email)->first();
                 if (!is_null($doctor)) {
                     Session::put('doctor', $doctor);
                 }
             }
             if (is_null(Session::get('url'))) {
                 return Redirect::to('home');
             } else {
                 //return Session::get('url');
                 return Redirect::to(Session::get('url'));
                 //die();
             }
         }
     } else {
         return view('login');
     }
     return view('login');
 }