@@ -14,7 +14,7 @@ component extends="app.Controllers.Controller" {
1414
1515 function blog () {
1616 blogs = getAllBlogs ();
17-
17+
1818 }
1919
2020 function approve () {
@@ -222,11 +222,27 @@ component extends="app.Controllers.Controller" {
222222
223223 private function blogApproval (id ){
224224 var blog = model (" Blog" ).findByKey (id );
225-
225+ var user = model (" user" ).findByKey (blog .createdby );
226+
226227 if (! isNull (blog )) {
227228
228229 blog .status = " Approved" ; // approved
229230 if (blog .save ()) {
231+ siteurl = " http://#cgi .http_host #/blog/#blog .slug #" ;
232+ emailContent = generateApprovalEmail (siteurl );
233+ cfheader (name = " Content-Type" value = " text/html; charset=UTF-8" );
234+ cfmail (
235+ to = " #user .email #" ,
236+ from = " #application .env .mail_from #" ,
237+ subject = " Your blog post has been approved and published" ,
238+ server = " #application .env .smtp_host #" ,
239+ port = " #application .env .smtp_port #" ,
240+ username = " #application .env .smtp_username #" ,
241+ password = " #application .env .smtp_password #" ,
242+ type = " html"
243+ ) {
244+ writeOutput (emailContent );
245+ };
230246 return {
231247 success = true ,
232248 message = " blog status approved successfully"
@@ -248,12 +264,28 @@ component extends="app.Controllers.Controller" {
248264
249265 private function blogReject (id ){
250266 var blog = model (" Blog" ).findByKey (id );
251-
267+ var user = model (" user" ).findByKey (blog .createdby );
268+
252269 if (! isNull (blog )) {
253270
254271 blog .status = " Rejected" ; // reject
255272
256273 if (blog .save ()) {
274+ siteurl = " http://#cgi .http_host #/blog/#blog .slug #" ;
275+ emailContent = generateRejectEmail (siteurl );
276+ cfheader (name = " Content-Type" value = " text/html; charset=UTF-8" );
277+ cfmail (
278+ to = " #user .email #" ,
279+ from = " #application .env .mail_from #" ,
280+ subject = " Your blog post has been Rejected to publish" ,
281+ server = " #application .env .smtp_host #" ,
282+ port = " #application .env .smtp_port #" ,
283+ username = " #application .env .smtp_username #" ,
284+ password = " #application .env .smtp_password #" ,
285+ type = " html"
286+ ) {
287+ writeOutput (emailContent );
288+ };
257289 return {
258290 success = true ,
259291 message = " blog status rejected successfully"
@@ -272,4 +304,141 @@ component extends="app.Controllers.Controller" {
272304 message = " blog not found"
273305 };
274306 }
307+
308+ private string function generateApprovalEmail (required string siteurl ) {
309+ return '
310+ <!DOCTYPE html>
311+ <html>
312+ <head>
313+ <meta charset="UTF-8">
314+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
315+ <title>Approve blog post</title>
316+ <style>
317+ body {
318+ font-family: Arial, sans-serif;
319+ background-color: ## f4f4f4;
320+ margin: 0;
321+ padding: 0;
322+ }
323+ .container {
324+ max-width: 600px;
325+ margin: 40px auto;
326+ background: ## ffffff;
327+ padding: 20px;
328+ border-radius: 8px;
329+ box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
330+ text-align: center;
331+ }
332+ .logo {
333+ width: 120px;
334+ margin-bottom: 20px;
335+ }
336+ h1 {
337+ color: ## 333;
338+ font-size: 24px;
339+ }
340+ p {
341+ color: ## 666;
342+ font-size: 16px;
343+ line-height: 1.5;
344+ }
345+ .button {
346+ display: inline-block;
347+ background-color: ## 007BFF;
348+ color: ## ffffff;
349+ text-decoration: none;
350+ font-size: 18px;
351+ padding: 12px 20px;
352+ border-radius: 6px;
353+ margin-top: 20px;
354+ }
355+ .footer {
356+ margin-top: 30px;
357+ font-size: 14px;
358+ color: ## 999;
359+ }
360+ </style>
361+ </head>
362+ <body>
363+
364+ <div class="container">
365+ <img src="https://avatars.githubusercontent.com/u/159224?s=200&v=4" alt="Bootstrap" width="260">
366+ <h1>Welcome to Wheels.dev!</h1>
367+ <p>Thank you for writing a blog post. Your post has been approved and published on the Wheels website.</p>
368+ <a href="' & siteurl & ' " class="button">View Your Post</a>
369+ <p class="footer">If you did not write blog, you can safely ignore this email.</p>
370+ </div>
371+
372+ </body>
373+ </html>
374+ ' ;
375+ }
376+
377+ private string function generateRejectEmail (required string siteurl ) {
378+ return '
379+ <!DOCTYPE html>
380+ <html>
381+ <head>
382+ <meta charset="UTF-8">
383+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
384+ <title>Reject blog post</title>
385+ <style>
386+ body {
387+ font-family: Arial, sans-serif;
388+ background-color: ## f4f4f4;
389+ margin: 0;
390+ padding: 0;
391+ }
392+ .container {
393+ max-width: 600px;
394+ margin: 40px auto;
395+ background: ## ffffff;
396+ padding: 20px;
397+ border-radius: 8px;
398+ box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
399+ text-align: center;
400+ }
401+ .logo {
402+ width: 120px;
403+ margin-bottom: 20px;
404+ }
405+ h1 {
406+ color: ## 333;
407+ font-size: 24px;
408+ }
409+ p {
410+ color: ## 666;
411+ font-size: 16px;
412+ line-height: 1.5;
413+ }
414+ .button {
415+ display: inline-block;
416+ background-color: ## 007BFF;
417+ color: ## ffffff;
418+ text-decoration: none;
419+ font-size: 18px;
420+ padding: 12px 20px;
421+ border-radius: 6px;
422+ margin-top: 20px;
423+ }
424+ .footer {
425+ margin-top: 30px;
426+ font-size: 14px;
427+ color: ## 999;
428+ }
429+ </style>
430+ </head>
431+ <body>
432+
433+ <div class="container">
434+ <img src="https://avatars.githubusercontent.com/u/159224?s=200&v=4" alt="Bootstrap" width="260">
435+ <h1>Welcome to Wheels.dev!</h1>
436+ <p>Thank you for writing a blog post. Your post has been rejected and not published on the Wheels website.</p>
437+ <p class="footer">If you did not write post, you can safely ignore this email.</p>
438+ </div>
439+
440+ </body>
441+ </html>
442+ ' ;
443+ }
275444}
0 commit comments