diff --git a/.env.example b/.env.example index e6bbb76..b3d05f6 100644 --- a/.env.example +++ b/.env.example @@ -29,6 +29,9 @@ MAIL_USERNAME=null MAIL_PASSWORD=null MAIL_ENCRYPTION=null +MAIL_RPC_HOST=127.0.0.1 +MAIL_RPC_PORT=65525 + ALLOW_REG=false # 大一同学的入学年份(两位),用来判断用户是否过期 FRESH_YEAR=16 diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index 9d1f161..8521a20 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -11,7 +11,7 @@ use App\User; use App\Announcement; use App\Http\Controllers\Controller; use App\Ticket; - +use JsonRpcClient; use App\Transaction; use Mews\Purifier\Purifier; @@ -174,6 +174,20 @@ class AdminController extends Controller return Redirect::to('/admin'); } + // This part gonna work with https://github.com/NEUP-Net-Depart/email-daemon/ + public function testEmail(Request $request) + { + $conn = new JsonRpcClient("127.0.0.1", 65525); + $mailSettings = []; + $mailSettings["Body"] = view('auth.checkLetter')->with(['host' => $request->server("HTTP_HOST"), 'token' => "sometesttokenhhhh"])->render(); + $mailSettings["To"] = "wangkule@cool2645.com"; + $mailSettings["FromName"] = "先锋市场"; + $mailSettings["Subject"] = "PHP 邮件测试"; + $mailSettings["SendID"] = "notify"; + $response = $conn->Call("Daemon.SendMail", $mailSettings); + return $response; + } + /** * @function AdminController@getAnnouncement * @input Request $request diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 45f583d..90a3787 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -16,7 +16,7 @@ use App\Http\Requests\ResetPassRequest; use App\User; use App\CheckEmail; use App\PasswordReset; -use Mail; +use JsonRpcClient; use Illuminate\Support\Facades\Storage; use App\AuthLog; use phpCAS; @@ -259,11 +259,16 @@ class AuthController extends Controller $time = time(); $data['token'] = base64_encode($token . "#" . $time . "#" . $email . "#" . substr(sha1($time . $email . env('APP_KEY')), 0, 6)); $data['host'] = $request->server("HTTP_HOST"); - if (env('APP_ENV') != "testing") - Mail::send('auth.checkLetter', $data, function ($m) use ($user, $email) { - $m->from(env('MAIL_USERNAME'), "先锋市场"); - $m->to($email, $user->username)->subject('验证你的邮箱'); - }); + if (env('APP_ENV') != "testing") { + $conn = new JsonRpcClient(env('MAIL_RPC_HOST', "127.0.0.1"), env('MAIL_RPC_PORT', 65525)); + $mailSettings = []; + $mailSettings["Body"] = view('auth.checkLetter')->with($data)->render(); + $mailSettings["To"] = $email; + $mailSettings["FromName"] = "先锋市场"; + $mailSettings["Subject"] = "验证你的邮箱"; + $mailSettings["SendID"] = "service"; + $conn->Call("Daemon.SendMail", $mailSettings); + } self::log($user->id, "sendcheckletter", $request); } @@ -295,11 +300,16 @@ class AuthController extends Controller $time = time(); $data['token'] = base64_encode($token . "#" . $time . "#" . $email . "#" . substr(sha1($time . $email . env('APP_KEY')), 0, 6)); $data['host'] = $request->server("HTTP_HOST"); - if (env('APP_ENV') != "testing") - Mail::send('auth.unbindLetter', $data, function ($m) use ($user, $email) { - $m->from(env('MAIL_USERNAME'), "先锋市场"); - $m->to($email, $user->username)->subject('邮箱解绑请求'); - }); + if (env('APP_ENV') != "testing") { + $conn = new JsonRpcClient(env('MAIL_RPC_HOST', "127.0.0.1"), env('MAIL_RPC_PORT', 65525)); + $mailSettings = []; + $mailSettings["Body"] = view('auth.unbindLetter')->with($data)->render(); + $mailSettings["To"] = $email; + $mailSettings["FromName"] = "先锋市场"; + $mailSettings["Subject"] = "邮箱解绑请求"; + $mailSettings["SendID"] = "service"; + $conn->Call("Daemon.SendMail", $mailSettings); + } self::log($user->id, "sendunbindletter", $request); } @@ -442,11 +452,16 @@ class AuthController extends Controller $time = time(); $data['token'] = base64_encode($token . "#" . $time . "#" . substr(sha1($time . env('APP_KEY')), 0, 6)); $data['host'] = $request->server("HTTP_HOST"); - if (env('APP_ENV') != "testing") - Mail::send('auth.resetLetter', $data, function ($m) use ($user, $email) { - $m->from(env('MAIL_USERNAME'), '先锋市场'); - $m->to($email, $user->username)->subject('重置密码'); - }); + if (env('APP_ENV') != "testing") { + $conn = new JsonRpcClient(env('MAIL_RPC_HOST', "127.0.0.1"), env('MAIL_RPC_PORT', 65525)); + $mailSettings = []; + $mailSettings["Body"] = view('auth.resetLetter')->with($data)->render(); + $mailSettings["To"] = $email; + $mailSettings["FromName"] = "先锋市场"; + $mailSettings["Subject"] = "重置密码"; + $mailSettings["SendID"] = "service"; + $conn->Call("Daemon.SendMail", $mailSettings); + } $this->log($user->id, "sendpwdresetletter", $request); diff --git a/app/Http/Controllers/GoodController.php b/app/Http/Controllers/GoodController.php index 01ed411..d0655c6 100644 --- a/app/Http/Controllers/GoodController.php +++ b/app/Http/Controllers/GoodController.php @@ -127,18 +127,6 @@ class GoodController extends Controller return view::make('good.goodList')->with($data); } - public function check(Request $request) - { - $data = []; - $user_id = $request->session()->get('user_id'); - $data['goods'] = Transaction::where('seller_id',$user_id)->where('status',1)->get(); - $data['sells'] = Transaction::where('seller_id',$user_id)->where('status',2)->get(); - $data['mysells'] = Transaction::where('seller_id',$user_id)->where('status',4)->get(); - $data['users'] = Transaction::where('buyer_id',$user_id)->where('status',3)->get(); - $data['transactions'] = Transaction::where('buyer_id',$user_id)->where('status',2)->get(); - return view::make('good.goodCheck')->with($data); - } - /** * @function GoodController@getInfo * @input Request $request, $good_id diff --git a/app/Http/Controllers/MessageController.php b/app/Http/Controllers/MessageController.php index 0b71740..3e52f79 100644 --- a/app/Http/Controllers/MessageController.php +++ b/app/Http/Controllers/MessageController.php @@ -18,6 +18,7 @@ use App\Message; use App\User; use App\MessageContact; use App\Http\Controllers\Controller; +use Mews\Purifier\PurifierServiceProvider; class MessageController extends Controller { @@ -83,7 +84,7 @@ class MessageController extends Controller //Create Message $message = new Message; $user_id = $sender; - $message->content = $content; + $message->content = clean($content); $message->sender_id = $user_id; $message->receiver_id = $receiver; $message->save(); diff --git a/app/Http/routes.php b/app/Http/routes.php index e9a99c2..76f51a7 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -142,6 +142,7 @@ Route::group(['middleware' => ['web']],function () { Route::delete('/notice/{ann_id}', "AdminController@delAnnouncement")->middleware('admin'); Route::get('/admin', "AdminController@adminIndex")->middleware('admin'); + Route::get('/test/email', "AdminController@testEmail")->middleware('su'); Route::post('/user/{user_id}/updatePriv', [ "uses" => "AdminController@updateUserPriv", diff --git a/app/JsonRpcClient.php b/app/JsonRpcClient.php new file mode 100644 index 0000000..c55347a --- /dev/null +++ b/app/JsonRpcClient.php @@ -0,0 +1,95 @@ +. +// All rights reserved. +// This program comes with ABSOLUTELY NO WARRANTY; +// Use of this source code is governed by a free software license, +// for details visit http://www.gnu.org/licenses/lgpl.html + +/* + Simple PHP JsonRPC client through raw tcp connection. + Socket connections follow lazy open pattern and are closed + during object destruction. + */ +class JsonRpcException extends Exception {} + +class JsonRpcClient { + private $address; + private $port; + private $socket; + + public function __construct($address, $port) { + $this->address = $address; + $this->port = $port; + $this->socket = false; + } + + public function __desctructor() { + if ($this->socket) { + socket_close($this->socket); + } + } + + public function __open() { + if (($this->socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { + throw new JsonRpcException("socket_create() failed: reason: " . socket_strerror(socket_last_error())); + } + } + + private function generateId() { + $chars = array_merge(range('A', 'Z'), range('a', 'z'), range(0, 9)); + $id = ''; + for($c = 0; $c < 16; ++$c) + $id .= $chars[mt_rand(0, count($chars) - 1)]; + return $id; + } + + public function Call($name, $arguments=null) { + $id = $this->generateId(); + + $request = array( + 'jsonrpc' => '2.0', + 'method' => $name, + 'params' => array($arguments), + 'id' => $id + ); + + $jsonRequest = json_encode($request); + + //echo $jsonRequest . PHP_EOL; + $this->__open(); + + socket_bind($this->socket, $this->address); + if (!socket_connect($this->socket, $this->address, $this->port)) { + throw new JsonRpcException('unable to open socket', -32603); + } + + socket_write($this->socket, $jsonRequest); + $jsonResponse = socket_read($this->socket, 4096); + + if ($jsonResponse === false) { + throw new JsonRpcException('file_get_contents failed', -32603); + } + + $response = json_decode($jsonResponse); + if ($response === null) { + throw new JsonRpcException('JSON cannot be decoded', -32603); + } + + if ($response->id != $id) { + throw new JsonRPCException('Mismatched JSON-RPC IDs', -32603); + } + + if ($response->error) { + throw new JsonRpcException($response->error); + } + + if (property_exists($response, 'result')) { + return $response->result; + } else { + throw new JsonRpcException('Invalid JSON-RPC response', -32603); + } + } +} + +?> diff --git a/composer.json b/composer.json index 65371ca..da577f7 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ }, "autoload": { "classmap": [ - "database" + "database", + "app/JsonRpcClient.php" ], "psr-4": { "App\\": "app/", diff --git a/config/app.php b/config/app.php index 5700fb3..ff01c78 100644 --- a/config/app.php +++ b/config/app.php @@ -2,7 +2,7 @@ return [ - 'version' => '0.8', + 'version' => '0.9', /* |-------------------------------------------------------------------------- | Application Environment diff --git a/config/purifier.php b/config/purifier.php index 7e2ba89..f93fcfa 100644 --- a/config/purifier.php +++ b/config/purifier.php @@ -26,7 +26,7 @@ return [ 'HTML.Doctype' => 'HTML 4.01 Transitional', 'HTML.Allowed' => 'div,b,strong,i,em,u,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]', 'CSS.AllowedProperties' => 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align', - 'AutoFormat.AutoParagraph' => true, + 'AutoFormat.AutoParagraph' => false, 'AutoFormat.RemoveEmpty' => true, ], 'test' => [ diff --git a/public/css/message.css b/public/css/message.css index f84d4f6..13bac67 100644 --- a/public/css/message.css +++ b/public/css/message.css @@ -57,8 +57,7 @@ height: 2em; padding-top: 0.2em; position: absolute; - top: 0.3em; - left: 5em; + left: 0em; z-index: 10; } @@ -95,6 +94,12 @@ opacity: 0; } +.center-block { + display: block; + margin-left: auto; + margin-right: auto; +} + .err-msg { color: red; font-weight: bold; diff --git a/public/img/sorry.png b/public/img/sorry.png new file mode 100644 index 0000000..bee1552 Binary files /dev/null and b/public/img/sorry.png differ diff --git a/public/js/message.js b/public/js/message-20170622.js similarity index 99% rename from public/js/message.js rename to public/js/message-20170622.js index fd2515b..8fca99b 100644 --- a/public/js/message.js +++ b/public/js/message-20170622.js @@ -299,6 +299,7 @@ var Message = new Vue({ }, methods: { startLoop: function () { + $("#vue-error-msg").remove(); var vm = this; vm.loadContact(); vm.timer = window.setInterval(function() { diff --git a/resources/views/admin/index.blade.php b/resources/views/admin/index.blade.php index ce3bda1..6c4dea8 100644 --- a/resources/views/admin/index.blade.php +++ b/resources/views/admin/index.blade.php @@ -104,8 +104,9 @@ {{ $repo->id }} - {{ $repo->sender_id }} - {{ $repo->receiver_id }} + {{ $repo->sender_id }} + {{ $repo->receiver_id }} + 查看