mentors

mentors Commit Details


Date:2014-07-12 17:05:48 (10 years 5 months ago)
Author:Right Or Wrong
Branch:develop
Commit:725160e25c0c8d1a7c856574e0d401206e7dffef
Parents: 16f978deb0ad4e42e55ecff757b4d7e744031e54
Message:added email management controller

Changes:

File differences

app/controllers/AdminController.php
1313
1414
1515
16
16
17
18
1719
1820
1921
public function home()
{
return View::make('admin.index');
$users = User::all();
return View::make('admin.index')->with('users', $users);
}
public function manageUsers()
app/controllers/EmailController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
class EmailController extends \BaseController {
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
}
/**
* Show the form for creating a new resource.
*
* @return Response
*/
public function create()
{
return View::make('emails.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$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);
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();
}
}
app/database/migrations/2014_07_12_172800_create_sent_emails_table.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateSentEmailsTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('sent_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();
});
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');
}
}
app/models/ReceivedEmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
class ReceivedEmail extends \Eloquent
{
protected $table = 'received_emails';
protected $softDelete = true;
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',
);
}
app/models/SentEmail.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
class SentEmail extends \Eloquent
{
protected $table = 'sent_emails';
protected $softDelete = true;
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',
);
}
app/routes.php
6464
6565
6666
67
6768
6869
6970
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');
});
vendor/autoload.php
44
55
66
7
7
require_once __DIR__ . '/composer' . '/autoload_real.php';
return ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221::getLoader();
return ComposerAutoloaderInitef59d4e967a29076ef0d253a93dee760::getLoader();
vendor/composer/autoload_classmap.php
3939
4040
4141
42
4243
4344
4445
'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',
vendor/composer/autoload_real.php
22
33
44
5
5
66
77
88
......
1919
2020
2121
22
22
2323
24
24
2525
2626
2727
......
4646
4747
4848
49
49
5050
5151
5252
5353
5454
5555
56
56
5757
5858
5959
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit28465c2db9863d424f6e7d76c6a98221
class ComposerAutoloaderInitef59d4e967a29076ef0d253a93dee760
{
private static $loader;
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());
$includeFiles = require __DIR__ . '/autoload_files.php';
foreach ($includeFiles as $file) {
composerRequire28465c2db9863d424f6e7d76c6a98221($file);
composerRequireef59d4e967a29076ef0d253a93dee760($file);
}
return $loader;
}
}
function composerRequire28465c2db9863d424f6e7d76c6a98221($file)
function composerRequireef59d4e967a29076ef0d253a93dee760($file)
{
require $file;
}

Archive Download the corresponding diff file

Branches

Number of commits:
Page rendered in 0.08394s using 13 queries.