diff --git a/src/mibew/js/compiled/chat/model_views/controls/send_mail.js b/src/mibew/js/compiled/chat/model_views/controls/send_mail.js index 70c1be10..5ddc6c26 100644 --- a/src/mibew/js/compiled/chat/model_views/controls/send_mail.js +++ b/src/mibew/js/compiled/chat/model_views/controls/send_mail.js @@ -5,4 +5,4 @@ You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(b,d,e){b.Views.SendMailControl=b.Views.Control.extend({template:d.templates.chat_controls_send_mail,events:e.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link"),c=b.Objects.Models.page;if(a){var d=this.model.get("windowParams"),c=c.get("style"),a=a.replace(/\&\;/g,"&")+(c?"&style="+c:""),a=window.open(a,"ForwardMail",d);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_); +(function(b,d,f){b.Views.SendMailControl=b.Views.Control.extend({template:d.templates.chat_controls_send_mail,events:f.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link"),c=b.Objects.Models.page;if(a){var d=this.model.get("windowParams"),c=c.get("style"),e="";c&&(e=(-1===a.indexOf("?")?"?":"&")+"style="+c);a=a.replace(/\&\;/g,"&")+e;a=window.open(a,"ForwardMail",d);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_); diff --git a/src/mibew/js/compiled/chat_app.js b/src/mibew/js/compiled/chat_app.js index 7be91ff7..4f8d1e30 100644 --- a/src/mibew/js/compiled/chat_app.js +++ b/src/mibew/js/compiled/chat_app.js @@ -230,7 +230,7 @@ d="";c&&(d=(-1===a.indexOf("?")?"?":"&")+"style="+c);window.location.href=a.repl You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 */ -(function(b,d,e){b.Views.SendMailControl=b.Views.Control.extend({template:d.templates.chat_controls_send_mail,events:e.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link"),c=b.Objects.Models.page;if(a){var d=this.model.get("windowParams"),c=c.get("style"),a=a.replace(/\&\;/g,"&")+(c?"&style="+c:""),a=window.open(a,"ForwardMail",d);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_); +(function(b,d,f){b.Views.SendMailControl=b.Views.Control.extend({template:d.templates.chat_controls_send_mail,events:f.extend({},b.Views.Control.prototype.events,{click:"sendMail"}),sendMail:function(){var a=this.model.get("link"),c=b.Objects.Models.page;if(a){var d=this.model.get("windowParams"),c=c.get("style"),e="";c&&(e=(-1===a.indexOf("?")?"?":"&")+"style="+c);a=a.replace(/\&\;/g,"&")+e;a=window.open(a,"ForwardMail",d);null!==a&&(a.focus(),a.opener=window)}}})})(Mibew,Handlebars,_); /* Copyright 2005-2014 the original author or authors. Licensed under the Apache License, Version 2.0 (the "License"). diff --git a/src/mibew/js/source/chat/model_views/controls/send_mail.js b/src/mibew/js/source/chat/model_views/controls/send_mail.js index b159d7fb..d9357aaa 100644 --- a/src/mibew/js/source/chat/model_views/controls/send_mail.js +++ b/src/mibew/js/source/chat/model_views/controls/send_mail.js @@ -44,10 +44,14 @@ var winParams = this.model.get('windowParams'); var style = page.get('style'); + var styleArg = ''; + if (style) { + styleArg = ((link.indexOf('?') === -1) ? '?' : '&') + + 'style=' + style; + } // TODO: Kill & at the server side - link = link.replace(/\&\;/g, '&') - + (style ? ('&style=' + style) : ''); + link = link.replace(/\&\;/g, '&') + styleArg; var newWindow = window.open(link, 'ForwardMail', winParams); if (newWindow !== null) { diff --git a/src/mibew/libs/chat.php b/src/mibew/libs/chat.php index b600b3ec..7c2af4ce 100644 --- a/src/mibew/libs/chat.php +++ b/src/mibew/libs/chat.php @@ -526,9 +526,8 @@ function setup_chatview_for_user(Thread $thread) $params = "thread=" . $thread->id . "&token=" . $thread->lastToken; // Set link to send mail page - $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/chat?" - . $params - . "&act=mailthread"; + $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/chat" + . '/' . $thread->id . '/' . $thread->lastToken . '/mail'; // Set SSL link if (Settings::get('enablessl') == "1" && !is_secure_request()) { diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php index 81cfd1d1..03ff928b 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/User/ChatController.php @@ -56,7 +56,7 @@ class ChatController extends AbstractController } $action = $request->query->get('act'); - if (!in_array($action, array('invitation', 'mailthread'))) { + if ($action != 'invitation') { $action = 'default'; } @@ -101,15 +101,11 @@ class ChatController extends AbstractController $page = setup_chatview_for_user($thread); - if ($action == 'mailthread') { - return $this->render('mail', $page); - } else { - // Build js application options - $page['chatOptions'] = json_encode($page['chat']); + // Build js application options + $page['chatOptions'] = json_encode($page['chat']); - // Expand page - return $this->render('chat', $page); - } + // Expand page + return $this->render('chat', $page); } protected function startChat(Request $request) diff --git a/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php b/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php index 7c1e4879..ee96cac1 100644 --- a/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php +++ b/src/mibew/libs/classes/Mibew/Controller/Chat/User/MailController.php @@ -18,7 +18,7 @@ namespace Mibew\Controller\Chat\User; use Mibew\Controller\Chat\AbstractController; -use Mibew\Http\Exception\BadRequestException; +use Mibew\Http\Exception\NotFoundException; use Mibew\Settings; use Mibew\Thread; use Symfony\Component\HttpFoundation\Request; @@ -29,57 +29,79 @@ use Symfony\Component\HttpFoundation\Request; class MailController extends AbstractController { /** - * Process sending chat history to an email. + * Renders the mail form. * * @param Request $request Incoming request. - * @return string|\Symfony\Component\HttpFoundation\RedirectResponse Rendered - * page content or a redirect response. - * @throws BadRequestException If the thread cannot be loaded by some - * reasons. + * @return string Rendered page content. + * @throws NotFoundException If the thread with specified ID and token is + * not found. */ - public function indexAction(Request $request) + public function showFormAction(Request $request) { $page = array( - 'errors' => array(), + // Use errors list stored in the request. We need to do so to have + // an ability to pass the request from the "submitForm" action. + 'errors' => $request->attributes->get('errors', array()), ); - // Get and validate thread id - $thread_id = $request->request->get('thread'); - if (!preg_match("/^\d{1,10}$/", $thread_id)) { - throw new BadRequestException('Wrong value of "thread" argument.'); - } - - // Get token and verify it - $token = $request->request->get('token'); - if (!preg_match("/^\d{1,10}$/", $token)) { - throw new BadRequestException('Wrong value of "token" argument.'); - } + $thread_id = $request->attributes->get('thread_id'); + $token = $request->attributes->get('token'); + // Try to load the thread $thread = Thread::load($thread_id, $token); if (!$thread) { - throw new BadRequestException('Wrong thread.'); + throw new NotFoundException('The thread is not found.'); + } + + $email = $request->request->get('email', ''); + $group = is_null($thread->groupId) ? null : group_by_id($thread->groupId); + + $page['formemail'] = $email; + $page['chat.thread.id'] = $thread->id; + $page['chat.thread.token'] = $thread->lastToken; + $page['level'] = ''; + $page = array_merge_recursive( + $page, + setup_logo($group) + ); + + return $this->render('mail', $page); + } + + /** + * Process submitting of the mail form. + * + * @param Request $request Incoming request. + * @return string Rendered page content. + * @throws NotFoundException If the thread with specified ID and token is + * not found. + */ + public function submitFormAction(Request $request) + { + $errors = array(); + + $thread_id = $request->attributes->get('thread_id'); + $token = $request->attributes->get('token'); + + // Try to load the thread + $thread = Thread::load($thread_id, $token); + if (!$thread) { + throw new NotFoundException('The thread is not found.'); } $email = $request->request->get('email'); - $page['email'] = $email; $group = is_null($thread->groupId) ? null : group_by_id($thread->groupId); if (!$email) { - $page['errors'][] = no_field('form.field.email'); + $errors[] = no_field('form.field.email'); } elseif (!is_valid_email($email)) { - $page['errors'][] = wrong_field('form.field.email'); + $errors[] = wrong_field('form.field.email'); } - if (count($page['errors']) > 0) { - $page['formemail'] = $email; - $page['chat.thread.id'] = $thread->id; - $page['chat.thread.token'] = $thread->lastToken; - $page['level'] = ''; - $page = array_merge_recursive( - $page, - setup_logo($group) - ); + if (count($errors) > 0) { + $request->attributes->set('errors', $errors); - return $this->render('mail', $page); + // Render the mail form again + return $this->showFormAction($request); } $history = ''; @@ -102,7 +124,8 @@ class MailController extends AbstractController mibew_mail($email, MIBEW_MAILBOX, $subject, $body); - $page = array_merge_recursive($page, setup_logo($group)); + $page = setup_logo($group); + $page['email'] = $email; return $this->render('mailsent', $page); } diff --git a/src/mibew/libs/routing.yml b/src/mibew/libs/routing.yml index 40ad8644..5a90923b 100644 --- a/src/mibew/libs/routing.yml +++ b/src/mibew/libs/routing.yml @@ -43,9 +43,22 @@ chat_user: _controller: Mibew\Controller\Chat\User\ChatController::indexAction chat_user_mail: - path: /chat/mail + path: /chat/{thread_id}/{token}/mail defaults: - _controller: Mibew\Controller\Chat\User\MailController::indexAction + _controller: Mibew\Controller\Chat\User\MailController::showFormAction + requirements: + thread_id: \d{1,10} + token: \d{1,10} + methods: [GET] + +chat_user_mail_send: + path: /chat/{thread_id}/{token}/mail + defaults: + _controller: Mibew\Controller\Chat\User\MailController::submitFormAction + requirements: + thread_id: \d{1,10} + token: \d{1,10} + methods: [POST] # Pages that are available for all users button: diff --git a/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars b/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars index ef0b0581..f4594db8 100644 --- a/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars +++ b/src/mibew/styles/dialogs/default/templates_src/server_side/mail.handlebars @@ -8,10 +8,8 @@ {{/override}} {{#override "message"}} -