コード例 #1
0
ファイル: TeamController.php プロジェクト: matthiku/cSpot
 /**
  * Send an email to the user to request his confirmation for being a member of the team
  *
  * @return \Illuminate\Http\Response
  */
 public function sendrequest($plan_id, $id, AppMailer $mailer)
 {
     // check access rights
     if (!Auth::user()->ownsPlan($plan_id)) {
         return redirect('home')->with('error', 'You are unauthorized for this request.');
     }
     // get the resource handle
     $team = Team::find($id);
     if ($team) {
         if ($team->requested) {
             $error = 'Request Email was already sent to this user!';
             return \Redirect::back()->with(['error' => $error]);
         }
         $team->requested = True;
         $team->remember_token = str_random(32);
         // send internal message to user
         $message = 'Please open <a href="' . url('cspot/plans/' . $plan_id) . '/team"> this plan </a> and confirm if you accept the given role.';
         $thread_id = sendInternalMessage('You have been assigned a role in a Service plan', $message, $team->user_id, false);
         $team->thread_id = $thread_id;
         $team->save();
         // also send an email to the user
         $recipient = User::find($team->user_id);
         $plan = Plan::find($team->plan_id);
         $mailer->getPlanMemberConfirmation($recipient, $plan, $team);
         $status = 'Email with membership request was sent to user.';
         return \Redirect::route('team.index', ['plan_id' => $plan_id])->with(['status' => $status]);
     }
     $error = 'Wrong team member id!';
     return \Redirect::back()->with(['error' => $error]);
 }