コード例 #1
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]);
 }
コード例 #2
0
ファイル: AuthController.php プロジェクト: istatease-dev/api
 /**
  * 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);
 }
コード例 #3
0
 /**
  * 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.');
 }