/**
  * get the list of announcements for givin hood.
  *
  * @return json
  * @author gcg
  */
 public function getList($hood_id = null, $start = 0, $take = 25)
 {
     $hood = [];
     if (empty($hood_id) or $hood_id == 'null') {
         if (Auth::check()) {
             if (isset(Auth::user()->hood_id) and !empty(Auth::user()->hood_id)) {
                 $hood = Hood::with('district.city')->find(Auth::user()->hood_id);
                 $hood_id = $hood->id;
             }
         }
     } else {
         $hood = Hood::with('district.city')->find($hood_id);
     }
     if (empty($hood)) {
         if ($this->isApi) {
             return response()->api(404, 'No hood spesified.', []);
         }
         return redirect('/')->with('error', 'Lütfen profil ayarlarınızdan mahallenizi girip tekrar deneyin.');
     }
     $hood_id = $hood->id;
     $announcements = Announcement::with('user')->where('hood_id', $hood_id)->orderBy('id', 'desc')->skip($start)->take($take)->get();
     if ($this->isApi) {
         if ($announcements === null) {
             return response()->api(200, 'Announcements: ', []);
         }
         return response()->api(200, 'Announcements: ', $announcements->toArray());
     }
     return response()->app(200, 'announcements.list', ['announcements' => $announcements, 'hood' => $hood]);
 }
Beispiel #2
0
 /**
  * gets the hood_id from location string. creates table records if not exists
  *
  * @return hood object
  * @author gcg
  */
 public static function fromLocation($location)
 {
     $hood = false;
     $location_parts = explode(",", $location);
     foreach ($location_parts as $index => $lp) {
         $location_parts[$index] = trim($lp);
     }
     try {
         $city = City::firstOrCreate(['name' => $location_parts[2]]);
     } catch (Exception $e) {
         Log::error('HoodModel/city', (array) $e);
         return false;
     }
     try {
         $district = District::firstOrCreate(['name' => $location_parts[1], 'city_id' => $city->id]);
     } catch (Exception $e) {
         Log::error('HoodModel/district', (array) $e);
         return false;
     }
     try {
         $hood = Hood::firstOrCreate(['name' => $location_parts[0], 'city_id' => $city->id, 'district_id' => $district->id]);
     } catch (Exception $e) {
         Log::error('HoodModel/hood', (array) $e);
         return false;
     }
     return $hood;
 }
Beispiel #3
0
 /**
  * get a list of hoods based on city or district or autocomplete
  *
  * @return json
  * @author
  **/
 public function getHoods($city_id = null, $district_id = null, $q = null)
 {
     $hoods = Hood::orderBy('name', 'asc');
     if ($q !== null and $q !== 'null') {
         $hoods->where('name', 'LIKE', '%' . $q . '%');
     }
     if ($city_id !== null and $city_id !== 'null') {
         $hoods->where('city_id', $city_id);
     }
     if ($district_id !== null and $district_id !== 'null') {
         $hoods->where('district_id', $district_id);
     }
     $hoods = $hoods->get();
     if (null === $hoods) {
         $hoods = [];
     } else {
         $hoods = $hoods->toArray();
     }
     return response()->api(200, 'Hoods: ', $hoods);
 }
Beispiel #4
0
 /**
  * register as a new user
  *
  * @return json
  * @author
  **/
 public function postRegister()
 {
     $data = Request::all();
     $required_fields = ['email', 'first_name', 'last_name', 'password'];
     if ($this->isApi) {
         $required_fields[] = 'client_id';
         $required_fields[] = 'client_secret';
     }
     foreach ($required_fields as $key) {
         if (!isset($data[$key]) or empty($data[$key])) {
             if ($this->isApi) {
                 return response()->api(400, 'Missing fields, ' . $key . ' is required', $data);
             }
             return redirect('/register')->with('error', 'Lütfen formu doldurup tekrar deneyin.');
         }
     }
     #lets figure out the location.
     $location_parts = explode(",", $data['location']);
     $hood = false;
     if (count($location_parts) === 3) {
         $hood = Hood::fromLocation($data['location']);
     }
     if ($hood === false or $hood === null or !isset($hood->id) or !isset($hood->city_id) or !isset($hood->district_id)) {
         if (isset($data['level']) and $data['level'] == 4) {
             if ($this->isApi) {
                 return response()->api(401, 'Cant get the hood information from the location provided.', ['data' => $data]);
             }
             return redirect('/register-muhtar')->with('error', 'Lokasyonunuzu girerken bir hata oldu, lütfen tekrar deneyin.')->withInput();
         }
     }
     $user = new User();
     $user->level = (isset($data['level']) and $data['level'] == 4) ? 4 : 0;
     if (!isset($data['username'])) {
         $data['username'] = '';
     }
     $data['username'] = Str::slug($data['username']);
     if (empty($data['username'])) {
         $data['username'] = Str::slug($data['first_name']) . "-" . Str::slug($data['last_name']);
     }
     $check_username = DB::table('users')->where('username', $data['username'])->first();
     $check_email = DB::table('users')->where('email', $data['email'])->first();
     if (null !== $check_email) {
         Log::error('Auth/Register/DuplicateEmail', $data);
         if ($this->isApi) {
             return response()->api(400, 'Duplicate entry on email.', $data);
         }
         return redirect('/register')->with('warning', 'Bu eposta adresi ile daha önceden kayıt olunmuş, şifreni unuttuysan, şifreni hatırlatabilirim? ')->withInput();
     }
     if (null !== $check_username) {
         $data['username'] = $data['username'] . time();
     }
     $user->username = $data['username'];
     $user->email = $data['email'];
     $user->password = bcrypt($data['password']);
     $user->first_name = $data['first_name'];
     $user->last_name = $data['last_name'];
     if (isset($hood) and isset($hood->id)) {
         $user->hood_id = $hood->id;
         $user->location = $data['location'];
     }
     try {
         $user->save();
     } catch (Exception $e) {
         Log::error('AuthController/postRegister', (array) $e);
         if ($this->isApi) {
             return response()->api(500, 'Error while creating the user. ', ['details' => (array) $e]);
         }
         return redirect('/register')->with('error', 'Teknik bir sıkıntı oldu :( ')->withInput();
     }
     try {
         Auth::login($user);
     } catch (Exception $e) {
         Log::error('AuthController/postRegister', (array) $e);
         if ($this->isApi) {
             return response()->api(500, 'Login error on tech', []);
         }
         return redirect('/login')->with('warning', 'Kayıttan sonra oturum açarken bir hata oluştu.')->withInput();
     }
     if ($this->isApi) {
         try {
             Auth::login($user);
             Request::merge(['grant_type' => 'direct', 'user_id' => $user->id]);
             $token = Authorizer::issueAccessToken();
         } catch (Exception $e) {
             Log::error('AuthController/postRegister', (array) $e);
             return response()->api(500, 'User saved but there were some errors on login.', ['details' => (array) $e]);
         }
         return response()->api(200, 'Registered and logged in. ', ['user' => $user, 'oauth2' => $token]);
     }
     return redirect()->intended($this->redirPath)->with('success', 'Hoşgeldin, ' . $user->first_name);
 }
Beispiel #5
0
 /**
  * get issues based on pagination and filters
  *
  * @return view
  * @author Me
  */
 public function getIssues($hood_id = null)
 {
     $issues = Issue::with('user', 'tags', 'images');
     $hood = null;
     if ($hood_id != 'all') {
         if (!empty($hood_id)) {
             $hood = Hood::with('district.city')->find(Auth::user()->hood_id);
             $issues->where('hood_id', $hood->id);
         }
         if (empty($hood)) {
             if (Request::has('location')) {
                 $hood = Hood::fromLocation(Request::get('location'));
                 if (isset($hood) and isset($hood->id)) {
                     $issues->where('hood_id', $hood->id);
                 }
             } else {
                 if (Auth::check()) {
                     if (isset(Auth::user()->hood_id) and !empty(Auth::user()->hood_id)) {
                         $hood = Hood::with('district.city')->find(Auth::user()->hood_id);
                         $issues->where('hood_id', $hood->id);
                     }
                 }
             }
         }
     }
     $o1 = 'id';
     $o2 = 'desc';
     if (Request::has('sort')) {
         $sort = Request::get('sort');
         if ($sort == 'popular') {
             $o1 = 'supporter_count';
         }
     }
     $issues->orderBy($o1, $o2);
     if (Request::has('map') and (int) Request::get('map') === 1) {
         $data = $issues->paginate(100);
         return $this->displayMapData($data);
     }
     if (Request::ajax()) {
         return view('partials.issues', ['issues' => $issues->paginate(20), 'hood' => $hood]);
     }
     if ($this->isApi) {
         return response()->api(200, 'Issues', $issues->toArray());
     }
     view()->share('pageTitle', 'Fikir listesi - ');
     session(['last_page' => Request::path()]);
     return response()->app(200, 'issues.list', ['issues' => $issues->paginate(20), 'hood' => $hood]);
 }
 /**
  * update a users profile
  *
  * @return json
  * @author gcg
  */
 public function postUpdate()
 {
     $data = Request::all();
     if ($this->isApi) {
         $user_id = Authorizer::getResourceOwnerId();
     } else {
         $user_id = Auth::user()->id;
     }
     $user = User::find($user_id);
     if (empty($user)) {
         if ($this->isApi) {
             return response()->api(401, 'User issue', []);
         }
         return redirect('/')->with('error', 'Kullanıcı bulanamdı.');
     }
     if (isset($data['email']) and filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
         $user->email = $data['email'];
         $user->is_verified = 0;
     }
     #lets figure out the location.
     $location_parts = explode(",", $data['location']);
     $hood = false;
     if (count($location_parts) === 3) {
         $hood = Hood::fromLocation($data['location']);
     }
     if (isset($hood) and isset($hood->id)) {
         $user->hood_id = $hood->id;
     }
     if (isset($data['username']) and !empty($data['username'])) {
         $data['username'] = Str::slug($data['username']);
         $check_slug = (int) DB::table('users')->where('username', $data['username'])->where('id', '<>', $user_id)->count();
         if ($check_slug === 0) {
             $user->username = $data['username'];
         }
     }
     if (isset($data['first_name']) and !empty($data['first_name'])) {
         $user->first_name = $data['first_name'];
     }
     if (isset($data['last_name']) and !empty($data['last_name'])) {
         $user->last_name = $data['last_name'];
     }
     if (isset($data['location']) and !empty($data['location'])) {
         $user->location = $data['location'];
     }
     if (!empty($data['image']) and is_array($data['image'])) {
         try {
             $name = str_replace('.', '', microtime(true));
             Storage::put('users/' . $name, base64_decode($data['image']));
             $user->picture = $name;
         } catch (Exception $e) {
             Log::error('MembersController/postUpdate/SavingTheImage', (array) $e);
         }
     }
     try {
         $user->save();
     } catch (Exception $e) {
         Log::error('MembersController/postUpdate', (array) $e);
         if ($this->isApi) {
             return response()->api(500, 'Tech problem', []);
         }
         return redirect('/members/edit-profile')->with('error', 'Profilinizi güncellerken bir hata meydana geldi.');
     }
     if ($this->isApi) {
     }
     return redirect('/members/my-profile')->with('success', 'Profiliniz güncellendi.');
 }