コード例 #1
0
 /**
  * Send a reply message to another
  * user and email them about it.
  *
  * @return Illuminate\Http\Response
  */
 protected function send_message()
 {
     if (Input::get('is_reply') !== NULL) {
         $wasReply = true;
         // It's a reply message
         $original_message = Message::find((int) Input::get('original_message_id'));
         // Get the 'id' of the user the
         // message is in reply to
         $to = (int) Input::get('to');
         // And the username of the sender.
         $sender = $original_message->sender->username;
     } else {
         $wasReply = false;
         // It's a new message (i.e. not a reply)
         $original_message = NULL;
         // Get the 'id' of the user the
         // message is being sent to
         $to = User::where('username', '=', Input::get('to'))->first()->id;
         // And the username of the sender
         $sender = Auth::user()->username;
     }
     // Save the body of the message
     // to the filesystem
     $bodyFilename = md5(uniqid(rand(), true)) . '.html';
     $bodyFile = fopen(base_path() . '/resources/message_bodies/' . $bodyFilename, 'w+');
     fwrite($bodyFile, Input::get('message_body'));
     fclose($bodyFile);
     // Save it to the database
     $messageWasSaved = Message::create(['from' => Auth::id(), 'to' => $to, 'subject' => Input::get('subject'), 'body_filename' => $bodyFilename, 'created_at' => date('Y-m-d H:i:s', time()), 'updated_at' => date('Y-m-d H:i:s', time())]);
     if ($messageWasSaved) {
         // Notify the recipient through email
         $mailViewData = ['sender' => $sender, 'preview' => substr(Input::get('message_body'), 0, 200) . '...', 'subject' => Input::get('subject')];
         // Send the mail message
         Mail::send('mail.message_received', $mailViewData, function ($message) use($sender) {
             $message->from('*****@*****.**', 'Eximius');
             $message->to(Auth::user()->email);
             $message->subject($sender . ' has sent you a message through Eximius!');
         });
         // Redirect the sender to their messages
         return redirect('/messages');
     } else {
         echo 'Your message couldn\'t be sent.';
     }
 }
コード例 #2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     // Save the image uploaded to the filesystem
     if (Input::hasFile('selfie')) {
         // The user has uploaded a selfie; Save
         // it to the servers' filesystem
         $extension = Input::file('selfie')->getClientOriginalExtension();
         $persistedFilename = md5(uniqid(rand(), true)) . '.' . $extension;
         $persistedPath = base_path() . '/public/assets/selfies/';
         Input::file('selfie')->move($persistedPath, $persistedFilename);
         // Tell the database the filename
         $data += array('selfie_filename' => $persistedFilename);
     } else {
         // The user has not uploaded a
         // selfie; Tell the database
         $data += array('selfie_filename' => NULL);
     }
     // Save the PDF uploaded to the filesystem
     if (Input::hasFile('résumé')) {
         // The user has uploaded their résumé; Save it
         // The user has uploaded a selfie; Save
         // it to the servers' filesystem
         $extension = Input::file('résumé')->getClientOriginalExtension();
         $persistedFilename = md5(uniqid(rand(), true)) . '.' . $extension;
         $persistedPath = base_path() . '/public/assets/résumés/';
         Input::file('résumé')->move($persistedPath, $persistedFilename);
         // Tell the database the filename
         $data += array('résumé_filename' => $persistedFilename);
     } else {
         // The user has not uploaded a
         // résumé; Tell the database
         $data += array('résumé_filename' => NULL);
     }
     // If checkboxes aren't ticked their values
     // aren't sent with the POST data, so we'll
     // set their values here before sending them
     // to the database.
     //
     isset($data['is_employer']) ? $data['is_employer'] = 1 : ($data['is_employer'] = 0);
     isset($data['is_seeker']) ? $data['is_seeker'] = 1 : ($data['is_seeker'] = 0);
     return User::create(['username' => $data['username'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'selfie_filename' => $data['selfie_filename'], 'is_employer' => $data['is_employer'], 'is_seeker' => $data['is_seeker']]);
 }
コード例 #3
0
ファイル: User.php プロジェクト: Arcrammer/Eximius-in-Laravel
 /**
  * Soft delete a users' profile
  *
  * @return Illuminate\Http\Response
  */
 protected function delete()
 {
     \Eximius\User::destroy(Auth::id());
     \Eximius\Message::where('from', '=', Auth::id())->delete();
     Auth::logout();
     return redirect('/');
 }