Beispiel #1
0
 public static function changeStatus($eid, $uid, $status)
 {
     $result = DB::table('invites')->where('eid', $eid)->where('uid', $uid)->update(['status' => $status]);
     if (!$result) {
         if (is_null(Invite::where('eid', $eid)->where('uid', $uid)->first())) {
             DB::table('invites')->insert(array('eid' => $eid, 'uid' => $uid, 'status' => $status));
         }
     }
 }
 /**
  * Send invites to new members by email.
  *
  * @param  int $group_id [description]
  *
  * @return [type]           [description]
  */
 public function sendInvites(Request $request, Group $group)
 {
     $status_message = null;
     // extract emails
     // from http://textsnippets.com/posts/show/179
     preg_match_all("/[\\._a-zA-Z0-9-]+@[\\._a-zA-Z0-9-]+/i", $request->invitations, $matches);
     $emails = $matches[0];
     $emails = array_unique($emails);
     // for each invite email,
     foreach ($emails as $email) {
         // - check that the user has not been invited yet for this group
         $invitation_counter = \App\Invite::where('email', '=', $email)->where('claimed_at', '=', null)->where('group_id', '=', $group->id)->count();
         // check that the user is not already member of the group
         $user_already_member = false;
         $user = \App\User::where('email', $email)->first();
         if ($user) {
             if ($user->isMemberOf($group)) {
                 $user_already_member = true;
             }
         }
         if ($invitation_counter > 0 || $user_already_member) {
             $status_message .= trans('membership.user_already_invited') . ' : ' . $email . '<br/>';
         } else {
             // - create an invite token and store in invite table
             $invite = new \App\Invite();
             $invite->generateToken();
             $invite->email = $email;
             $invite->group_id = $group->id;
             $invite->user_id = $request->user()->id;
             $invite->save();
             // - send invitation email
             Mail::send('emails.invite', ['invite' => $invite, 'group' => $group, 'invitating_user' => $request->user()], function ($message) use($email, $request, $group) {
                 $message->from(env('MAIL_FROM', '*****@*****.**'), env('APP_NAME', 'Laravel'))->to($email)->subject('[' . env('APP_NAME') . '] ' . trans('messages.invitation_to_join') . ' "' . $group->name . '"');
             });
             $status_message .= trans('membership.users_has_been_invited') . ' : ' . $email . '<br/>';
         }
     }
     // NICETOHAVE We could queue or wathever if more than 50 mails for instance.
     // But it's also a kind of spam prevention that it takes time to invite on the server
     if ($status_message) {
         flash()->info($status_message);
     }
     return redirect()->back();
 }
 public function postInvite(Request $request)
 {
     // check if already invited or not
     if (Invite::where('email', $request->email)->first() == null) {
         $user = Auth::user();
         //create new invite
         $invite = new Invite();
         $invite->email = $request->email;
         $invite->user()->associate($user);
         $invite->save();
         $data = ['title' => $user->name . ' invited you to join CocaCola Rewards!', 'content' => 'Join us right now by signing up. Start acquiring points and claim your rewards!', 'email' => $invite->email];
         //send mail to invited person
         Mail::send('emails.invite', $data, function ($message) use($data) {
             $message->to($data['email']);
             $message->subject('Invite to CocaCola Rewards');
         });
     }
     return redirect('dashboard');
 }
Beispiel #4
0
 /**
  * Function to get invite details
  * @param $inviteSenderEmailID
  * @param $inviteRecipientEmailID
  * @return string
  */
 public function getInvite($inviteSenderEmailID, $inviteRecipientEmailID)
 {
     $return = "failure";
     $status = $this->checkInviteStatus($inviteSenderEmailID, $inviteRecipientEmailID);
     if (strcmp($status, 'failure') != 0) {
         $invite = Invite::where('inviteSender', $inviteSenderEmailID)->where('inviteRecipient', $inviteRecipientEmailID)->get();
         $return = $invite[0];
     }
     return $return;
 }
 public function postRegister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     Auth::login($this->create($request->all()));
     $user = Auth::user();
     $user->ip = $request->ip();
     $invited = Invite::where('email', $request->email)->first();
     if ($invited) {
         $invited->accepted = 1;
         $invited->save();
         $inviter = $invited->user;
         $inviter->points = $inviter->points + 100;
         $inviter->save();
     }
     $user->save();
     return redirect('dashboard');
 }
 public function join(User $user, Group $group)
 {
     // if group is open anyone can join, else it's invite only
     if ($group->group_type == $group::OPEN) {
         return true;
     } elseif ($group->group_type == $group::CLOSED) {
         // do we have an invite already for this group and user?
         $invite = \App\Invite::where('email', $user->email)->where('group_id', $group->id)->count();
         if ($invite == 1) {
             return true;
         }
     }
     return false;
 }
Beispiel #7
0
 /**
  * @param  integer $user_id
  * @param  string $email
  * @return mixed
  */
 public function findByUserIDandEmail($user_id, $email)
 {
     return Invite::where('user_id', $user_id)->where('email', $email)->first();
 }