diff --git a/app/controllers/EmailController.php b/app/controllers/EmailController.php index 515130f..87a48c1 100644 --- a/app/controllers/EmailController.php +++ b/app/controllers/EmailController.php @@ -9,7 +9,23 @@ class EmailController extends \BaseController { */ public function index() { - + $sent_emails = SentEmail::all(); + $received = ReceivedEmail::all(); + + $user = Auth::user()->level; + + if(!$user == 'admin') + { + return View::make('users.profile') + ->with('sent', $sent_emails) + ->with('received', $received); + }else + { + return View::make('admin.index') + ->with('sent', $sent_emails) + ->with('received', $received); + } + } @@ -20,7 +36,9 @@ class EmailController extends \BaseController { */ public function create() { - return View::make('emails.create'); + $user = Auth::user(); + + return View::make('emails.create')->with('user', $user); } @@ -33,48 +51,45 @@ class EmailController extends \BaseController { { $user_id = Auth::id(); $from_address = Auth::user()->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); + $rules = array( + 'to' => 'required|email', + 'subject' => 'required', + 'message' => 'required' + ); + + $valid = Validator::make(array(Input::only('to', 'subject', 'message')), $rules); if($valid->fails()) { - return Redirect::route('emails/create') + return Redirect::route('emails.create') ->withInput(Input::all()) ->withErrors($valid); }else { - $recepient = User::where('email', '=', $to_address)->get(); + $recepient = User::where('email', '=', Input::get('to'))->first(); - $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) + Mail::queue('users.welcome', array('name'=> $recepient->first), function($message) use ($recepient) { - Session::flash('message', 'We were unable to send your email. Please try again later'); - - return Redirect::route('emails.create')->withInput(Input::all()); - } + $message->to($recepient->email, $recepient->first . ' '. $recepient->last)->subject(\Input::get('subject')); + }); - $sentEmail = new SentEmail; - - $sentEmail->user_id = $user_id; - $sentEmail->from_address = $from_address; - $sentEmail->to_address = $to_address; - $sentEmail->title = $title; - $sentEmail->message = $message; + $sentEmail = SentEmail::create(array( + 'user_id' => $user_id, + 'from_address' => $from_address, + 'to_address' => Input::get('to'), + 'subject' => Input::get('subject'), + 'message' => Input::get('message') + )); if($sentEmail->save()) { return Redirect::route('user'); }else { - Session::flash('message', 'Something bad happened.') - return Redirect::route('emails/create') + Session::flash('message', 'Something bad happened.'); + + return Redirect::route('emails.create') ->withInput(Input::all()); } } @@ -132,5 +147,10 @@ class EmailController extends \BaseController { $email->delete(); } + public function sendEmail($address, $recepient, $subject) + { + return; + } + } diff --git a/app/controllers/ProjectsController.php b/app/controllers/ProjectsController.php index 8901ea3..433aa3d 100644 --- a/app/controllers/ProjectsController.php +++ b/app/controllers/ProjectsController.php @@ -43,8 +43,8 @@ class ProjectsController extends \BaseController { public function store() { $rules = array( - 'title' => 'required|min:5', - 'link' => 'required|url', + 'title' => 'required|min:5', + 'link' => 'required|url', 'language' => 'required' ); 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 index 7d41c89..ddb2dee 100644 --- 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 @@ -17,9 +17,9 @@ class CreateSentEmailsTable extends Migration { $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->string('from', 100); + $table->string('to', 100); + $table->string('subject', 100); $table->text('message'); $table->timestamps(); }); @@ -29,9 +29,9 @@ class CreateSentEmailsTable extends Migration { $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->string('from', 100); + $table->string('to', 100); + $table->string('subject', 100); $table->text('message'); $table->timestamps(); }); diff --git a/app/models/ReceivedEmail.php b/app/models/ReceivedEmail.php index b6d320b..8c2122c 100644 --- a/app/models/ReceivedEmail.php +++ b/app/models/ReceivedEmail.php @@ -8,12 +8,12 @@ class ReceivedEmail extends \Eloquent protected $dates = ['deleted_at']; - protected $fillable = array('user_id','from_address', 'to_address', 'title', 'message'); + protected $fillable = array('user_id','from', 'to', 'subject', 'message'); protected static $rules = array( - 'from_address' => 'required|email', - 'to_address' => 'required|email', - 'title' => 'required', - 'message' => 'required', + 'from' => 'required|email', + 'to' => 'required|email', + 'subject' => 'required', + 'message' => 'required', ); } \ No newline at end of file diff --git a/app/models/SentEmail.php b/app/models/SentEmail.php index 7bd638d..4c9910a 100644 --- a/app/models/SentEmail.php +++ b/app/models/SentEmail.php @@ -8,12 +8,6 @@ class SentEmail extends \Eloquent protected $dates = ['deleted_at']; - protected $fillable = array('user_id','from_address', 'to_address', 'title', 'message'); - - protected static $rules = array( - 'from_address' => 'required|email', - 'to_address' => 'required|email', - 'title' => 'required', - 'message' = 'required', - ); + protected $fillable = array('user_id','from', 'to', 'subject', 'message'); + } \ No newline at end of file diff --git a/app/routes.php b/app/routes.php index 5677565..55c5307 100755 --- a/app/routes.php +++ b/app/routes.php @@ -38,6 +38,7 @@ Route::group(array('before' => 'auth'), function() Route::get('mentors', array('as' => 'mentors', 'uses' => 'UserController@mentors')); Route::get('mentees', array('as' => 'mentees', 'uses' => 'UserController@mentees')); Route::resource('projects', 'ProjectsController'); + Route::resource('emails', 'EmailController'); }); @@ -64,7 +65,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/app/views/admin/index.blade.php b/app/views/admin/index.blade.php index 852f08a..acda378 100644 --- a/app/views/admin/index.blade.php +++ b/app/views/admin/index.blade.php @@ -27,7 +27,7 @@ - + {{ HTML::image("images/mentconnect.png", "editor", array("width" => "150px", "height" => "30px")) }} diff --git a/app/views/emails/create.blade.php b/app/views/emails/create.blade.php new file mode 100644 index 0000000..f68abca --- /dev/null +++ b/app/views/emails/create.blade.php @@ -0,0 +1,89 @@ + + + + + + + {{ $user->first}}- Mentconnect + + + {{HTML::style('css/userprofile.css')}} + + + + + + + + + + +
+
+
+
+ {{ Form::open(array('route' => 'emails.store', 'class' => 'form-horizontal')) }} + +
+
+ +
+ + {{Form::email('to_address', \Input::old('to_address'), array('class' => 'form-control form-control-bordered', 'tabindex' => '1'))}} {{$errors->first('to_address')}} +
+
+ + + {{ Form::text('subject', \Input::old('subject'), array('class' => 'form-control form-control-bordered', 'tabindex' => '2')) }} {{$errors->first('subject')}} +
+
+ + + {{ Form::textarea('message', \Input::old('message'), array('class' => 'form-control form-control-bordered', + 'tabindex' => '3')) }} {{$errors->first('message') }} +
+ +
+ {{Form::submit('Send', array('class' => 'btn btn-primary btn-large submit-button'))}} +
+
+
+
+ {{ Form::close() }} + +
+
+
+ + + + diff --git a/app/views/emails/email.blade.php b/app/views/emails/email.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/app/views/emails/show.blade.php b/app/views/emails/show.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/app/views/users/profile.blade.php b/app/views/users/profile.blade.php index cf9c7a9..d2437d3 100644 --- a/app/views/users/profile.blade.php +++ b/app/views/users/profile.blade.php @@ -6,10 +6,12 @@ {{ $user->first}}- Mentconnect - + {{HTML::style('css/userprofile.css')}} + + @@ -45,12 +47,11 @@ -
- diff --git a/public/js/user-profile.js b/public/js/user-profile.js new file mode 100644 index 0000000..1bfff7a --- /dev/null +++ b/public/js/user-profile.js @@ -0,0 +1,7 @@ + +$(function() +{ + $('#dialog').click(function(){ + $('#compose').dialog(); + }); +}); \ No newline at end of file