public function loginWithLinkedin() { // get data from input $code = Input::get('code'); $linkedinService = OAuth::consumer('Linkedin'); if (!empty($code)) { // This was a callback request from linkedin, get the token $token = $linkedinService->requestAccessToken($code); //$token="7ee85959-1809-4899-a10d-626740702f5d"; // Send a request with it. Please note that XML is the default format. $result = json_decode($linkedinService->request('/people/~:(id,first-name,last-name,skills,headline,summary,industry,member-url-resources,picture-urls::(original),location,public-profile-url,email-address,site-standard-profile-request)?format=json'), true); $linkedinid = $result['id']; //echo "<pre>";print_r($token->getAccessToken());echo "</pre>"; //echo $token->accessToken;die; //die(); if (!empty($token)) { //$user = User::where('linkedinid', '=', $linkedinid)->first(); $user = User::where('linkedinid', '=', $linkedinid)->first(); if (!empty($user)) { $user_data = $user->toArray(); $user_id = $user_data['id']; $user_info = User::find($user_id); $user = User::find($user_id); $user->token = $token->getAccessToken(); $user->save(); $CurrentDate = KarmaHelper::currentDate(); $profileupdatedate = $user_info->profileupdatedate; $diffDate = KarmaHelper::dateDiff($CurrentDate, $profileupdatedate); $diffDate = $diffDate->days * 24 + $diffDate->h; $refreshTime = Adminoption::where('option_name', '=', 'connection refresh time')->first(); //echo "<pre>";print_r($refreshTime);echo "</pre>";die(); $InsConnection = KarmaHelper::updateUserProfile($user, $result); if (!empty($refreshTime)) { $refreshTime = $refreshTime->toArray(); $refreshTime = $refreshTime['option_value']; } else { $refreshTime = '360'; } if ($diffDate >= $refreshTime) { $date = Carbon::now()->addMinutes(5); Queue::push('UpdateUser', array('id' => $user_id, 'result' => $result)); } //echo "<pre>";print_r($user);echo "</pre>";die(); if (Auth::loginUsingId($user_id)) { if ($user['registrationstatus'] == '0') { return Redirect::to('register'); } else { return Redirect::to('dashboard'); } } else { return Redirect::route('/'); } } else { if (!isset($result['publicProfileUrl']) || $result['publicProfileUrl'] == '') { $publicProfileUrl = $result['siteStandardProfileRequest']['url']; } else { $publicProfileUrl = $result['publicProfileUrl']; } $user = new User(); $user->fname = $result['firstName']; $user->lname = @$result['lastName']; $user->email = $result['emailAddress']; $user->piclink = @$result['pictureUrls']['values'][0]; $user->linkedinid = $result['id']; $user->summary = @$result['summary']; $user->location = @$result['location']['name']; $user->industry = @$result['industry']; $user->headline = @$result['headline']; $user->linkedinurl = @$publicProfileUrl; $user->token = $token->getAccessToken(); $user->profileupdatedate = date('Y-m-d H:i:s'); $user->save(); $user = $user; $user_id = $user->id; $InsTag = KarmaHelper::insertUsertag($user, $result); Queue::push('MessageSender@newUserEmail', array('user_id' => $user_id)); $InsConnection = KarmaHelper::insertUserConnection($user); if (Auth::loginUsingId($user_id)) { return Redirect::to('dashboard'); } else { return Redirect::route('/'); } } } } else { // get linkedinService authorization $url = $linkedinService->getAuthorizationUri(array('state' => 'DCEEFWF45453sdffef424')); // return to linkedin login url return Redirect::to((string) $url); } }
/** Function name: saveKarmanote() Created by : Evon Created on : 04/10/2014 **/ public function saveKarmanote() { $CurrentUser = Auth::User(); $meetingId = $receiverId = $giverId = $note = $receiverName = $giverName = $ShareKarmaNote = ''; $note = array(); if (!empty(Input::get('ShareKarmaNote'))) { $ShareKarmaNote = Input::get('ShareKarmaNote'); } if (!empty(Input::get('meetingId'))) { $meetingId = Input::get('meetingId'); } if (!empty(Input::get('receiverId'))) { $receiverId = Input::get('receiverId'); } if (!empty(Input::get('introducerId'))) { $introducerId = Input::get('introducerId'); } if (!empty(Input::get('giverId'))) { $giverId = Input::get('giverId'); } if (!empty(Input::get('skillTags'))) { $skills = Input::get('skillTags'); } if (!empty(Input::get('details'))) { $note = Input::get('details'); } if (!empty(Input::get('receiverName'))) { $receiverName = Input::get('receiverName'); } if (!empty(Input::get('giverName'))) { $giverName = Input::get('giverName'); } //print_r($ShareKarmaNote);die; if (!$this->Karmanote->isValid(Input::all())) { return Redirect::back()->withInput()->withErrors($this->Karmanote->errors); } else { $feedType = 'KarmaNote'; $karmaNote = new Karmanote(); $karmaNote->req_id = $meetingId; $karmaNote->user_idgiver = $giverId; $karmaNote->user_idreceiver = $receiverId; $karmaNote->details = strip_tags($note); if (!empty($skills)) { $karmaNote->skills = implode(',', $skills); } else { $karmaNote->skills = ''; } $karmaNote->viewstatus = 0; if ($ShareKarmaNote == 1) { $karmaNote->share_onlinkedin = $ShareKarmaNote; } $karmaNote->created_at = KarmaHelper::currentDate(); $karmaNote->save(); $karmaNoteId = $karmaNote->id; //$karmaNoteMessage=$karmaNote->details; if (!empty($skills)) { $getName = $getSkillDataName = ""; foreach ($skills as $key => $value) { $getName = Tag::where('id', '=', $value)->select('name')->first(); $getSkillDataName .= $getName->name . ","; } $result = rtrim($getSkillDataName, ","); $karmaNoteMessage = $karmaNote->details . "\nEndorsements: " . $result; } else { $karmaNoteMessage = $karmaNote->details; } $Meetingrequest = Meetingrequest::find($meetingId); $Meetingrequest->status = 'completed'; $Meetingrequest->save(); $messageData = new Message(); $messageData->request_id = $meetingId; $messageData->sender_id = $CurrentUser->id; $messageData->giver_id = $giverId; $messageData->receiver_id = $CurrentUser->id; $messageText = $CurrentUser->fname . ' ' . $CurrentUser->lname . ' has sent a KarmaNote.'; $messageData->messageText = $messageText; $messageData->save(); $messageData = new Message(); $messageData->message_type = 'user'; $messageData->request_id = $meetingId; $messageData->sender_id = $CurrentUser->id; $messageData->giver_id = $giverId; $messageData->receiver_id = $CurrentUser->id; $messageTextOfKarmaNote = $karmaNoteMessage; $messageData->messageText = $messageTextOfKarmaNote; $messageData->save(); DB::table('users_mykarma')->where('entry_id', '=', $meetingId)->update(array('status' => 'completed', 'entry_updated_on' => Carbon::now())); DB::table('requests')->where('id', '=', $meetingId)->update(array('status' => 'completed')); $userRole = 'Receiver'; $changeStatus = KarmaHelper::updateMeetingStatus($meetingId, $userRole); KarmaHelper::updateKarmaScore($giverId, $receiverId); //KarmaHelper::storeKarmacirclesRecord($giverId,$receiverId); //KarmaHelper::storeKarmacirclesRelation($giverId,$receiverId); KarmaHelper::storeKarmacirclesfeed($giverId, $receiverId, $feedType, $karmaNoteId); if (!empty($introducerId)) { KarmaHelper::updateIntroducerKarmaScore($introducerId); } if (!empty($ShareKarmaNote)) { $receiverDetail = User::find($receiverId); //MessageHelper::shareOnLinkedin($receiverDetail->token,'asdasd');die(); Queue::push('MessageSender', array('type' => '9', 'user_id_giver' => $giverId, 'user_id_receiver' => $receiverId, 'meetingId' => $meetingId)); } //$sendLinkedinMessage = MessageHelper::triggerEmailAndMessage($giverId,$receiverId,'5',$meetingId); Queue::push('MessageSender', array('type' => '5', 'user_id_giver' => $giverId, 'user_id_receiver' => $receiverId, 'meetingId' => $meetingId)); return Redirect::to('meeting/' . $receiverName . '-' . $giverName . '/' . $meetingId); } }
public function submitIntroform() { $payitforward = $sendKarmaNote = $buyyoucoffee = '0'; $receiverWR = Input::get('receiverWR'); if (!empty($receiverWR)) { foreach ($receiverWR as $key => $value) { if ($value == "I'd pay it forward") { $payitforward = '1'; } elseif ($value == "I'd send you a Karma Note") { $sendKarmaNote = '1'; } } } $giver_email = Input::get('giver_email'); $user_id_receiver = Input::get('receiver_id'); $connection_id_receiver = Input::get('receiver_conn_id'); if (!empty(Input::get('giver_id') && Input::get('giver_id') != 'undefined')) { echo $user_id_giver = Input::get('giver_id'); } $connection_id_giver = Input::get('giver_conn_id'); $user_id_introducer = Input::get('user_id_Intro'); $detail = Input::get('note'); if (!empty($user_id_giver)) { $Meetingrequest = new Meetingrequest(); $Meetingrequest->user_id_introducer = $user_id_introducer; $Meetingrequest->user_id_receiver = $user_id_receiver; $Meetingrequest->user_id_giver = $user_id_giver; $Meetingrequest->connection_id_giver = $connection_id_giver; $Meetingrequest->notes = strip_tags($detail); $Meetingrequest->payitforward = $payitforward; $Meetingrequest->sendKarmaNote = $sendKarmaNote; $Meetingrequest->buyyoucoffee = $buyyoucoffee; $Meetingrequest->status = 'pending'; $Meetingrequest->req_createdate = KarmaHelper::currentDate(); $Meetingrequest->save(); $meetingId = $Meetingrequest->id; Queue::push('MessageSender', array('type' => '12', 'user_id_giver' => $user_id_giver, 'user_id_receiver' => $user_id_receiver, 'meetingId' => $meetingId)); //$sendLinkedinMessage = MessageHelper::triggerEmailAndMessage($user_id_giver,$user_id_receiver,'12',$meetingId); //echo "<pre>";print_r($sendLinkedinMessage);echo "</pre>";die(); return Redirect::to('/karma-intro'); } else { $Meetingrequest = new Meetingrequest(); $Meetingrequest->user_id_introducer = $user_id_introducer; $Meetingrequest->user_id_receiver = $user_id_receiver; $Meetingrequest->connection_id_giver = $connection_id_giver; $Meetingrequest->notes = strip_tags($detail); $Meetingrequest->payitforward = $payitforward; $Meetingrequest->sendKarmaNote = $sendKarmaNote; $Meetingrequest->buyyoucoffee = $buyyoucoffee; $Meetingrequest->status = 'pending'; $Meetingrequest->req_createdate = KarmaHelper::currentDate(); $Meetingrequest->save(); $meetingId = $Meetingrequest->id; if ($giver_email != "") { Queue::push('MessageSender@IntroEmailToNonKarmaGiver', array('type' => '15', 'user_id_giver' => $connection_id_giver, 'user_id_receiver' => $user_id_receiver, 'giver_email' => $giver_email, 'meetingId' => $meetingId)); } Queue::push('MessageSender', array('type' => '13', 'user_id_giver' => $connection_id_giver, 'user_id_receiver' => $user_id_receiver, 'meetingId' => $meetingId)); return Redirect::to('/karma-intro'); /*For Sending Intro Email to Non Karma User if email id is given*/ } }
/** * Function to request new time. * * @return Response */ public static function commonMeetingRequestNewTime($meetingId, $userId) { $getUser = User::find($userId); $meetingDetail = Meetingrequest::find($meetingId); $meetingDetail->meetingduration = 'null'; $meetingDetail->meetingtimezonetext = 'null'; $meetingDetail->meetingtimezone = 'null'; $meetingDateTime = 'null'; $meetingDetail->meetingdatetime = 'null'; $meetingDetail->meetinglocation = 'null'; $meetingDetail->meetingtimezone = 'null'; $meetingDetail->meetingtype = 'null'; $meetingDetail->req_updatedate = KarmaHelper::currentDate(); $meetingDetail->reply = 'null'; $meetingDetail->status = 'responded'; $meetingDetail->save(); $userRole = 'Receiver'; DB::table('users_mykarma')->where('entry_id', '=', $meetingId)->update(array('status' => 'responded', 'entry_updated_on' => Carbon::now())); $changeStatus = KarmaHelper::updateMeetingStatus($meetingId, $userRole); $getGiverData = DB::table('requests')->join('users', 'requests.user_id_giver', '=', 'users.id')->where('requests.id', '=', $meetingId)->select('users.fname', 'users.lname', 'requests.user_id_giver', 'requests.user_id_receiver', 'requests.status')->get(); //Add message in requests_messages table if (!empty($getGiverData)) { $messageData = new Message(); $messageData->request_id = $meetingId; $messageData->sender_id = $userId; $messageData->giver_id = $getGiverData[0]->user_id_giver; $messageData->receiver_id = $userId; $messageText = $getUser->fname . ' ' . $getUser->lname . ' has requested a new time for the meeting.'; $messageData->messageText = $messageText; $messageData->save(); } else { $getGiverData = array(); } return $getGiverData; }
/** * Function to save user information. * * @return Response */ public function saveuserInfo() { $result = Request::all(); $rules = Validator::make(Request::all(), ['fname' => 'required', 'lname' => 'required', 'email' => 'required', 'linkedinid' => 'required', 'token' => 'required', 'linkedinurl' => 'required']); if ($rules->fails()) { $this->status = 'failure'; $this->message = 'There is something missing So user cant be registered'; return Response::json(array('status' => $this->status, 'message' => $this->message)); } else { $linkedinid = Request::get('linkedinid'); $email = Request::get('email'); $user = User::where('linkedinid', '=', $linkedinid)->orWhere('email', '=', $email)->first(); $randNumber = ApiController::getGUID(); if (!empty($user)) { //This code will execute when user will already register. $user_id = $user->id; $user_data = $user->toArray(); $user_id = $user_data['id']; $user_info = User::find($user_id); $user = User::find($user_id); $user->token = $result['token']; $user->site_token = $randNumber; $user->save(); $CurrentDate = KarmaHelper::currentDate(); $profileupdatedate = $user_info->profileupdatedate; $diffDate = KarmaHelper::dateDiff($CurrentDate, $profileupdatedate); $diffDate = $diffDate->days * 24 + $diffDate->h; $refreshTime = Adminoption::where('option_name', '=', 'connection refresh time')->first(); if (!empty($refreshTime)) { $refreshTime = $refreshTime->toArray(); $refreshTime = $refreshTime['option_value']; } else { $refreshTime = '360'; } if ($diffDate >= $refreshTime) { $date = Carbon::now()->addMinutes(5); Queue::push('UpdateUser', array('id' => $user_id, 'result' => $result)); } $this->status = 'Success'; $this->message = 'You are already registered'; $userStatus = User::where('linkedinid', '=', $linkedinid)->orWhere('email', '=', $email)->select('userstatus')->first(); $userStatus = $userStatus->userstatus; } else { //This code will execute when new user will register. $user = new User(); $user->fname = $result['fname']; $user->lname = @$result['lname']; $user->email = $result['email']; $user->piclink = @$result['piclink']; $user->linkedinid = $result['linkedinid']; $user->summary = @$result['summary']; $user->location = @$result['location']; $user->industry = @$result['industry']; $user->headline = @$result['headline']; $user->linkedinurl = @$result['linkedinurl']; $user->token = @$result['token']; $user->termsofuse = 1; $user->userstatus = 'ready for approval'; $user->noofmeetingspm = 2; $user->profileupdatedate = date('Y-m-d H:i:s'); $user->site_token = $randNumber; $user->save(); $user = $user; $user_id = $user->id; Queue::push('MessageSender@newUserEmail', array('user_id' => $user_id)); //funtion to save data on connections table. $InsConnection = KarmaHelper::insertUserConnection($user); $this->status = 'Success'; $this->message = 'User successfully registered'; $userStatus = User::where('linkedinid', '=', $result['linkedinid'])->orWhere('email', '=', $result['email'])->select('userstatus')->first(); $userStatus = $userStatus->userstatus; } return Response::json(array('status' => $this->status, 'message' => $this->message, 'UserId' => $user_id, 'UserAccesstoken' => $user->site_token, 'UserStatus' => $userStatus)); } }
public function updateUser() { $user_id = Input::get('id'); $userDetail = User::find($user_id); $userstatus = Input::get('userstatus'); $username = Input::get('name'); $fname = $lname = ''; if (isset($username)) { list($fname, $lname) = explode(" ", $username); } if ($userstatus == "approved" && $userDetail->userstatus != "approved") { //MessageHelper::sendActivationMessage($userDetail); Queue::push('MessageSender@sendActivationEmail', array('user_id' => $user_id)); // send an email and save a karmanote to user from kc team to show on his profile $Meetingrequest = new Meetingrequest(); $Meetingrequest->user_id_receiver = '430'; $Meetingrequest->user_id_giver = $user_id; $Meetingrequest->subject = ''; $Meetingrequest->notes = ""; $Meetingrequest->status = 'completed'; $Meetingrequest->meetingdatetime = date('Y-m-d H:i:s'); $Meetingrequest->replyviewstatus = '1'; $Meetingrequest->requestviewstatus = '1'; $Meetingrequest->meetingtimezone = ''; $Meetingrequest->req_createdate = KarmaHelper::currentDate(); $Meetingrequest->save(); $meetingId = $Meetingrequest->id; $meetingId = $Meetingrequest->id; $karmaNote = new Karmanote(); $karmaNote->req_id = $meetingId; $karmaNote->user_idgiver = $user_id; $karmaNote->user_idreceiver = '430'; $karmaNote->details = "Welcome to KarmaCircles. Thank you for joining the world's largest movement to spread good karma."; $karmaNote->skills = ''; $karmaNote->statusreceiver = 'hidden'; $karmaNote->viewstatus = 0; $karmaNote->created_at = KarmaHelper::currentDate(); $karmaNote->save(); } $profileupdatedate = Input::get('profileupdatedate'); $userrole = Input::get('role'); $userupdate = User::find($user_id); $userupdate->userstatus = $userstatus; $userupdate->fname = $fname; $userupdate->lname = $lname; $userupdate->profileupdatedate = $profileupdatedate; $userupdate->role = $userrole; $userupdate->save(); /*Group Settings*/ $group_ids = Input::get('Groups'); $meeting_setting = "accept from group only"; /* $meeting_setting = Input::get('meeting_setting'); if(empty($meeting_setting)){ $meeting_setting = "accept from all"; } else{ $meeting_setting = "accept from group only"; } */ //echo "<pre>";print_r($group_ids);echo "</pre>";die; $UsersgroupCount = Usersgroup::where('user_id', '=', $user_id)->count(); if ($UsersgroupCount > '0') { $UsersgroupCount = Usersgroup::where('user_id', '=', $user_id)->delete(); } if (!empty($group_ids)) { foreach ($group_ids as $key => $value) { $usergroup = new Usersgroup(); $usergroup->user_id = $user_id; $usergroup->group_id = $value; $usergroup->save(); } $user = User::find($user_id); $user->meeting_setting = $meeting_setting; $user->save(); } else { $user = User::find($user_id); //$user->meeting_setting = "accept from all"; $user->meeting_setting = $meeting_setting; $user->save(); } return Redirect::to('/admin/manageUser'); //echo "<pre>"; print_r($_POST);echo "</pre>"; }