diff --git a/coreui/src/router/index.js b/coreui/src/router/index.js index f48da9ad0..50adef161 100644 --- a/coreui/src/router/index.js +++ b/coreui/src/router/index.js @@ -84,6 +84,13 @@ const Resource = () => import('@/views/resources/Resource') const EditResource = () => import('@/views/resources/EditResource') const DeleteResource = () => import('@/views/resources/DeleteResource') +//Email +const Emails = () => import('@/views/email/Emails') +const CreateEmail = () => import('@/views/email/CreateEmail') +const EditEmail = () => import('@/views/email/EditEmail') +const ShowEmail = () => import('@/views/email/ShowEmail') +const SendEmail = () => import('@/views/email/SendEmail') + const EditMenu = () => import('@/views/menu/EditMenu') const Media = () => import('@/views/media/Media') @@ -212,7 +219,7 @@ function configRoutes () { { path: 'create', meta: { label: 'Create Role' }, - name: 'Create Note', + name: 'Create Role', component: CreateRole }, { @@ -266,6 +273,43 @@ function configRoutes () { }, ] }, + { + path: 'email', + meta: { label: 'Emails'}, + component: { + render (c) { return c('router-view') } + }, + children: [ + { + path: '', + component: Emails, + }, + { + path: 'create', + meta: { label: 'Create Email Template' }, + name: 'Create Email Template', + component: CreateEmail + }, + { + path: ':id', + meta: { label: 'Show Email Template'}, + name: 'Show Email Tempalte', + component: ShowEmail, + }, + { + path: ':id/edit', + meta: { label: 'Edit Email Tempalate' }, + name: 'Edit Email Template', + component: EditEmail + }, + { + path: ':id/sendEmail', + meta: { label: 'Send Email' }, + name: 'Send Email', + component: SendEmail + }, + ] + }, { path: 'resource', meta: { label: 'Resources'}, diff --git a/coreui/src/views/email/CreateEmail.vue b/coreui/src/views/email/CreateEmail.vue new file mode 100644 index 000000000..86afdcd84 --- /dev/null +++ b/coreui/src/views/email/CreateEmail.vue @@ -0,0 +1,93 @@ + + + diff --git a/coreui/src/views/email/EditEmail.vue b/coreui/src/views/email/EditEmail.vue new file mode 100644 index 000000000..c13b5d66f --- /dev/null +++ b/coreui/src/views/email/EditEmail.vue @@ -0,0 +1,94 @@ + + + diff --git a/coreui/src/views/email/Emails.vue b/coreui/src/views/email/Emails.vue new file mode 100644 index 000000000..6cee506ae --- /dev/null +++ b/coreui/src/views/email/Emails.vue @@ -0,0 +1,148 @@ + + + + + \ No newline at end of file diff --git a/coreui/src/views/email/SendEmail.vue b/coreui/src/views/email/SendEmail.vue new file mode 100644 index 000000000..4ed07cee5 --- /dev/null +++ b/coreui/src/views/email/SendEmail.vue @@ -0,0 +1,93 @@ + + + diff --git a/coreui/src/views/email/ShowEmail.vue b/coreui/src/views/email/ShowEmail.vue new file mode 100644 index 000000000..6b22a31c8 --- /dev/null +++ b/coreui/src/views/email/ShowEmail.vue @@ -0,0 +1,50 @@ + + + diff --git a/laravel/app/Http/Controllers/MailController.php b/laravel/app/Http/Controllers/MailController.php new file mode 100644 index 000000000..ec389755d --- /dev/null +++ b/laravel/app/Http/Controllers/MailController.php @@ -0,0 +1,119 @@ +json( $emailTemplates ); + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return \Illuminate\Http\Response + */ + public function store(Request $request) + { + $validatedData = $request->validate([ + 'name' => 'required|min:1|max:64', + 'subject' => 'required|min:1|max:128', + 'content' => 'required|min:1', + ]); + $template = new EmailTemplate(); + $template->name = $request->input('name'); + $template->subject = $request->input('subject'); + $template->content = $request->input('content'); + $template->save(); + return response()->json( ['status' => 'success'] ); + } + + /** + * Display the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function show($id) + { + return response()->json( [ 'template' => EmailTemplate::find($id) ] ); + } + + /** + * Show the form for editing the specified resource. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function edit($id) + { + return response()->json( [ 'template' => EmailTemplate::find($id) ] ); + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function update(Request $request, $id) + { + $validatedData = $request->validate([ + 'name' => 'required|min:1|max:64', + 'subject' => 'required|min:1|max:128', + 'content' => 'required|min:1', + ]); + $template = EmailTemplate::find($id); + $template->name = $request->input('name'); + $template->subject = $request->input('subject'); + $template->content = $request->input('content'); + $template->save(); + return response()->json( ['status' => 'success'] ); + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return \Illuminate\Http\Response + */ + public function destroy($id, Request $request) + { + $template = EmailTemplate::find($id); + if($template){ + $template->delete(); + } + return response()->json( ['status' => 'success'] ); + } + + public function prepareSend($id){ + return response()->json( [ 'template' => EmailTemplate::find($id) ] ); + } + + public function send($id, Request $request){ + $validatedData = $request->validate([ + 'email' => 'required|email', + ]); + $template = EmailTemplate::find($id); + Mail::send([], [], function ($message) use ($request, $template) + { + $message->to($request->input('email')); + $message->subject($template->subject); + $message->setBody($template->content,'text/html'); + }); + return response()->json( ['status' => 'success'] ); + } +} diff --git a/laravel/app/Models/EmailTemplate.php b/laravel/app/Models/EmailTemplate.php new file mode 100644 index 000000000..b6b065aba --- /dev/null +++ b/laravel/app/Models/EmailTemplate.php @@ -0,0 +1,11 @@ +bigIncrements('id'); + $table->timestamps(); + $table->text('content'); + $table->string('name'); + $table->string('subject'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('email_template'); + } +} diff --git a/laravel/database/seeds/DatabaseSeeder.php b/laravel/database/seeds/DatabaseSeeder.php index ae22e5e1d..153173fd5 100644 --- a/laravel/database/seeds/DatabaseSeeder.php +++ b/laravel/database/seeds/DatabaseSeeder.php @@ -19,5 +19,6 @@ public function run() $this->call('FolderTableSeeder'); $this->call('ExampleSeeder'); $this->call('BREADSeeder'); + $this->call('EmailSeeder'); } } diff --git a/laravel/database/seeds/EmailSeeder.php b/laravel/database/seeds/EmailSeeder.php new file mode 100644 index 000000000..b4ab4cf03 --- /dev/null +++ b/laravel/database/seeds/EmailSeeder.php @@ -0,0 +1,97 @@ +insert([ + 'name' => 'Example E-mail', + 'subject' => 'Example E-mail', + 'content' => + ' + + + + + + + Example + + + +
+

Lorem ipsum dolor

+

Ipsum dolor cet emit amet

+

+ Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. + Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +

+

Ipsum dolor cet emit amet

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +

+

Ipsum dolor cet emit amet

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +

+ Lorem ipsum dolor +

Ipsum dolor cet emit amet

+

+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. + Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. + Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. +

+
+ + ', + ]); + } +} diff --git a/laravel/database/seeds/MenusTableSeeder.php b/laravel/database/seeds/MenusTableSeeder.php index 786da510c..778a8220d 100644 --- a/laravel/database/seeds/MenusTableSeeder.php +++ b/laravel/database/seeds/MenusTableSeeder.php @@ -137,6 +137,7 @@ public function run() $this->insertLink('admin', 'Users', '/users'); $this->insertLink('admin', 'Menu', '/menu'); $this->insertLink('admin', 'BREAD', '/bread'); + $this->insertLink('admin', 'Email', '/email'); $this->endDropdown(); $this->insertTitle('user,admin', 'Theme'); $this->insertLink('user,admin', 'Colors', '/colors', 'cil-drop'); diff --git a/laravel/routes/api.php b/laravel/routes/api.php index a6fb87ed7..e4189e326 100644 --- a/laravel/routes/api.php +++ b/laravel/routes/api.php @@ -26,7 +26,11 @@ Route::resource('resource/{table}/resource', 'ResourceController'); Route::group(['middleware' => 'admin'], function ($router) { - + + Route::resource('mail', 'MailController'); + Route::get('prepareSend/{id}', 'MailController@prepareSend')->name('prepareSend'); + Route::post('mailSend/{id}', 'MailController@send')->name('mailSend'); + Route::resource('bread', 'BreadController'); //create BREAD (resource) Route::resource('users', 'UsersController')->except( ['create', 'store'] );