mirror of
https://github.com/Mibew/mibew.git
synced 2025-03-03 18:38:31 +03:00
Replace "operator/invite.php" with a controller
This commit is contained in:
parent
938c4cbd69
commit
f4129ff8ee
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Copyright 2005-2014 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Mibew\Controller;
|
||||||
|
|
||||||
|
use Mibew\Http\Exception\BadRequestException;
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contains actions which are related with invitations.
|
||||||
|
*/
|
||||||
|
class InvitationController extends AbstractController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Invites a visitor to chat.
|
||||||
|
*
|
||||||
|
* @param Request $request
|
||||||
|
* @return string Rendered page content
|
||||||
|
*/
|
||||||
|
public function inviteAction(Request $request)
|
||||||
|
{
|
||||||
|
$operator = $request->attributes->get('_operator');
|
||||||
|
|
||||||
|
// Get visitor ID from the request and check it
|
||||||
|
$visitor_id = $request->query->get('visitor');
|
||||||
|
if (!preg_match("/^\d{1,10}$/", $visitor_id)) {
|
||||||
|
throw new BadRequestException('Wrong format of visitor param.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to invite the visitor
|
||||||
|
$thread = invitation_invite($visitor_id, $operator);
|
||||||
|
if (!$thread) {
|
||||||
|
return new Response('Invitation failed!');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Open chat window for operator
|
||||||
|
$redirect_to = $request->getBasePath()
|
||||||
|
. '/operator/agent.php?thread=' . intval($thread->id)
|
||||||
|
. '&token=' . urlencode($thread->lastToken);
|
||||||
|
|
||||||
|
return $this->redirect($redirect_to);
|
||||||
|
}
|
||||||
|
}
|
@ -162,6 +162,13 @@ history_user_track:
|
|||||||
_controller: Mibew\Controller\HistoryController::userTrackAction
|
_controller: Mibew\Controller\HistoryController::userTrackAction
|
||||||
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||||
|
|
||||||
|
## Invitations
|
||||||
|
invite:
|
||||||
|
path: /operator/invite
|
||||||
|
defaults:
|
||||||
|
_controller: Mibew\Controller\InvitationController::inviteAction
|
||||||
|
_access_check: Mibew\AccessControl\Check\LoggedInCheck
|
||||||
|
|
||||||
## Password recovery
|
## Password recovery
|
||||||
password_recovery:
|
password_recovery:
|
||||||
path: /operator/password-recovery
|
path: /operator/password-recovery
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
<?php
|
|
||||||
/*
|
|
||||||
* Copyright 2005-2014 the original author or authors.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
require_once(dirname(dirname(__FILE__)) . '/libs/init.php');
|
|
||||||
|
|
||||||
$operator = check_login();
|
|
||||||
|
|
||||||
$visitor_id = verify_param("visitor", "/^\d{1,8}$/");
|
|
||||||
|
|
||||||
$thread = invitation_invite($visitor_id, $operator);
|
|
||||||
if (!$thread) {
|
|
||||||
die("Invitation failed!");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open chat window for operator
|
|
||||||
$redirect_to = MIBEW_WEB_ROOT
|
|
||||||
. '/operator/agent.php?thread=' . intval($thread->id)
|
|
||||||
. '&token=' . urlencode($thread->lastToken);
|
|
||||||
header('Location: ' . $redirect_to);
|
|
@ -102,7 +102,7 @@
|
|||||||
geoLink: "{{geoLink}}",
|
geoLink: "{{geoLink}}",
|
||||||
trackedLink: "{{mibewRoot}}/operator/history/user-track",
|
trackedLink: "{{mibewRoot}}/operator/history/user-track",
|
||||||
banLink: "{{mibewRoot}}/operator/ban.php",
|
banLink: "{{mibewRoot}}/operator/ban.php",
|
||||||
inviteLink: "{{mibewRoot}}/operator/invite.php",
|
inviteLink: "{{mibewRoot}}/operator/invite",
|
||||||
|
|
||||||
chatWindowParams: "{{[chatStyles.chatWindowParams]}}",
|
chatWindowParams: "{{[chatStyles.chatWindowParams]}}",
|
||||||
geoWindowParams: "{{geoWindowParams}}",
|
geoWindowParams: "{{geoWindowParams}}",
|
||||||
|
Loading…
Reference in New Issue
Block a user