public static function addNew($text = '', $attachment = null) { $alert = new Alert(); $alert->text = $text; if (is_object($attachment)) { $alert->alertable_id = $attachment->id; $alert->alertable_type = get_class($attachment); } $alert->save(); return $alert; }
public function fetch($range) { $days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']; $startTime = Carbon::now('America/Los_Angeles'); $dayOfWeek = $startTime->dayOfWeek; $midnightThisMorning = Carbon::today('America/Los_Angeles'); $startTimeString = $startTime->toTimeString(); $endTimeString = $startTime->addMinutes($range)->toTimeString(); $alerts = Alert::whereBetween('alert_time', [$startTimeString, $endTimeString])->where($days[$dayOfWeek], 1)->whereNotBetween('last_sent', [$midnightThisMorning, $startTimeString])->orderBy('alert_time', 'asc')->get(); return $alerts; }
/** * Execute the console command. * * @return mixed */ public function handle() { $email = $this->argument('email'); $stop = $this->argument('stop'); $route = $this->argument('route'); $departure_time = $this->argument('departure_time'); $time_to_stop = $this->argument('time_to_stop'); $lead_time = $this->argument('lead_time'); $timezone = $this->argument('timezone'); $alert = new Alert(); $alert->email = $email; $alert->stop = $stop; $alert->route = $route; $alert->departure_time = $departure_time; $alert->time_to_stop = $time_to_stop; $alert->lead_time = $lead_time; $alert->timezone = $timezone; $alert->save(); $this->info('Alert created!'); }
/** * Execute the console command. * * @return mixed */ public function handle() { /* curl -u YOUR_SECRET_KEY: -H "Content-Type: application/json" -H "X-Ionic-Application-Id: YOUR_APP_ID" https://push.ionic.io/api/v1/push -d '{"tokens": ["YOUR_TOKEN"],"notification":{"alert":"Hello world."}}' */ $numbers = ContactRequest::all()->pluck('phone'); $alert = Alert::Create(['message' => $this->argument('message')]); /*$tokens = DeviceToken::all('token')->pluck('token'); \Log::info('Tokens', $tokens->toArray()); $fields = array ( "tokens"=> $tokens, "notification" => [ 'alert' => $this->argument('message')] ); $headers = array ( 'X-Ionic-Application-Id: 35509efc', 'Content-Type: application/json' ); $username='******'; $ch = curl_init(); curl_setopt( $ch,CURLOPT_URL, 'https://push.ionic.io/api/v1/push' ); curl_setopt( $ch,CURLOPT_POST, true ); curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers ); curl_setopt($ch, CURLOPT_USERPWD, "$username"); curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false ); curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) ); $result = curl_exec($ch ); curl_close( $ch ); echo $result;*/ foreach ($numbers as $number) { try { Mail::raw($this->argument('message'), function ($message) use($number) { $message->from('*****@*****.**'); $message->to($number); $message->subject('New Info!'); }); } catch (Exception $e) { break; } } }
public function changePassword(Request $request) { Validator::extend('password_check', function ($attribute, $value, $parameters) { return Hash::check($value, Auth::user()->getAuthPassword()); }); $validator = Validator::make($request->all(), ['current_password' => 'required|password_check', 'password' => 'required|min:6|confirmed'], ['password_check' => Lang::get('app.incorrect_current_password')]); if ($validator->fails()) { return redirect()->action('UserController@getChangePasswordView')->withErrors($validator)->withInput(); } $user_id = Auth::user()->id; $user = User::find($user_id); $user->password = Hash::make($request->input('password')); if ($user->save()) { Alert::setSuccessAlert(Lang::get('app.password_change')); } else { Alert::setErrorAlert(Lang::get('app.unknown_error')); } return redirect()->action('UserController@account'); }
/** * Display the specified resource. * * @param int $id * @return Response */ public function show($id) { // setlocale(LC_TIME, 'es_ES'); $user = Sentinel::getUser(); $task = Task::find($id); $alerts = Alert::where('task_id', '=', $id)->first(); if (empty($alerts->alert_display)) { $array_read[] = $user->id; $alerts->alert_display = serialize($array_read); $alerts->save(); } else { $array_read = unserialize($alerts->alert_display); if (!in_array($user->id, $array_read)) { array_push($array_read, $user->id); $alerts->alert_display = serialize($array_read); $alerts->save(); } } return view('notifications.alerts.show', compact('task')); }
/** * Execute the console command. * * @return mixed */ public function handle() { $tasks = \App\Task::where(['active' => 0])->get(); $now = \Carbon\Carbon::now(); foreach ($tasks as $task) { $nodestat = \App\Nodestat::where('node_id', $task->node_id)->first(); if (isset($nodestat)) { if ($nodestat->isonline == 1) { if (!empty($task->offlinesince)) { $task->offlinesince = null; } } else { if (empty($task->offlinesince)) { $task->offlinesince = $now; } $checkdate = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $task->offlinesince); $intervall = \Carbon\Carbon::createFromFormat('Y-m-d H:i:s', $task->intervall); $checkdate->addHours($intervall->hour)->addMinutes($intervall->minute); if ($checkdate->lte($now)) { // wenn letzter alarm und lastrun identisch, war node bisher nichtmehr online => next task if ($task->lastalert != null && $task->lastrun == $task->lastalert) { continue; } $user = \App\User::findOrFail($task->user_id); Mail::send('emails.alarm', ['user' => $user, 'task' => $task], function ($m) use($user, $task) { $m->to($user->email, $user->name)->subject($task->node->name . ' is Offline!'); }); if ($task->smsalarm == 0 && !empty($user->mobilenumber)) { //TODO: write sms } \App\Alert::insert(['task_id' => $task->id]); $task->lastalert = $now; } } $task->lastrun = $now; $task->save(); } } }
public function createContactMessage(Request $request) { $this->validate($request, ['email' => 'email|max:40', 'text' => 'required|max:100000|min:2', 'category_id' => 'required|numeric']); $email = $request->input('email'); $text = $request->input('text'); $category_id = $request->input('category_id'); $category = ContactMessagesCategory::where('id', $category_id)->first(); if (!$category) { abort(406); } $message = new ContactMessage(); $message->email = !empty($email) ? $email : NULL; $message->text = $text; $message->category_id = $category_id; $pass = $message->save(); if ($pass) { Alert::setSuccessAlert('Your message was send.'); } else { Alert::setErrorAlert('Error ' . __METHOD__); } return redirect()->action('HomeController@index'); }
<?php use App\Events\UserHasRegistered; use App\Alert; // Landing Page for pre-release Route::get('/', ['as' => 'landing.optin', 'uses' => 'LandingController@create']); Route::post('/', ['as' => 'landing.confirm', 'uses' => 'LandingController@store']); Route::get('/home', function () { return view('home'); }); Route::resource('alerts', 'AlertController', ['names' => ['create' => 'alerts.new']]); Route::get('admin', ['as' => 'admin', 'middleware' => 'auth', function () { $alerts = Alert::all(); return view('alerts.index')->with('alerts', $alerts); // return "Admin Panel"; }]); // Alert endpoint to ping for sending Route::get(env('ALERT_SEND_ENDPOINT'), function () { $handler = new App\AlertHandler(new App\Curl()); $handler->sendAlertEmails(env('ALERT_FETCH_RANGE')); }); // Authentication routes... Route::get('auth/login', 'Auth\\AuthController@getLogin'); Route::post('auth/login', 'Auth\\AuthController@postLogin'); Route::get('auth/logout', 'Auth\\AuthController@getLogout'); // Social Authentication... Route::get('auth/facebook', 'Auth\\AuthController@redirectToProvider'); Route::get('auth/facebook/callback', 'Auth\\AuthController@handleProviderCallback'); // Registration routes... Route::get('auth/register', 'Auth\\AuthController@getRegister'); Route::post('auth/register', 'Auth\\AuthController@postRegister');
public function addAlertToPatient(Request $request) { $patient = Patient::findOrFail($request->input('patient_id')); Alert::addNew($request->input('text'), $patient); return redirect()->back()->with('alert-added', true); }
public function delete(Request $request) { $this->validate($request, ['task_id' => 'required|numeric']); $task_id = $request->input('task_id'); $task = Task::where('id', $task_id)->where('deleted', false)->where('user_id', Auth::user()->id)->first(); if (!$task) { abort(404); } $task->deleted = true; $pass = $task->save(); $this->clearCache($task); if ($pass) { Alert::setSuccessAlert(Lang::get('app.deleted_task')); } else { Log::alert(__METHOD__ . '(' . __FILE__ . ')', array('task_id' => $task->id, 'user_id' => Auth::user()->id)); Alert::setErrorAlert(Lang::get('app.unknown_error')); } Statistic::SubTask(); return redirect()->action('UserController@tasks'); }
} else { $items[] = ['label' => Yii::t('app', 'Payment'), 'url' => Yii::$app->user->identity->isManager() ? ['/invoice/index'] : ['/invoice/index', 'user' => Yii::$app->user->identity->name]]; $items[] = ['label' => Yii::t('app', 'Profile'), 'url' => ['/user/view', 'name' => Yii::$app->user->identity->name]]; $items[] = ['label' => Yii::t('app', 'Logout') . ' (' . Yii::$app->user->identity->name . ')', 'url' => ['/user/logout'], 'linkOptions' => ['data-method' => 'post']]; } echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right'], 'items' => $items]); NavBar::end(); ?> <div class="container"> <?php echo Breadcrumbs::widget(['homeLink' => false, 'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : []]); ?> <?php echo Alert::widget(); ?> <?php echo $content; ?> </div> </div> <!--footer class="footer"> <div class="container"> <p class="pull-left">© My Company <?php echo date('Y'); ?> </p> <p class="pull-right"><?php echo Yii::powered();
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { \App\Alert::where(['task_id' => $id])->delete(); \App\Task::find($id)->delete(); return $this->index(); }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $alerts = \App\Alert::join('tasks', 'tasks.id', '=', 'alerts.task_id')->where('tasks.user_id', \Auth::user()->id)->with('node')->orderBy('alerts.created_at', 'desc')->get(); return view('alert/index')->with('alerts', $alerts); }
public function destroy(Alert $alert) { return response()->json(['deleted' => $alert->delete()]); }
public function complete($id) { $user = Sentinel::getUser(); $task = Task::find($id); $now = Carbon::now(); $task->user_complete_id = $user->id; $task->time_complete = $now; if ($task->save()) { // Ponemos alertas leidas, para que no aparescan cuando ya se completo una tarea $alerts = Alert::where('task_id', '=', $id)->first(); if (empty($alerts->alert_display)) { $array_read[] = $user->id; } else { $array_read = unserialize($alerts->alert_display); if (!in_array($user->id, $array_read)) { array_push($array_read, $user->id); } } $alerts->alert_display = serialize($array_read); $alerts->save(); return Redirect::to('tasks/tasks')->withSuccess('Tarea Completada'); } }
/** * @Given an alert is due now */ public function anAlertIsDueNow() { $timezone = 'America/Los_Angeles'; $now = Carbon::now($timezone); $soon = $now->addMinutes(1); $yesterday = Carbon::yesterday(); $user = factory('App\\User')->create(); $alert = new Alert(); $alert->user_id = $user->id; $alert->email = '*****@*****.**'; $alert->stop = 5020; $alert->route = 15; $alert->departure_time = $soon; $alert->time_to_stop = 0; $alert->lead_time = 0; $alert->alert_time = $soon; $alert->last_sent = $yesterday; $alert->timezone = $timezone; $alert->monday = 1; $alert->tuesday = 1; $alert->wednesday = 1; $alert->thursday = 1; $alert->friday = 0; $alert->saturday = 0; $alert->sunday = 0; //add days of week for god's sake $alert->save(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $alert = Alert::findOrFail($id)->delete(); return Redirect::route('alerts.index')->withMessage('Your alert was deleted.'); }