diff --git a/app/controllers/AdminController.php b/app/controllers/AdminController.php index 224a9c9..8c1bff8 100644 --- a/app/controllers/AdminController.php +++ b/app/controllers/AdminController.php @@ -13,7 +13,9 @@ class AdminController extends \BaseController public function home() { - return View::make('admin.index'); + $users = User::all(); + + return View::make('admin.index')->with('users', $users); } public function manageUsers() diff --git a/app/controllers/EmailController.php b/app/controllers/EmailController.php new file mode 100644 index 0000000..515130f --- /dev/null +++ b/app/controllers/EmailController.php @@ -0,0 +1,136 @@ +email; + $to_address = Input::get('to_address'); + $title = Input::get('title'); + $message = Input::get('message'); + + $valid = Validator::make(array($to_address, $title, $message), SentEmail::$rules); + + if($valid->fails()) + { + return Redirect::route('emails/create') + ->withInput(Input::all()) + ->withErrors($valid); + }else + { + $recepient = User::where('email', '=', $to_address)->get(); + + $response = Mail::queue('emails.email', array('name'=> $recepient->first), function($message) use ($recepient) + { + $message->to($to_address, $recepient->first . ' '. $recepient->last)->subject($title); + }); + + if(!$response) + { + Session::flash('message', 'We were unable to send your email. Please try again later'); + + return Redirect::route('emails.create')->withInput(Input::all()); + } + + $sentEmail = new SentEmail; + + $sentEmail->user_id = $user_id; + $sentEmail->from_address = $from_address; + $sentEmail->to_address = $to_address; + $sentEmail->title = $title; + $sentEmail->message = $message; + + if($sentEmail->save()) + { + return Redirect::route('user'); + }else + { + Session::flash('message', 'Something bad happened.') + return Redirect::route('emails/create') + ->withInput(Input::all()); + } + } + } + + + /** + * Display the specified resource. + * + * @param int $id + * @return Response + */ + public function show($id) + { + $email = SentEmail::find($id); + + return View::make('emails.show')->with('email', $email); + } + + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return Response + */ + public function edit($id) + { + //cannot edit emails + } + + + /** + * Update the specified resource in storage. + * + * @param int $id + * @return Response + */ + public function update($id) + { + //cannot update emails + } + + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return Response + */ + public function destroy($id) + { + $email = SentEmail::find($id); + + $email->delete(); + } + + +} diff --git a/app/database/migrations/2014_07_12_172800_create_sent_emails_table.php b/app/database/migrations/2014_07_12_172800_create_sent_emails_table.php new file mode 100644 index 0000000..7d41c89 --- /dev/null +++ b/app/database/migrations/2014_07_12_172800_create_sent_emails_table.php @@ -0,0 +1,52 @@ +increments('id'); + $table->integer('user_id')->unsigned(); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade'); + $table->string('from_address', 100); + $table->string('to_address', 100); + $table->string('title', 100); + $table->text('message'); + $table->timestamps(); + }); + + Schema::create('received_emails', function(Blueprint $table) + { + $table->increments('id'); + $table->integer('user_id')->unsigned(); + $table->foreign('user_id')->references('id')->on('users')->onUpdate('cascade')->onDelete('cascade'); + $table->string('from_address', 100); + $table->string('to_address', 100); + $table->string('title', 100); + $table->text('message'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::drop('sent_emails'); + + Schema::drop('received_emails'); + } + +} diff --git a/app/models/ReceivedEmail.php b/app/models/ReceivedEmail.php new file mode 100644 index 0000000..b6d320b --- /dev/null +++ b/app/models/ReceivedEmail.php @@ -0,0 +1,19 @@ + 'required|email', + 'to_address' => 'required|email', + 'title' => 'required', + 'message' => 'required', + ); +} \ No newline at end of file diff --git a/app/models/SentEmail.php b/app/models/SentEmail.php new file mode 100644 index 0000000..7bd638d --- /dev/null +++ b/app/models/SentEmail.php @@ -0,0 +1,19 @@ + 'required|email', + 'to_address' => 'required|email', + 'title' => 'required', + 'message' = 'required', + ); +} \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index ce7c0c5..5677565 100755 --- a/app/routes.php +++ b/app/routes.php @@ -64,6 +64,7 @@ Route::group(array('before' => 'auth|admin'), function() Route::post('admin/user/contact', array('uses' => 'AdminController@contactUser')); Route::post('admin/user/revoke', array('uses' => 'AdminController@revokeAccess')); Route::get('admin/users/matches', array('as' => 'matches', 'uses' => 'AdminController@showMatches')); + Route::resource('emails', 'EmailController'); }); diff --git a/vendor/autoload.php b/vendor/autoload.php index a80c7fd..2d90776 100755 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer' . '/autoload_real.php'; -return ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221::getLoader(); +return ComposerAutoloaderInitef59d4e967a29076ef0d253a93dee760::getLoader(); diff --git a/vendor/composer/autoload_classmap.php b/vendor/composer/autoload_classmap.php index 53ea70e..c91ee01 100755 --- a/vendor/composer/autoload_classmap.php +++ b/vendor/composer/autoload_classmap.php @@ -39,6 +39,7 @@ return array( 'CreateMentorMenteeMatchTable' => $baseDir . '/app/database/migrations/2014_06_29_143038_create_mentor_mentee_match_table.php', 'CreatePasswordRemindersTable' => $baseDir . '/app/database/migrations/2014_06_27_002502_create_password_reminders_table.php', 'CreateProjectsListingTable' => $baseDir . '/app/database/migrations/2014_07_06_025411_create_projects_listing_table.php', + 'CreateSentEmailsTable' => $baseDir . '/app/database/migrations/2014_07_12_172800_create_sent_emails_table.php', 'CreateUserXrefRoleTable' => $baseDir . '/app/database/migrations/2014_06_27_003343_create_user_xref_role_table.php', 'Crypt_AES' => $vendorDir . '/phpseclib/phpseclib/phpseclib/Crypt/AES.php', 'Crypt_Base' => $vendorDir . '/phpseclib/phpseclib/phpseclib/Crypt/Base.php', diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index bcbc380..994e070 100755 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221 +class ComposerAutoloaderInitef59d4e967a29076ef0d253a93dee760 { private static $loader; @@ -19,9 +19,9 @@ class ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitef59d4e967a29076ef0d253a93dee760', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitef59d4e967a29076ef0d253a93dee760', 'loadClassLoader')); $includePaths = require __DIR__ . '/include_paths.php'; array_push($includePaths, get_include_path()); @@ -46,14 +46,14 @@ class ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221 $includeFiles = require __DIR__ . '/autoload_files.php'; foreach ($includeFiles as $file) { - composerRequire28465c2db9863d424f6e7d76c6a98221($file); + composerRequireef59d4e967a29076ef0d253a93dee760($file); } return $loader; } } -function composerRequire28465c2db9863d424f6e7d76c6a98221($file) +function composerRequireef59d4e967a29076ef0d253a93dee760($file) { require $file; }