mirror of
				https://github.com/Mibew/mibew.git
				synced 2025-11-04 04:15:19 +03:00 
			
		
		
		
	Clean up "Chat\User\MailController" logic
This commit is contained in:
		
							parent
							
								
									e886e7dc33
								
							
						
					
					
						commit
						44ca9e2a2e
					
				@ -5,4 +5,4 @@
 | 
				
			|||||||
 You may obtain a copy of the License at
 | 
					 You may obtain a copy of the License at
 | 
				
			||||||
     http://www.apache.org/licenses/LICENSE-2.0
 | 
					     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,_);
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
					 You may obtain a copy of the License at
 | 
				
			||||||
     http://www.apache.org/licenses/LICENSE-2.0
 | 
					     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.
 | 
					 Copyright 2005-2014 the original author or authors.
 | 
				
			||||||
 Licensed under the Apache License, Version 2.0 (the "License").
 | 
					 Licensed under the Apache License, Version 2.0 (the "License").
 | 
				
			||||||
 | 
				
			|||||||
@ -44,10 +44,14 @@
 | 
				
			|||||||
                    var winParams = this.model.get('windowParams');
 | 
					                    var winParams = this.model.get('windowParams');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var style = page.get('style');
 | 
					                    var style = page.get('style');
 | 
				
			||||||
 | 
					                    var styleArg = '';
 | 
				
			||||||
 | 
					                    if (style) {
 | 
				
			||||||
 | 
					                        styleArg = ((link.indexOf('?') === -1) ? '?' : '&')
 | 
				
			||||||
 | 
					                            + 'style=' + style;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    // TODO: Kill & at the server side
 | 
					                    // TODO: Kill & at the server side
 | 
				
			||||||
                    link = link.replace(/\&\;/g, '&')
 | 
					                    link = link.replace(/\&\;/g, '&') + styleArg;
 | 
				
			||||||
                        + (style ? ('&style=' + style) : '');
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    var newWindow = window.open(link, 'ForwardMail', winParams);
 | 
					                    var newWindow = window.open(link, 'ForwardMail', winParams);
 | 
				
			||||||
                    if (newWindow !== null) {
 | 
					                    if (newWindow !== null) {
 | 
				
			||||||
 | 
				
			|||||||
@ -526,9 +526,8 @@ function setup_chatview_for_user(Thread $thread)
 | 
				
			|||||||
    $params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
 | 
					    $params = "thread=" . $thread->id . "&token=" . $thread->lastToken;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Set link to send mail page
 | 
					    // Set link to send mail page
 | 
				
			||||||
    $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/chat?"
 | 
					    $data['chat']['links']['mail'] = MIBEW_WEB_ROOT . "/chat"
 | 
				
			||||||
        . $params
 | 
					        . '/' . $thread->id . '/' . $thread->lastToken . '/mail';
 | 
				
			||||||
        . "&act=mailthread";
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Set SSL link
 | 
					    // Set SSL link
 | 
				
			||||||
    if (Settings::get('enablessl') == "1" && !is_secure_request()) {
 | 
					    if (Settings::get('enablessl') == "1" && !is_secure_request()) {
 | 
				
			||||||
 | 
				
			|||||||
@ -56,7 +56,7 @@ class ChatController extends AbstractController
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $action = $request->query->get('act');
 | 
					        $action = $request->query->get('act');
 | 
				
			||||||
        if (!in_array($action, array('invitation', 'mailthread'))) {
 | 
					        if ($action != 'invitation') {
 | 
				
			||||||
            $action = 'default';
 | 
					            $action = 'default';
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -101,15 +101,11 @@ class ChatController extends AbstractController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        $page = setup_chatview_for_user($thread);
 | 
					        $page = setup_chatview_for_user($thread);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($action == 'mailthread') {
 | 
					        // Build js application options
 | 
				
			||||||
            return $this->render('mail', $page);
 | 
					        $page['chatOptions'] = json_encode($page['chat']);
 | 
				
			||||||
        } else {
 | 
					 | 
				
			||||||
            // Build js application options
 | 
					 | 
				
			||||||
            $page['chatOptions'] = json_encode($page['chat']);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Expand page
 | 
					        // Expand page
 | 
				
			||||||
            return $this->render('chat', $page);
 | 
					        return $this->render('chat', $page);
 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected function startChat(Request $request)
 | 
					    protected function startChat(Request $request)
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@
 | 
				
			|||||||
namespace Mibew\Controller\Chat\User;
 | 
					namespace Mibew\Controller\Chat\User;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Mibew\Controller\Chat\AbstractController;
 | 
					use Mibew\Controller\Chat\AbstractController;
 | 
				
			||||||
use Mibew\Http\Exception\BadRequestException;
 | 
					use Mibew\Http\Exception\NotFoundException;
 | 
				
			||||||
use Mibew\Settings;
 | 
					use Mibew\Settings;
 | 
				
			||||||
use Mibew\Thread;
 | 
					use Mibew\Thread;
 | 
				
			||||||
use Symfony\Component\HttpFoundation\Request;
 | 
					use Symfony\Component\HttpFoundation\Request;
 | 
				
			||||||
@ -29,57 +29,79 @@ use Symfony\Component\HttpFoundation\Request;
 | 
				
			|||||||
class MailController extends AbstractController
 | 
					class MailController extends AbstractController
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * Process sending chat history to an email.
 | 
					     * Renders the mail form.
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     * @param Request $request Incoming request.
 | 
					     * @param Request $request Incoming request.
 | 
				
			||||||
     * @return string|\Symfony\Component\HttpFoundation\RedirectResponse Rendered
 | 
					     * @return string Rendered page content.
 | 
				
			||||||
     *   page content or a redirect response.
 | 
					     * @throws NotFoundException If the thread with specified ID and token is
 | 
				
			||||||
     * @throws BadRequestException If the thread cannot be loaded by some
 | 
					     * not found.
 | 
				
			||||||
     * reasons.
 | 
					 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    public function indexAction(Request $request)
 | 
					    public function showFormAction(Request $request)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        $page = array(
 | 
					        $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->attributes->get('thread_id');
 | 
				
			||||||
        $thread_id = $request->request->get('thread');
 | 
					        $token = $request->attributes->get('token');
 | 
				
			||||||
        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.');
 | 
					 | 
				
			||||||
        }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Try to load the thread
 | 
				
			||||||
        $thread = Thread::load($thread_id, $token);
 | 
					        $thread = Thread::load($thread_id, $token);
 | 
				
			||||||
        if (!$thread) {
 | 
					        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');
 | 
					        $email = $request->request->get('email');
 | 
				
			||||||
        $page['email'] = $email;
 | 
					 | 
				
			||||||
        $group = is_null($thread->groupId) ? null : group_by_id($thread->groupId);
 | 
					        $group = is_null($thread->groupId) ? null : group_by_id($thread->groupId);
 | 
				
			||||||
        if (!$email) {
 | 
					        if (!$email) {
 | 
				
			||||||
            $page['errors'][] = no_field('form.field.email');
 | 
					            $errors[] = no_field('form.field.email');
 | 
				
			||||||
        } elseif (!is_valid_email($email)) {
 | 
					        } elseif (!is_valid_email($email)) {
 | 
				
			||||||
            $page['errors'][] = wrong_field('form.field.email');
 | 
					            $errors[] = wrong_field('form.field.email');
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (count($page['errors']) > 0) {
 | 
					        if (count($errors) > 0) {
 | 
				
			||||||
            $page['formemail'] = $email;
 | 
					            $request->attributes->set('errors', $errors);
 | 
				
			||||||
            $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);
 | 
					            // Render the mail form again
 | 
				
			||||||
 | 
					            return $this->showFormAction($request);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $history = '';
 | 
					        $history = '';
 | 
				
			||||||
@ -102,7 +124,8 @@ class MailController extends AbstractController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        mibew_mail($email, MIBEW_MAILBOX, $subject, $body);
 | 
					        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);
 | 
					        return $this->render('mailsent', $page);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -43,9 +43,22 @@ chat_user:
 | 
				
			|||||||
        _controller: Mibew\Controller\Chat\User\ChatController::indexAction
 | 
					        _controller: Mibew\Controller\Chat\User\ChatController::indexAction
 | 
				
			||||||
 | 
					
 | 
				
			||||||
chat_user_mail:
 | 
					chat_user_mail:
 | 
				
			||||||
    path: /chat/mail
 | 
					    path: /chat/{thread_id}/{token}/mail
 | 
				
			||||||
    defaults:
 | 
					    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
 | 
					# Pages that are available for all users
 | 
				
			||||||
button:
 | 
					button:
 | 
				
			||||||
 | 
				
			|||||||
@ -8,10 +8,8 @@
 | 
				
			|||||||
    {{/override}}
 | 
					    {{/override}}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    {{#override "message"}}
 | 
					    {{#override "message"}}
 | 
				
			||||||
        <form name="mailThreadForm" method="post" action="{{mibewRoot}}/chat/mail">
 | 
					        <form name="mailThreadForm" method="post" action="{{mibewRoot}}/chat/{{this.[chat.thread.id]}}/{{this.[chat.thread.token]}}/mail">
 | 
				
			||||||
            <input type="hidden" name="style" value="{{styleName}}"/>
 | 
					            <input type="hidden" name="style" value="{{styleName}}"/>
 | 
				
			||||||
            <input type="hidden" name="thread" value="{{chat.thread.id}}"/>
 | 
					 | 
				
			||||||
            <input type="hidden" name="token" value="{{chat.thread.token}}"/>
 | 
					 | 
				
			||||||
            <input type="hidden" name="level" value="{{level}}"/>
 | 
					            <input type="hidden" name="level" value="{{level}}"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            <strong>{{l10n "mailthread.enter_email"}}</strong>
 | 
					            <strong>{{l10n "mailthread.enter_email"}}</strong>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user