Example #1
0
 public function upvote($id, Request $request)
 {
     //upvote reply
     $reply = Reply::find($id);
     //notify commenter
     if (Auth::check()) {
         App('App\\Notification')->notify('reply_upvote', Auth::user(), $reply->user, $reply->article, $reply);
         if ($reply->votes()->ByWhom(Auth::id())->count()) {
             // click twice for remove upvote
             $reply->votes()->ByWhom(Auth::id())->delete();
             $reply->decrement('vote_count', 1);
             $reply->article()->decrement('vote_count', 1);
         } else {
             // first time click
             $reply->votes()->create(['user_id' => Auth::id()]);
             $reply->increment('vote_count', 1);
             $reply->article()->increment('vote_count', 1);
         }
     } else {
         //匿名投票
         App('App\\Notification')->nonamenotify('reply_upvote', $reply->user, $reply->article, $reply);
         if ($reply->votes()->ByWhom($request->ip())->count()) {
             $reply->votes()->ByWhom($request->ip())->delete();
             $reply->decrement('vote_count', 1);
         } else {
             $reply->votes()->create(['user_id' => $request->ip()]);
             $reply->increment('vote_count', 1);
         }
     }
     return $reply->vote_count;
 }
Example #2
0
 public function postVote(Request $request, $id)
 {
     $vote = Vote::find($id);
     if (!$vote->is_active) {
         return redirect('/');
     } else {
         $voted = Voter::where('vote_id', '=', $id)->where('ip', '=', sprintf('%u', ip2long($request->ip())))->count();
         if ($voted) {
             return redirect('auth/logout');
         }
     }
     $inputs = $request->all();
     $voter = new Voter();
     $voter->ip = $request->ip();
     $voter->name = trim($inputs['name']);
     $voter->department = trim($inputs['department']);
     $voter->mobile = str_replace(' ', '', $inputs['mobile']);
     $voter->type_id = $inputs['type'];
     $voter->vote_id = $id;
     if ($voter->save()) {
         Voter::find($voter->id)->nominations()->sync($inputs['vote']);
         return redirect('vote/statistics/' . $id)->with('status', '投票保存成功');
     } else {
         return back()->withErrors('投票保存失败');
     }
 }
 public function login(Request $request, Manager $fractal, UserTransformer $userTransformer)
 {
     $validator = \Validator::make($request->all(), ['username' => 'required', 'password' => 'required'], ['required' => 'no-:attribute-provided']);
     if ($validator->fails()) {
         $errors = [];
         foreach ($validator->errors()->all() as $error) {
             $errors[] = $error;
         }
         return $this->setStatusCode(400)->respond(['errors' => $errors]);
     }
     $ipCheck = Login::where(['ip' => $request->ip(), 'valid' => false])->where('time', '>', date('Y-m-d H:i:s', time() - 60 * 60 * 24))->get();
     if (count($ipCheck) > 15) {
         Login::create(['time' => date('Y-m-d H:i:s'), 'ip' => $request->ip(), 'valid' => false]);
         return $this->setStatusCode(403)->respond(['errors' => ['ip-banned']]);
     }
     $user = User::where(['username' => $request->get('username')])->orWhere(['email' => $request->get('username')])->first();
     if (is_null($user)) {
         return $this->setStatusCode(404)->respond(['errors' => ['user-not-found']]);
     }
     $userCheck = Login::where(['user_id' => $user->id, 'valid' => false])->where('time', '>', time() - 60 * 15)->get();
     if (count($userCheck) > 15) {
         return $this->setStatusCode(403)->respond(['errors' => ['user-locked']]);
     }
     if (!\Hash::check($request->get('password'), $user->password)) {
         Login::create(['time' => date('Y-m-d H:i:s'), 'ip' => $request->ip(), 'user_id' => $user->id, 'valid' => false]);
         return $this->setStatusCode(403)->respond(['errors' => ['invalid-password']]);
     }
     $user->session = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
     $user->session_expire_time = date('Y-m-d H:i:s', time() + 60 * 60);
     $user->update();
     Login::create(['time' => date('Y-m-d H:i:s'), 'ip' => $request->ip(), 'user_id' => $user->id, 'valid' => true]);
     $item = new Item($user, $userTransformer);
     $data = $fractal->setSerializer(new ArraySerializer())->createData($item)->toArray();
     return $this->respond($data);
 }
Example #4
0
 public function Post(Request $request)
 {
     $recaptcha = new \ReCaptcha\ReCaptcha('6LfWHfkSAAAAAMj0Kkhn1FJV6y-RiSZ_M9rasufn');
     $resp = $recaptcha->verify($request->input('g-recaptcha-response'), $request->ip());
     $msgValidation = trim(strip_tags(str_replace(" ", ' ', $request->input('message'))));
     $username = trim(strip_tags(str_replace(" ", ' ', $request->input('name'))));
     $errors = [];
     if (!Auth::check() && strlen($username) < 3) {
         array_push($errors, 'Veuillez saisir un nom d\'utilisateur d\'au moins 3 caractères svp !');
     }
     if (strlen($msgValidation) == 0) {
         array_push($errors, 'Le message est obligatoire !');
     }
     if (!$resp->isSuccess()) {
         array_push($errors, 'Veuillez renseigner le captcha svp !');
     }
     if (count($errors) == 0) {
         $msg = new Message();
         if (Auth::check()) {
             $msg->author_id = $request->user()->id;
         } else {
             $msg->username = $username;
         }
         $msg->message = $msgValidation;
         $msg->remote_addr = $request->ip();
         $msg->save();
         return redirect()->route('minichat');
     }
     Session::flash('errors', $errors);
     return redirect()->route('minichat')->withInput();
 }
Example #5
0
 public function rate(Request $request, $id)
 {
     $Quote = Quote::withCount(['ratesPlus', 'ratesMinus'])->find($id);
     if (null == $Quote) {
         return response()->json(['status' => 'error', 'message' => trans('app.not_found')]);
     }
     $count = $Quote->rates_plus_count - $Quote->rates_minus_count;
     $voted = $request->cookie(sha1('voted'));
     $voted = null == $voted ? [] : json_decode($voted);
     if (!empty($voted)) {
         if (in_array($id, $voted)) {
             return response()->json(['status' => 'error', 'message' => trans('app.twice_vote'), 'rate' => $count])->cookie(sha1('voted'), json_encode($voted), 60 * 60 * 24 * 120);
         }
     }
     $voted[] = $id;
     $Rate = Rate::where('quote_id', $id)->where('ip', $request->ip())->first();
     if (null != $Rate) {
         return response()->json(['status' => 'error', 'message' => trans('app.twice_vote'), 'rate' => $count])->cookie(sha1('voted'), json_encode($voted), 60 * 60 * 24 * 120);
     }
     $rate = 1 == strpos($request->getPathInfo(), 'omg') ? 1 : (1 == strpos($request->getPathInfo(), 'wtf') ? -1 : 0);
     $Rate = new Rate();
     $Rate->quote_id = $id;
     $Rate->ip = $request->ip();
     $Rate->rate = $rate;
     $Rate->save();
     $Quote->count += $rate;
     $Quote->save();
     return response()->json(['status' => 'ok', 'message' => trans('app.voted'), 'rate' => $count + $rate])->cookie(sha1('voted'), json_encode($voted), 60 * 60 * 24 * 120);
 }
 public function getLoginGoogle(Request $request)
 {
     # GET OAUTH DATA
     $oauth = Socialite::driver('google')->user();
     # GET USER
     $user = User::where('email', $oauth->email)->first();
     # LOGIN OR KICK
     if ($user) {
         // # RECORD LOGIN
         $log = new LogLogin();
         $log->user_id = $user->id;
         $log->email = $oauth->email;
         $log->ip = $request->ip();
         $log->result = 'successful';
         $log->save();
         Auth::login($user);
         return redirect()->action('\\Skydiver\\RapydDashboard\\Controllers\\DashboardController@getIndex');
     } else {
         // # RECORD LOGIN
         $log = new LogLogin();
         $log->email = $oauth->email;
         $log->ip = $request->ip();
         $log->result = 'failed';
         $log->save();
         Session::flash('message', array('type' => 'danger', 'msg' => 'No user found.<br>Attempt has been recorded.'));
         return redirect()->action('\\Skydiver\\RapydDashboard\\Controllers\\OAuthController@getSSOLogin');
     }
 }
Example #7
0
 public function start(Request $request)
 {
     if ($request->ajax()) {
         //get ip and store info
         $winner = Winner::where('user_id', '=', $request->ip())->first();
         if (!empty($winner)) {
             $result = ['msg' => '您已经抢过了,不能再抢了哦~', 'cdkey' => $winner->cdkey, 'status' => '2'];
         } else {
             $join = Join::create(['ip' => $request->ip()]);
             //get kucun
             if ($join->id) {
                 $award = Award::find($request->input('event_id'));
                 $result = ['msg' => '恭喜!您抢到了', 'cdkey' => $request->input('event_id'), 'status' => '1'];
                 if ($award->surplus <= 0) {
                     $result = ['msg' => '很遗憾,被抢光了!', 'status' => '0'];
                 } else {
                     //库存-1
                     $award->surplus = $award->surplus - 1;
                     $award->save();
                     //生成cdkey
                     $cdkey = $this->generateCdkey(5);
                     //
                     //保存中奖用户
                     $winner = Winner::create(['user_id' => $request->ip(), 'award_id' => $request->input('award_id'), 'cdkey' => $cdkey, 'event_id' => $request->input('event_id')]);
                     $result = ['msg' => '恭喜!您抢到了', 'cdkey' => $cdkey, 'status' => '1'];
                 }
             }
         }
     }
     return response()->json($result);
 }
Example #8
0
 public function giveCookie(Request $request, $cookieID)
 {
     $cookieObj = ChCookie::find($cookieID);
     $infoArr = ["cookie_id" => $cookieObj->id, "first_login_ip" => $request->ip(), "last_login_ip" => $request->ip(), "ban_level" => 0, "admin_flag" => 0];
     User::create($infoArr);
     $cookieObj->state = 1;
     $cookieObj->save();
 }
Example #9
0
 public function log($message)
 {
     // if the even is system generated, then add 0 as user id
     // and mark it system event
     if (Auth::guest()) {
         $userId = 1;
         $message = 'System event: ' . $message;
     } else {
         $userId = Auth::user()->id;
     }
     $this->activity->log(['description' => $message, 'user_id' => $userId, 'ip_address' => $this->request->ip(), 'user_agent' => $this->getUserAgent()]);
 }
Example #10
0
 public function store(Request $request)
 {
     if ($request->ajax()) {
         parse_str($request->data, $input);
     } else {
         $input = $request->all();
     }
     $rules = ['fullname' => 'required|farsi|min:3|max:150', 'email' => 'required|email|min:5|max:150', 'tel' => 'required|digits_between:8,15', 'des' => 'required|min:10|max:500'];
     $validator = Validator::make($input, $rules);
     if ($validator->fails()) {
         if ($request->ajax()) {
             return response()->json(['result' => 'error', 'errors' => $validator->errors()]);
         } else {
             return back()->withInput()->withErrors($validator);
         }
     } else {
         $supportticket = Support::where('ip', $request->ip())->whereRaw('UTC_TIMESTAMP() <= TIMESTAMP(created_at + INTERVAL ' . config('app.support_throttle') . ')')->count();
         if ($supportticket > 0) {
             if ($request->ajax()) {
                 return response()->json(['result' => 'wait']);
             } else {
                 return redirect()->home()->with('fail', 'شما لحظاتی پیش یک پیام با موفقیت ارسال کرده اید، لطفا بعدا تلاش کنید.');
             }
         } else {
             # Create Support
             $support = new Support();
             $support->fullname = $input['fullname'];
             $support->email = $input['email'];
             $support->tel = $input['tel'];
             $support->description = $input['des'];
             $support->ip = $request->ip();
             # Redirect on Success
             if ($support->save()) {
                 Mail::send('emails.support', ['support' => $support], function ($message) use($support) {
                     $message->from(config('app.info_email'), 'کامت');
                     $message->sender(config('app.info_email'), 'کامت');
                     $message->to($support->email, $support->fullname)->subject('گروه طراحی و توسعه کامت');
                     $message->replyTo(config('app.support_email'), 'کامت');
                 });
                 if ($request->ajax()) {
                     return response()->json(['result' => 'success']);
                 } else {
                     return redirect()->home()->with('success', 'پیام شما با موفقیت ثبت شد.');
                 }
             }
         }
     }
     if ($request->ajax()) {
         return response()->json(['result' => 'fail']);
     } else {
         return back()->withInput()->with('fail', 'مشکل در اتصال به سرور. لطفا مجددا تلاش کنید.');
     }
 }
Example #11
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request        	
  * @param \Closure $next        	
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $ignore = ['222.20.35.168', '127.0.0.1'];
     if (array_search($request->ip(), $ignore) === false) {
         $ip = $request->ip();
         $path = $request->path();
         $view = new View();
         $view->ip = $ip;
         $view->url = $path;
         $view->location = GeoipParser::parse($ip);
         $view->save();
     }
     return $next($request);
 }
 public function store(Request $request)
 {
     $user = $request->all();
     $companyId = Auth::user()->company_id;
     $cn = \App\Company::where('id', '=', $companyId)->first();
     if (!empty($request->input('email'))) {
         $referee = new References();
         $referee->company_id = Auth::user()->company_id;
         $referee->code = str_random(40);
         $referee->first_name = $request->input('first_name');
         $referee->last_name = $request->input('surname');
         $referee->referee_name = $request->input('name');
         $referee->referee_company = $request->input('company_name');
         $referee->referee_email = $request->input('email');
         $referee->reference_only = '1';
         //$referee->re_employ = $request->input('re_employ');
         $referee->ip_address = $request->ip();
         $referee->referee_contact = $request->input('contact');
         $referee->save();
         $data = array('email' => $request->input('email'), 'name' => $request->input('name'), 'worker' => $request->input('first_name') . ' ' . $request->input('surname'), 'company' => $cn->name, 'code' => $referee->code);
         // Send the email
         Mail::send('emails/references/request', $data, function ($message) use($data) {
             $message->to($data['email'])->from('noreply@madesimpleapp.co.uk')->subject('You have been selected to provide a reference');
         });
     }
     if (!empty($request->input('email2'))) {
         $refereetwo = new References();
         $refereetwo->company_id = Auth::user()->company_id;
         $refereetwo->first_name = $request->input('first_name');
         $refereetwo->last_name = $request->input('surname');
         $refereetwo->code = str_random(40);
         $refereetwo->referee_name = $request->input('name2');
         $refereetwo->referee_company = $request->input('company_name2');
         $refereetwo->referee_email = $request->input('email2');
         $refereetwo->referee_contact2 = $request->input('contact2');
         $refereetwo->completedtwo = 'No';
         $refereetwo->reference_only = '1';
         $refereetwo->ip_address = $request->ip();
         $refereetwo->save();
         $data = array('emailtwo' => $request->input('email2'), 'name' => $request->input('name2'), 'worker' => $request->input('first_name') . ' ' . $request->input('surname'), 'company' => $cn->name, 'code' => $refereetwo->code);
         // Send the email
         Mail::send('emails/references/request2', $data, function ($message) use($data) {
             $message->to($data['emailtwo'])->from('noreply@madesimpleapp.co.uk')->subject('You have been selected to provide a reference');
         });
     }
     flash()->success('Success', 'Reference request has been sent');
     return redirect('/references');
 }
Example #13
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->ip() == '::1') {
         return $next($request);
     }
     return response('Unauthorized.', 401);
 }
 /**
  * Handle the command.
  *
  * @param InviteModel $invites
  * @param Request $request
  * @param Dispatcher $events
  * @return array
  */
 public function handle(InviteModel $invites, Request $request, Dispatcher $events)
 {
     $user['ip_address'] = $request->ip();
     // Slack configurations
     $slackTeam = config('anomaly.extension.slack_inviter::slack.team');
     $slackToken = config('anomaly.extension.slack_inviter::slack.token');
     $slackChannels = config('anomaly.extension.slack_inviter::slack.channels');
     if (!$slackToken) {
         throw new \Exception("Slack API has not been configured. Missing 'anomaly.extension.slack_inviter::slack.auth_token'");
     }
     $slackInviteUrl = 'https://' . $slackTeam . '.slack.com/api/users.admin.invite?t=' . time();
     $fields = array('email' => $user['email'] = $this->builder->getFormValue('email'), 'first_name' => urlencode($user['name'] = $this->builder->getFormValue('name')), 'channels' => $slackChannels, 'token' => $slackToken, 'set_active' => true, '_attempts' => '1');
     // Open the connection.
     $ch = curl_init();
     // set the url, number of POST vars, POST data
     curl_setopt($ch, CURLOPT_URL, $slackInviteUrl);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     curl_setopt($ch, CURLOPT_POST, count($fields));
     curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
     // Execute the request.
     $reply = json_decode(curl_exec($ch), true);
     if ($reply['ok'] == false) {
         $user['error'] = $reply['error'];
     } else {
         $user['successful'] = true;
     }
     // Close the connection.
     curl_close($ch);
     $events->fire(new SlackInviteWasSent($invites->create($user)));
     return $reply;
 }
Example #15
0
 public function get_item(Request $request, $q_id)
 {
     $query = new Question();
     if (Gate::allows('admin')) {
         $query = $query->withTrashed();
     }
     $q = $query->with('writer.socials')->with('tags')->with('viewCounts')->with(['answers' => function ($query) {
         // 답변은 점수 높은 순으로 정렬
         $query->selectRaw('qna_answers.*, COALESCE(SUM(qna_votes.grade),0) AS total_grade')->leftJoin('qna_votes', function ($join) {
             $join->on('qna_answers.id', '=', 'qna_votes.votable_id')->on('qna_votes.votable_type', '=', \DB::raw("'ModernPUG\\\\Qna\\\\Models\\\\Answer'"));
         })->groupBy('qna_answers.id')->orderBy('total_grade', 'desc')->with('writer.socials')->with('comments.writer.socials')->with('comments.votes')->with('votes');
     }])->with('votes')->with('comments.writer.socials')->with('comments.votes')->find($q_id);
     if (!$q) {
         abort(404);
     }
     // 조회수 증가
     ViewCount::create(['q_id' => $q->id, 'ip' => $request->ip(), 'user_id' => Auth::check() ? Auth::user()->id : 0]);
     // 메타 지정
     $desc = strip_tags($q->md_content);
     $desc = str_replace("\r\n", "\n", $desc);
     $desc = str_replace("\r", " ", $desc);
     $desc = str_replace("\n", " ", $desc);
     $desc = $this->limit_words($desc, 30);
     config(['title' => $q->title]);
     config(['author' => $q->writer->name]);
     config(['description' => $desc]);
     config(['keywords' => $q->tagsString]);
     config(['og:title' => $q->title]);
     config(['og:description' => $desc]);
     return view('ncells::qna.pages.item', ['q' => $q]);
 }
 /**
  * Run the request filter.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->exists('g-recaptcha-response')) {
         $recaptcha = new ReCaptcha(Settings::get('secret_key'));
         /**
          * Verify the reponse, pass user's IP address
          */
         $response = $recaptcha->verify($request->input('g-recaptcha-response'), $request->ip());
         /**
          * Fail, if the response isn't OK
          */
         if (!$response->isSuccess()) {
             if ($request->ajax()) {
                 throw new AjaxException($response->getErrorCodes());
             } else {
                 foreach ($response->getErrorCodes() as $code) {
                     Flash::error($code);
                 }
                 return redirect()->back()->withInput();
             }
         }
     }
     /**
      * Handle request
      */
     return $next($request);
 }
 /**
  * Reset the given user's password.
  *
  * @param  Request  $request
  * @return Response
  */
 public function postChange(Request $request)
 {
     $validator = Validator::make($request->all(), ['token' => 'required', 'old_passwd' => 'required', 'password' => 'required|confirmed'], [], ['old_passwd' => '原密码', 'password' => '新密码']);
     if ($validator->fails()) {
         return Redirect::back()->withInput()->withErrors($validator);
     }
     $auth_array = array('email' => Auth::user()->email, 'password' => Input::get('old_passwd'));
     if (Auth::validate($auth_array)) {
     } else {
         return redirect()->back()->withErrors("请输入正确的密码!");
     }
     $credentials = array('email' => Auth::user()->email, 'password' => Input::get('password'), 'password_confirmation' => Input::get('password_confirmation'), 'token' => Input::get('token'));
     $response = $this->passwords->reset($credentials, function ($user, $password) {
         $user->password = bcrypt($password);
         $user->save();
         $this->auth->login($user);
     });
     switch ($response) {
         case PasswordBroker::PASSWORD_RESET:
             $array = array('email' => Auth::user()->email);
             $token = $this->passwords->getToken($array);
             UserManageLog::insertLog("修改密码", Auth::user()->id, Auth::user()->name, Auth::user()->email, Auth::user()->name . '(' . Auth::user()->email . ')', null, null, $request->ip());
             return view('auth.change_password')->withTips("密码修改成功!")->withToken($token);
         default:
             return redirect()->back()->withErrors(['email' => trans($response)]);
     }
 }
Example #18
0
 /**
  * Handle a login request to the application.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function postLogin(Request $request, RateLimiter $rateLimiter, ImageCaptcha $imageCaptcha)
 {
     $identifier = $request->input('identifier');
     $user = User::getUserByIdentifier($identifier);
     $maxAttempts = 3;
     $decayMinutes = 4 * 60;
     if ($user) {
         $key = 'user_id_' . $user->id . ':' . $request->ip();
         if ($rateLimiter->tooManyAttempts($key, $maxAttempts, $decayMinutes)) {
             $retriesLeft = 0;
             if (!$imageCaptcha->check('login', $request->input('captcha'))) {
                 return response()->json(['status' => false, 'message' => '您输入的验证码输入错误', 'field' => 'captcha', 'attempts' => $retriesLeft]);
             }
         } else {
             $retriesLeft = $maxAttempts - $rateLimiter->hit($key) + 1;
         }
         if ($user->login($request->input('password'), true)) {
             $rateLimiter->clear($key);
             return response()->json(['status' => true, 'location' => session('project_invite') ? session('project_invite.active_url') : url('user/home')]);
         } else {
             $forgotPasswordUrl = url('account/forgot-password', [$identifier]);
             return response()->json(['status' => false, 'message' => '您输入的密码错误 <a href="' . $forgotPasswordUrl . '">尝试找回密码</a>', 'field' => 'password', 'attempts' => $retriesLeft]);
         }
     } else {
         return response()->json(['status' => false, 'message' => '系统无法找到您登陆的用户 ' . e($identifier), 'field' => 'identifier', 'attempts' => $maxAttempts]);
     }
 }
Example #19
0
 /**
  * Reset opcache.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function opcacheReset(Request $request)
 {
     if ('127.0.0.1' === $request->ip()) {
         opcache_reset();
     }
     return response()->json('', 200);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->ip() != env('ADMIN_IP', '127.0.0.1')) {
         return redirect('/');
     }
     return $next($request);
 }
 public function index(Request $request)
 {
     //message to show the user
     $message = trans('ban.You are banned.');
     /**
      * check for ban by ip
      */
     $remote_ip = $request->ip();
     $cache_key = '_ban_ip_' . $remote_ip;
     $ban_info = Cache::rememberForever($cache_key, function () use($remote_ip) {
         return AdBanIp::where('ban_ip', $remote_ip)->first();
     });
     /**
      * check if user is banned my email
      */
     if (Auth()->check()) {
         $user_mail = Auth()->user()->email;
         $cache_key = '_ban_email_' . $user_mail;
         $ban_info = Cache::rememberForever($cache_key, function () use($user_mail) {
             return AdBanEmail::where('ban_email', $user_mail)->first();
         });
     }
     //show ban reason
     if (!empty($ban_info)) {
         $message = $ban_info->ban_reason;
     }
     return view('errors.ban', ['message' => $message]);
 }
 /**
  * process request from gitlab webhook.
  *
  * @param  Request  $request
  * @return Response
  */
 public function hookHandler(Request $request)
 {
     $clientIp = !empty($request->header('X-Forwarded-For')) ?: $request->ip();
     Log::debug('hook received from ' . $clientIp);
     if ($this->isVerbose()) {
         dump($request);
     }
     $eventType = $request->headers->get('X-Gitlab-Event');
     if (is_null($eventType)) {
         $eventType = 'Push Hook';
     }
     // for debugging purpose.
     \Storage::put(str_replace(' ', '-', $eventType) . ".json", json_encode($request->json()->all(), JSON_PRETTY_PRINT));
     Log::info('eventType : ' . $eventType);
     if ($eventType == 'Push Hook') {
         return $this->pushHook($request);
     } elseif ($eventType == 'Tag Push Hook') {
         return $this->tagPushHook($request);
     } elseif ($eventType == 'Issue Hook') {
         return $this->issueHook($request);
     } elseif ($eventType == 'Note Hook') {
         return $this->noteHook($request);
     } elseif ($eventType == 'Merge Request Hook') {
         return $this->mergeRequestHook($request);
     }
     abort(500, 'Unknown Hook type : ' . $eventType);
 }
Example #23
0
 /**
  * Verify captcha
  *
  * @return bool
  */
 public function verify()
 {
     if ($this->response === null) {
         $this->response = $this->captcha->verify($this->request->get($this->input), $this->request->ip());
     }
     return $this->response->isSuccess();
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     /**
      * check for ban by ip
      */
     $remote_ip = $request->ip();
     $cache_key = '_ban_ip_' . $remote_ip;
     $ban_info = Cache::rememberForever($cache_key, function () use($remote_ip) {
         return AdBanIp::where('ban_ip', $remote_ip)->first();
     });
     if (!empty($ban_info) && !$request->is('ban')) {
         return redirect('ban');
     }
     /**
      * check if user is banned my email
      */
     if (Auth()->check()) {
         $user_mail = Auth()->user()->email;
         $cache_key = '_ban_email_' . $user_mail;
         $ban_info = Cache::rememberForever($cache_key, function () use($user_mail) {
             return AdBanEmail::where('ban_email', $user_mail)->first();
         });
         if (!empty($ban_info) && !$request->is('ban')) {
             return redirect('ban');
         }
     }
     return $next($request);
 }
Example #25
0
 /**
  * Search events.
  *
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function events(Request $request)
 {
     $ip = $request->ip();
     $ip = '73.85.49.134';
     $geolocation = $this->ipGeolocator->ipToGeolocation($ip);
     $perPage = 4;
     $defaultDistance = 25;
     $input = $request->only(['keyword', 'distance', 'lat', 'lng', 'city', 'type']);
     $input['distance'] = $input['distance'] ?: $defaultDistance;
     if (!$input['city'] && $geolocation) {
         $input['lat'] = $geolocation['lat'];
         $input['lng'] = $geolocation['lng'];
         $input['city'] = $geolocation['city'];
     }
     $events = Event::query()->filterActive()->filterUpcoming()->orderBySoonest();
     if ($input['keyword']) {
         $events->filterKeyword($input['keyword']);
     }
     if ($input['distance'] && is_numeric($input['distance'])) {
         $events->filterNearby($input['lat'], $input['lng'], $input['distance']);
     }
     if ($input['type']) {
         $events->filterTypes($input['type']);
     }
     $events = $events->paginate($perPage);
     $events->appends($input);
     return view('search.events.result', compact('events', 'input'));
 }
Example #26
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($this->core->isIpBlackListed($request->ip())) {
         abort(403, 'Sorry but your ip Banned');
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     $uri = $_SERVER['REQUEST_URI'];
     $ip = $request->ip();
     \Log::info("{$ip} {$uri}");
     return $next($request);
 }
Example #28
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure $next
  * @param int $maxAttempts
  * @param int $decayTime in Minutes
  * @return mixed
  * @throws TooManyRequestsHttpException
  */
 public function handle($request, Closure $next, $maxAttempts = null, $decayTime = null)
 {
     // We only process, if throttle is generally enabled in the config.
     if (config('throttle.enable')) {
         // If no $maxAttempts was submitted, we use the default-value set in the config.
         if ($maxAttempts === null) {
             $maxAttempts = config('throttle.defaultMaxAttempts');
         }
         // If no $decayTime was submitted, we use the default-value set in the config.
         if ($decayTime === null) {
             $decayTime = config('throttle.defaultDecayTime');
         }
         // The key under which this request is handled.
         // It's a hashed string containing the client's IP, the URL-path and the HTTP-method.
         $key = sha1($request->ip() . $request->path() . $request->method());
         // Check, if maximum count of attempts have been reached.
         if (app(RateLimiter::class)->tooManyAttempts($key, $maxAttempts, $decayTime)) {
             // If they have been reached, throw an error including the time left till this resource is available again.
             $availableIn = app(RateLimiter::class)->availableIn($key);
             throw new TooManyRequestsHttpException($availableIn, 'Rate limit exceeded. Please wait ' . $availableIn . ' seconds before trying again.');
         } else {
             // If they have not been reached, we just count this hit.
             app(RateLimiter::class)->hit($key, $decayTime);
         }
     }
     return $next($request);
 }
Example #29
0
 public function store(Request $request)
 {
     Laralum::permissionToAccess('laralum.users.access');
     # Check permissions
     Laralum::permissionToAccess('laralum.users.create');
     # create the user
     $row = Laralum::newUser();
     # Save the data
     $data_index = 'users';
     require 'Data/Create/Save.php';
     # Setup a random activation key
     $row->activation_key = str_random(25);
     # Get the register IP
     $row->register_ip = $request->ip();
     # Activate the user if set
     if ($request->input('active')) {
         $row->active = true;
     }
     # Save the user
     $row->save();
     # Send welcome email if set
     if ($request->input('mail')) {
         # Send Welcome email
         $row->sendWelcomeEmail($row);
     }
     # Send activation email if set
     if ($request->input('send_activation')) {
         $row->sendActivationEmail($row);
     }
     $this->setRoles($row->id, $request);
     # Return the admin to the users page with a success message
     return redirect()->route('Laralum::users')->with('success', trans('laralum.msg_user_created'));
 }
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create(Request $request)
 {
     $user = new User();
     $user->username = $request['username'];
     $user->email = $request['email'];
     $user->password = bcrypt($request['password']);
     $user->ip = $request->ip();
     $user->user_typeId = $request['user_typeId'];
     $user->save();
     if ($user->user_typeId == 5) {
         $org_profile = new Organization_profile();
         $org_profile->userId = $user->id;
         $org_profile->name = $request['name'];
         $org_profile->address = $request['address'];
         $org_profile->description = $request['description'];
         if ($request['brochure']) {
             $org_profile->brochure = $request['brochure'];
         }
         $org_profile->save();
         \Session::flash('sucess_message', 'Organization Regestration Completed !');
     } else {
         $user_profile = new User_profile();
         $user_profile->userId = $user->id;
         $user_profile->fname = $request['fname'];
         $user_profile->mname = $request['mname'];
         $user_profile->lname = $request['lname'];
         $user_profile->gender = $request['gender'];
         $user_profile->save();
         \Session::flash('sucess_message', 'User Regestration Completed !');
     }
     return redirect('');
 }