/** * deletes a member from the database * * @return redirect * @author gcg */ public function getDeleteMember($id = null) { $member = User::find($id); if (empty($member)) { return redirect('/admin/members')->with('error', 'Aradığınız kullanıcı bulunamıyor. '); } $tmp = ['created_at' => Carbon::now(), 'updated_at' => Carbon::now(), 'source_id' => Auth::user()->id, 'previous_level' => $member->level, 'current_level' => 0, 'user_id' => $member->id]; try { $member->delete(); DB::table('user_updates')->insert($tmp); } catch (Exception $e) { Log::error('AdminController/getDeleteMember', (array) $e); return redirect('/admin/members')->with('error', 'Üye silinirken bir hata oluştu.'); } return redirect('/admin/members')->with('success', 'Üye silindi.'); }
/** * logs in the user using facebook * * @return redirect * @author Me */ public function getFacebookLoginReturn() { $user = Socialize::with('facebook')->user(); #check if we get the user with all the data that we need to login $email = $user->getEmail(); $id = $user->getId(); $userData = $user->user; if (empty($email) or empty($id)) { return redirect('/signup')->with('error', 'Facebook ile girişte bir hata meydana geldi, normal login olmayı deneyebilirsiniz.')->withInput(); } #check if the user already has an account with the facebook $user_social_account = DB::table('user_social_accounts')->where('source', 'facebook')->where('source_id', $id)->first(); if (empty($user_social_account)) { #lets register the user_social_account #check if the user is already have an account with the same email. $u = User::where('email', $email)->first(); if (empty($u)) { #lets create the user account $u = new User(); $u->username = Str::slug($user->getName()); $u->email = $user->getEmail(); $u->first_name = $userData['first_name']; $u->last_name = $userData['last_name']; $u->picture = $this->picture($user->avatar_original); $u->is_verified = (isset($userData['verified']) and $userData['verified']) ? 1 : 0; try { $u->save(); } catch (Exception $e) { Log::error('User save error', (array) $e); return redirect('/signup')->with('error', 'Kaydınızı yaparken teknik bir hata meydana geldi.')->withInput(); } } $user_social_account = new UserSocialAccount(); $user_social_account->user_id = $u->id; $user_social_account->source = 'facebook'; $user_social_account->source_id = $id; $user_social_account->access_token = $user->token; try { $user_social_account->save(); } catch (Exception $e) { Log::error('AuthController/saveUserSocialAccount', (array) $e); } } else { $u = User::find($user_social_account->user_id); if (empty($u)) { DB::table('user_social_accounts')->where('id', $user_social_account->id)->delete(); return redirect('/login/facebook'); } } if ($u->picture == "placeholders/profile.png") { $u->picture = $this->picture($user->avatar_original); try { $u->save(); } catch (Exception $e) { Log::error('AuthController/updateUserPicture', (array) $e); } } Auth::login($u); return redirect()->intended($this->redirPath)->with('success', 'Hoşgeldin, ' . $u->first_name); }
/** * 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.'); }