Skip to content
Permalink
Browse files

Support local dev deployment

1. Adjust env configuration to support custom domain
deployment (e.g. munpanel.lhdev.xyz)
2. Add data seeders for users and conferences (more
should be added in future changes)
3. Log sms/calls into debugbar but do not actually
send those to APIs when in dev mode

Fore more information, please refer to
https://jira.yiad.am/confluence/display/MUN/MPCORE

Change-Id: Ia8ae28906d2c081744ea10ef82c177f7569e1d44
  • Loading branch information...
adamyi committed Jan 12, 2018
1 parent f6ca868 commit 9c7d7d6cde3a045e368fbafc80f542b9dbf86d59
@@ -12,7 +12,7 @@ MP_REGISTRATION_SCHOOL_CHANGABLE=true
MP_IMAP_HOST={mail.yiad.am:143/novalidate-cert}INBOX
MP_MAIL_HOST=http://mail.yiad.am/
MP_MAIL_KEY=api@yiad.am
MP_MAIL_SECRET=Shall I compare thee to a summer's day?
MP_MAIL_SECRET=ShallIcomparetheetoasummersday
MP_ICPLICENSE=京ICP备17022496号-1

DB_CONNECTION=mysql
@@ -10,11 +10,10 @@
*/
/**
*
* Return URL based on environment.
*/
function mp_url($url) {
return secure_url($url);
return url($url);
return env('APP_ENV') === 'prod' ? secure_url($url) : url($url);
}
//update 0: default, 1: update, 2: don't update
@@ -31,6 +31,7 @@
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Log;
use Config;
use Zipper;
use File;
@@ -47,8 +47,12 @@ static public function send($mobileList, $message) {
{
//twillio International
try {
Log::info('Successfully sent an SMS to '.$mobile. ' using Twillio, message of which is: '. $message);
Twilio::message($mobile, $message);
if (env('APP_ENV') === 'dev') {
Log::info('Twillio: in dev mode. Not sending message to '.$mobile. ': '. $message);
} else {
Twilio::message($mobile, $message);
Log::info('Successfully sent an SMS to '.$mobile. ' using Twillio, message of which is: '. $message);
}
} catch (\Exception $e) {
Log::info('Error sending an SMS to '.$mobile. ' using Twillio, message of which is: '. $message);
return false;
@@ -58,8 +62,46 @@ static public function send($mobileList, $message) {
else
{
//luosimao Chinese
if (env('APP_ENV') === 'dev') {
Log::info('Luosimao: in dev mode. Not sending message to '.$mobile. ': '. $message);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms-api.luosimao.com/v1/send.json");
curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD , 'api:key-'.Config::get('luosimao.key_sms'));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobile' => $mobile, 'message' => $message .'【MUNPANEL】'));
$res = curl_exec( $ch );
curl_close( $ch );
$result = json_decode($res);
if (is_null($result))
{
Log::info('Error sending an SMS to '.$mobile. ' using luosimao, message of which is: '. $message);
return false;
}
if ($result->error == 0)
{
Log::info('Successfully sent an SMS to '.$mobile. ' using luosimao, message of which is: '. $message);
return true;
}
Log::info('Error sending an SMS to '.$mobile. ' using luosimao, message of which is: '. $message);
return false;
}
}
} else { // batch send
if (env('APP_ENV') === 'dev') {
Log::info('Luosimao: in dev mode. Not sending message to '.implode(',', $mobileList). ': '. $message);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms-api.luosimao.com/v1/send.json");
curl_setopt($ch, CURLOPT_URL, "http://sms-api.luosimao.com/v1/send_batch.json");
curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
@@ -70,41 +112,11 @@ static public function send($mobileList, $message) {
curl_setopt($ch, CURLOPT_USERPWD , 'api:key-'.Config::get('luosimao.key_sms'));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobile' => $mobile, 'message' => $message .'【MUNPANEL】'));
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobilei_list' => implode(',', $mobileList), 'message' => $message .'【MUNPANEL】'));
$res = curl_exec( $ch );
curl_close( $ch );
$result = json_decode($res);
if (is_null($result))
{
Log::info('Error sending an SMS to '.$mobile. ' using luosimao, message of which is: '. $message);
return false;
}
if ($result->error == 0)
{
Log::info('Successfully sent an SMS to '.$mobile. ' using luosimao, message of which is: '. $message);
return true;
}
Log::info('Error sending an SMS to '.$mobile. ' using luosimao, message of which is: '. $message);
return false;
}
} else { // batch send
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://sms-api.luosimao.com/v1/send_batch.json");
curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 8);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD , 'api:key-'.Config::get('luosimao.key_sms'));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobilei_list' => implode(',', $mobileList), 'message' => $message .'【MUNPANEL】'));
$res = curl_exec( $ch );
curl_close( $ch );
}
return true;
}
@@ -125,49 +137,57 @@ static public function call($mobile, $code) {
if ($mobile[0] == '+')
{
try {
Twilio::call($mobile, function($message) {
$message->say("Welcome to mengpanle. Your code is ".implode(' ',str_split(session("code"))));
$message->pause(["length" => "1"]);
$message->say("Welcome to mengpanle. Your code is ".implode(' ',str_split(session("code"))));
$message->say("Thank you.");
});
Log::info('Successfully called '.$mobile. ' using Twilio, code of which is: '. $code);
if (env('APP_ENV') === 'dev') {
Log::info('Twilio: in dev mode. Not calling '.$mobile. ' with code '. $code);
} else {
Twilio::call($mobile, function($message) {
$message->say("Welcome to mengpanle. Your code is ".implode(' ',str_split(session("code"))));
$message->pause(["length" => "1"]);
$message->say("Welcome to mengpanle. Your code is ".implode(' ',str_split(session("code"))));
$message->say("Thank you.");
});
Log::info('Successfully called '.$mobile. ' using Twilio, code of which is: '. $code);
}
} catch (\Exception $e) {
Log::info('Error calling '.$mobile. ' using Twilio, code of which is: '. $code);
return false;
}
}
else
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://voice-api.luosimao.com/v1/verify.json");
if (env('APP_ENV') === 'dev') {
Log::info('Luosimao: in dev mode. Not calling '.$mobile. ' with code '. $code);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://voice-api.luosimao.com/v1/verify.json");
curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_0 );
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD , 'api:key-'.Config::get('luosimao.key_call'));
curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD , 'api:key-'.Config::get('luosimao.key_call'));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobile' => $mobile,'code' => $code));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobile' => $mobile,'code' => $code));
$res = curl_exec( $ch );
curl_close( $ch );
$result = json_decode($res);
if (is_null($result))
{
$res = curl_exec( $ch );
curl_close( $ch );
$result = json_decode($res);
if (is_null($result))
{
Log::info('Error calling '.$mobile. ' using luosimao, code of which is: '. $code);
return false;
}
if ($result->error == 0)
{
Log::info('Successfully called '.$mobile. ' using luosimao, code of which is: '. $code);
return true;
}
Log::info('Error calling '.$mobile. ' using luosimao, code of which is: '. $code);
return false;
}
if ($result->error == 0)
{
Log::info('Successfully called '.$mobile. ' using luosimao, code of which is: '. $code);
return true;
}
Log::info('Error calling '.$mobile. ' using luosimao, code of which is: '. $code);
return false;
}
return true;
}
@@ -32,7 +32,7 @@ public function handle($request, Closure $next)
{
if (is_null(config('munpanel.conference_id'))) //we may route all domains to one conference for debugging and developing.
{
$domain = $_SERVER['HTTP_HOST'];
$domain = explode(':',$_SERVER['HTTP_HOST'])[0];
$conference_id = Cache::tags('domains')->get($domain);
if (!isset($conference_id))
{
@@ -18,7 +18,7 @@ class HttpsProtocol {
public function handle($request, Closure $next)
{
if (!$request->secure() {//&& env('APP_ENV') === 'prod') {
if (!$request->secure() && env('APP_ENV') === 'prod') {
return redirect()->secure($request->getRequestUri());
}
@@ -29,7 +29,9 @@ class AppServiceProvider extends ServiceProvider
*/
public function boot()
{
\URL::forceScheme('https');
if (env('APP_ENV') === 'prod') {
\URL::forceScheme('https');
}
$pusher = $this->app->make('pusher');
$pusher->set_logger( new LaravelLoggerProxy() );
}
@@ -87,6 +87,7 @@
*/
'locale' => 'cn',
'faker_locale' => 'zh_CN',
/*
|--------------------------------------------------------------------------
@@ -20,7 +20,8 @@
'mailapi_key' => env('MP_MAILAPI_KEY', 'api@yiad.am'),
'mailapi_secret' => env('MP_MAILAPI_SECRET', ''),
'icp_license' => env('MP_ICPLICENSE', ''),
'landingDomain' => env('MP_LANDINGDOMAIN', 'www.munpanel.com'),
'portalDomain' => env('MP_PORTALDOMAIN', 'portal.munpanel.com'),
'payDomain' => env('MP_PAYDOMAIN', 'pay.munpanel.com')
'landingDomain' => env('MP_SUBDOMAIN_LANDING', 'www') . env('MP_MAIN_DOMAIN', '.munpanel.com'),
'portalDomain' => env('MP_SUBDOMAIN_PORTAL', 'portal') . env('MP_MAIN_DOMAIN', '.munpanel.com'),
'payDomain' => env('MP_SUBDOMAIN_PAY', 'pay') . env('MP_MAIN_DOMAIN', '.munpanel.com'),
'mainDomain' => env('MP_MAIN_DOMAIN', '.munpanel.com'),
];
@@ -157,7 +157,7 @@
|
*/
'domain' => env('SESSION_DOMAIN', null),
'domain' => env('SESSION_DOMAIN', env('MP_MAIN_DOMAIN', null)),
/*
|--------------------------------------------------------------------------
@@ -0,0 +1,35 @@
<?php
/**
* Copyright (C) MUNPANEL
* This file is part of MUNPANEL System.
*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*
* Developed by Adam Yi <xuan@yiad.am>
*/
use Faker\Generator as Faker;
$factory->define(App\Conference::class, function (Faker $faker) {
$conf_name = strtoupper($faker->unique()->lexify("??"));
return [
'name' => $conf_name . "MUN 201X",
'shortname' => $conf_name."MUN",
'fullname' => "201X年".$conf_name." 模拟联合国大会",
'description' => $faker->text(200),
];
});
$factory->state(App\Conference::class, 'reg', function ($faker) {
$st_date = $faker->dateTimeBetween('+1 months', '+3 months');
$ed_date = clone $st_date;
$ed_date->add(new DateInterval('P3D'));
return [
'status' => 'reg',
'date_start' => $st_date->format('Y-m-d'),
'date_end' => $faker->dateTimeInInterval($ed_date, '+ 3 days')->format('Y-m-d'),
];
});
//TOOD: more states to come
@@ -1,23 +1,26 @@
<?php
/**
* Copyright (C) MUNPANEL
* This file is part of MUNPANEL System.
*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*
* Developed by Adam Yi <xuan@yiad.am>
*/
use Faker\Generator as Faker;
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/
$factory->define(App\User::class, function (Faker $faker) {
static $password;
return [
'name' => $faker->name,
'email' => $faker->unique()->safeEmail,
'password' => '$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm', // secret
'tel' => $faker->unique()->phoneNUmber,
'password' => $password ?: $password = bcrypt('testpassword'),
'emailVerificationToken' => $faker->optional($weight = 0.1, $default = 'success')->lexify('????????????????'),
'telVerifications' => $faker->optional($weight = 0.1, $default = -1)->numberBetween(0, 15),
'remember_token' => str_random(10),
];
});
@@ -0,0 +1,32 @@
<?php
/**
* Copyright (C) MUNPANEL
* This file is part of MUNPANEL System.
*
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
*
* Developed by Adam Yi <xuan@yiad.am>
*/
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class ConferencesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//TODO: create conferences of different status
factory(App\Conference::class, 10)->states('reg')->create()->each(function ($c) {
DB::table('domains')->insert([
'conference_id' => $c->id,
'domain' => strtolower($c->shortname).config('munpanel.mainDomain')
]);
});
}
}

0 comments on commit 9c7d7d6

Please sign in to comment.
You can’t perform that action at this time.