示例#1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //
     $tasks = smslimit::all();
     foreach ($tasks as $task) {
         $task->delete();
     }
     $this->info('Smslimit table cleard!');
 }
示例#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 = Session::get('user');
     if (is_null($user) || $user->verified == 1) {
         return response()->json(['message' => 'Missmatch Data', 'code' => 'error']);
     }
     if (Request::get('task') == "sendEmail") {
         /**
          *
          *	Send the Email including the activation code
          *
          */
         $email = Request::get('email');
         if (is_null($email) || trim($email) == "" || !preg_match("/^([a-zA-Z0-9_.+-])+\\@(([a-zA-Z0-9-])+\\.)+([a-zA-Z0-9]{2,4})+\$/", $email)) {
             return response()->json(['message' => 'Missmatch Data', 'code' => 'error', 'task' => 'sendEmail']);
         }
         if ($user->email != $email) {
             $checkUser = user::where('email', $email)->count();
             if ($checkUser == 0) {
                 $user->email = $email;
             } else {
                 return response()->json(['message' => 'Email already Registerd', 'code' => 'error', 'task' => 'sendEmail']);
             }
         }
         Mail::send('mailtemplate/emailVerify', ['name' => $user->name, 'code' => Session::get('emailKey')], function ($m) use($user) {
             $m->from('*****@*****.**', 'Native Physician');
             $m->to($user->email, $user->name)->subject('Confirmation Code');
         });
         $user->save();
         Session::put('user', $user);
         return response()->json(['message' => 'Ok', 'code' => 'success', 'task' => 'sendEmail', 'email' => $email]);
     } elseif (Request::get('task') == "sendPhone") {
         /**
          *
          *	Send the MMS including the activation code
          *
          */
         $smsLimit = smslimit::where('uid', '=', Session::get('userid'))->first();
         if (is_null($smsLimit)) {
             $smsLimit = new smslimit();
             $smsLimit->uid = Session::get('userid');
             $smsLimit->count = 1;
             $smsLimit->save();
         } else {
             if ($smsLimit->count >= 2) {
                 return response()->json(['message' => 'you can only sent 2 SMS within a Day', 'code' => 'error', 'task' => 'sendPhone']);
             } else {
                 $smsCount = $smsLimit->count;
                 $smsCount++;
                 $smsLimit->count = $smsCount;
                 $smsLimit->save();
             }
         }
         $phone = Request::get('phone');
         if (is_null($phone) || trim($phone) == "" || !preg_match("/^[0-9]{9}\$/", $phone)) {
             return response()->json(['message' => 'Check your Phone number', 'code' => 'error', 'task' => 'sendPhone']);
         }
         $phone = "+94" . $phone;
         if ($user->tp != trim($phone)) {
             $checkUser = user::where('tp', $phone)->count();
             if ($checkUser == 0) {
                 $user->tp = trim($phone);
             } else {
                 return response()->json(['message' => 'phone already Registerd', 'code' => 'error', 'task' => 'sendPhone']);
             }
         }
         $code = Session::get('phoneKey');
         if (is_null($code)) {
             return response()->json(['message' => 'Refresh the page', 'code' => 'error', 'task' => 'sendPhone']);
         }
         $user->save();
         Session::put('user', $user);
         SMS::queue('Your Confirmation Code is: ' . $code, [], function ($sms) use($phone) {
             $sms->to($phone);
         });
         //$this->sendsms('Your Confirmation Code is: '.$code,$phone);
         /*
         Mail::send('mailtemplate/emailVerify', ['name'=> $user->name,'code'=>Session::get('phoneKey')], function ($m) use ($user,$phone,$code) {
         	$m->from('*****@*****.**', 'Your Application');
         
         	$m->to($phone."@mms.dialog.lk", $user->name)->subject($code);
         });
         */
         return response()->json(['message' => 'Ok', 'code' => 'success', 'task' => 'sendPhone', 'phone' => $phone]);
     } elseif (Request::get('task') == "verify") {
         /**
          *
          *	Finalized the registration by comparing activation codes
          *
          */
         $codePhone = Request::get('codePhone');
         //$codeEmail=Request::get('codeEmail');
         if (!is_null($codePhone) && Session::get('phoneKey') == $codePhone) {
             //if( Session::get('phoneKey')==$codePhone && Session::get('emailKey')==$codeEmail  ){
             $user->verified = 1;
             $user->save();
             Session::flush();
             return response()->json(['message' => 'Ok', 'code' => 'success', 'task' => 'verify']);
         } else {
             return response()->json(['message' => 'Codes Missmatch', 'code' => 'error', 'task' => 'verify']);
         }
     }
 }