Exemplo n.º 1
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @param  Request $request
  * @return bool
  */
 public function authorize(Request $request)
 {
     $landing_page_id = $request->get('landing_page_id');
     $landing_page = Landing_Page::findOrFail($landing_page_id);
     // Check that user is part of campaign users
     return $landing_page->first()->campaign->users->contains(Auth::id()) ? true : false;
 }
Exemplo n.º 2
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     // URL route is implicitly defined as the resource
     $landing_page_id = $this->route('landing_pages');
     $landing_page = Landing_Page::findOrFail($landing_page_id);
     // Check that user is part of campaign users
     return $landing_page->first()->campaign->users->contains(Auth::id()) ? true : false;
 }
Exemplo n.º 3
0
 /**
  * Custom validator to check email array
  * 
  * @param  Factory $factory
  * @return $object
  */
 public function validator($factory)
 {
     $landing_page_id = $this->route('landing_pages');
     $campaign_id = Landing_Page::where('id', $landing_page_id)->first()->campaign->id;
     // Validate email users are part of campaign
     $validation = $factory->make($this->all(), $this->rules());
     $validation->each('add_user_email_notification', ['exists:user_has_roles,user_id,campaign_id,' . $campaign_id]);
     return $validation;
 }
Exemplo n.º 4
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     // URL route is implicitly defined as the resource
     $landing_page_id = $this->route('landing_pages');
     $campaign_id = Landing_Page::findOrFail($landing_page_id)->first()->campaign->id;
     return Campaign::where('id', $campaign_id)->with('users')->whereHas('users', function ($q) {
         $q->where('user_id', Auth::id())->where('role_id', config('roles.admin'));
     })->exists();
 }
Exemplo n.º 5
0
 /**
  * Determine if the user is authorized to make this request.
  *
  * @param  Request $request
  * @return bool
  */
 public function authorize(Request $request)
 {
     /**
      * This request is publicly accessible
      */
     $landing_page_id = $request->get('landing_page_id');
     $landing_page = Landing_Page::findOrFail($landing_page_id);
     // Check that landing page and campaign are both active
     return $landing_page->active == 1 && $landing_page->campaign->active ? true : false;
 }
Exemplo n.º 6
0
 /**
  * Store a new lead (internal)
  * 
  * @param  StoreNewLeadRequest $request
  * @return Redirect
  */
 public function postStoreLead(StoreNewLeadRequest $request)
 {
     $landing_page_id = $request->get('landing_page_id');
     $landing_page = Landing_Page::find($landing_page_id);
     // Get any custom fields
     $custom = array_where($request->all(), function ($k, $v) {
         return !in_array($k, config('lead.fields'));
     });
     $lead = Lead::create(['landing_page_id' => $landing_page_id, 'first_name' => $request->get('first_name', ''), 'last_name' => $request->get('last_name', ''), 'email' => $request->get('email', ''), 'company' => $request->get('company', ''), 'title' => $request->get('title', ''), 'phone' => $request->get('phone', ''), 'zip' => $request->get('zip', ''), 'address' => $request->get('address', ''), 'city' => $request->get('city', ''), 'state' => $request->get('state', ''), 'country' => $request->get('country', ''), 'custom' => json_encode($custom)]);
     // Send emails
     if ($landing_page->send_email) {
         foreach ($landing_page->users_to_email as $user) {
             \Mail::queue('emails.leads.create', ['lead' => $lead, 'landing_page' => $landing_page], function ($message) use($user, $landing_page) {
                 if (!$landing_page->email_title) {
                     $landing_page->email_title = \Lang::get('lead.email.new_lead', ['title' => $landing_page->title]);
                 }
                 $message->to($user->email)->subject($landing_page->email_title);
             });
         }
     }
     // Link lead to attribution entry
     \Event::fire(new LeadSubmitted($lead));
     return redirect('leads')->with('status', \Lang::get('lead.lead_created', ['landing_page' => $landing_page->title]));
 }
Exemplo n.º 7
0
 /**
  * Add landing page to campaign
  * 
  * @param  AdminStoreLandingPageRequest $request
  * @param  Integer $id
  * @return Response
  */
 public function postAddLandingPage(AdminStoreLandingPageRequest $request, $id)
 {
     $landing_page = Landing_Page::create(['user_id' => $this->user->id, 'campaign_id' => $id, 'title' => $request->get('title'), 'description' => $request->get('description'), 'return_url' => $request->get('return_url'), 'auth_key' => str_random(40), 'send_email' => $request->has('send_email') ? $request->get('send_email') : 0, 'email_title' => $request->has('email_title') ? $request->get('email_title') : '']);
     // Attach users to email
     if ($request->has('add_user_email_notification')) {
         $landing_page->users_to_email()->sync($request->get('add_user_email_notification'));
     }
     return redirect('landing_pages/' . $landing_page->id)->with('status', \Lang::get('campaign.created_landing_page', ['landing_page_title' => $landing_page->title]));
 }
Exemplo n.º 8
0
 /**
  * Display the web to lead form
  * 
  * @param  ShowRequest $request
  * @param  Integer $id
  * @return Response
  */
 public function getWebToLead(ShowRequest $request, $id)
 {
     $landing_page = Landing_Page::find($id);
     return view('landing_pages.web_to_lead')->with('user', $this->user)->with('landing_page', $landing_page);
 }