From 456b5a802853f4c1a084059eb0b1b737ca235362 Mon Sep 17 00:00:00 2001 From: jack Date: Wed, 25 Apr 2018 22:09:11 +0800 Subject: [PATCH] added twilio library updated run laravel app after db started temporary added login and register test --- Dockerfile | 8 +- app/Http/Controllers/AuthController.php | 28 +++--- composer.json | 5 +- composer.lock | 112 +++++++++++++++++++++++- config/app.php | 2 + start.sh | 3 + tests/Feature/LoginTest.php | 26 ++++++ tests/Feature/RegisterTest.php | 26 ++++++ 8 files changed, 193 insertions(+), 17 deletions(-) create mode 100644 start.sh create mode 100644 tests/Feature/LoginTest.php create mode 100644 tests/Feature/RegisterTest.php diff --git a/Dockerfile b/Dockerfile index 678de57..5d4469e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,9 @@ FROM php:7 -RUN apt-get update -y && apt-get install -y openssl zip unzip git +RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN docker-php-ext-install pdo pdo_mysql WORKDIR /app COPY . /app -RUN composer update -CMD php artisan serve --host=0.0.0.0 --port=8000 -EXPOSE 8000 \ No newline at end of file +RUN composer install +ADD start.sh /start.sh +CMD ["/start.sh"] \ No newline at end of file diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 1330681..dc327f6 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -3,11 +3,22 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; use App\User; use JWTAuth; +use Aloha\Twilio\Twilio; use Tymon\JWTAuth\Exceptions\JWTException; use Validator, DB, Hash, Mail, Illuminate\Support\Facades\Password; class AuthController extends Controller { + /** + * API Send verification code + * + * @param Request $request + * @return \Illuminate\Http\JsonResponse + */ + public function verification_code(Request $request){ + + } + /** * API Register * @@ -21,28 +32,25 @@ class AuthController extends Controller $rules = [ 'name' => 'required|max:255', 'phone' => 'required|digits:10|unique:users', - 'password' => 'required', - 'confirm_password' => 'required', - + 'password' => 'required|confirmed|min:6' ]; $validator = Validator::make($credentials, $rules); if($validator->fails()) { return response()->json(['success'=> false, 'error'=> $validator->messages()]); } $name = $request->name; - $phone = $request->phone; + $phone = "+6" . $request->phone; $password = $request->password; $user = User::create(['name' => $name, 'phone' => $phone, 'password' => Hash::make($password)]); - $verification_code = str_random(30); //Generate verification code + $verification_code = rand (0000,9999); //Generate verification code DB::table('user_verifications')->insert(['user_id'=>$user->id,'token'=>$verification_code]); - /* + // send SMS + $message = "IZYIM verification code : 12332"; + $twilio = new Twilio(env('TWILIO_ACC'), env('TWILIO_TOKEN'), env('TWILIO_NUMBER')); + $twilio->message($phone, $message); - Twilio here - - */ - return response()->json(['success'=> true, 'message'=> 'A verification code has been send to your mobile number.']); } diff --git a/composer.json b/composer.json index 5669321..f687bd5 100644 --- a/composer.json +++ b/composer.json @@ -6,11 +6,12 @@ "type": "project", "require": { "php": "^7.1.3", + "aloha/twilio": "^4.0", + "doctrine/dbal": "~2.3", "fideloper/proxy": "^4.0", "laravel/framework": "5.6.*", "laravel/tinker": "^1.0", - "tymon/jwt-auth": "1.0.*", - "doctrine/dbal": "~2.3" + "tymon/jwt-auth": "1.0.*" }, "require-dev": { "filp/whoops": "^2.0", diff --git a/composer.lock b/composer.lock index bd91384..b06024f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,72 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "b2dc446e9fbb09e9c686c1292c79098c", + "content-hash": "79f35763f56d5e27e88c843097cba288", "packages": [ + { + "name": "aloha/twilio", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/aloha/laravel-twilio.git", + "reference": "0fd74d541116b0641f815bb59b8323cfe1d6004f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/aloha/laravel-twilio/zipball/0fd74d541116b0641f815bb59b8323cfe1d6004f", + "reference": "0fd74d541116b0641f815bb59b8323cfe1d6004f", + "shasum": "" + }, + "require": { + "php": ">=5.5.0", + "twilio/sdk": "5.*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^1.9", + "illuminate/console": "~4||~5", + "illuminate/support": "~4||~5", + "phpunit/phpunit": "~4.5" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Aloha\\Twilio\\Support\\Laravel\\ServiceProvider" + ], + "aliases": { + "Twilio": "Aloha\\Twilio\\Support\\Laravel\\Facade" + } + } + }, + "autoload": { + "psr-4": { + "Aloha\\Twilio\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Hannes Van De Vreken", + "email": "vandevreken.hannes@gmail.com" + }, + { + "name": "Travis J Ryan", + "email": "travisjryan@gmail.com" + } + ], + "description": "Twilio API for Laravel", + "homepage": "https://github.com/aloha/laravel-twilio", + "keywords": [ + "ivr", + "laravel", + "sms", + "twilio" + ], + "time": "2018-04-23T14:59:03+00:00" + }, { "name": "dnoegel/php-xdg-base-dir", "version": "0.1", @@ -2759,6 +2823,52 @@ "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", "time": "2017-11-27T11:13:29+00:00" }, + { + "name": "twilio/sdk", + "version": "5.17.1", + "source": { + "type": "git", + "url": "https://github.com/twilio/twilio-php.git", + "reference": "ae3477ccf88a0efb5bbe8928274c4a2046aec0c1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/twilio/twilio-php/zipball/ae3477ccf88a0efb5bbe8928274c4a2046aec0c1", + "reference": "ae3477ccf88a0efb5bbe8928274c4a2046aec0c1", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "require-dev": { + "apigen/apigen": "^4.1", + "phpunit/phpunit": "4.5.*" + }, + "type": "library", + "autoload": { + "psr-4": { + "Twilio\\": "Twilio/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Twilio API Team", + "email": "api@twilio.com" + } + ], + "description": "A PHP wrapper for Twilio's API", + "homepage": "http://github.com/twilio/twilio-php", + "keywords": [ + "api", + "sms", + "twilio" + ], + "time": "2018-04-20T23:40:08+00:00" + }, { "name": "tymon/jwt-auth", "version": "1.0.0-rc.2", diff --git a/config/app.php b/config/app.php index 3dc5bca..84f438a 100644 --- a/config/app.php +++ b/config/app.php @@ -150,6 +150,7 @@ return [ * Package Service Providers... */ Tymon\JWTAuth\Providers\LaravelServiceProvider::class, + Aloha\Twilio\Support\Laravel\ServiceProvider::class, /* * Application Service Providers... @@ -210,6 +211,7 @@ return [ 'View' => Illuminate\Support\Facades\View::class, 'JWTAuth' => Tymon\JWTAuth\Facades\JWTAuth::class, 'JWTFactory' => Tymon\JWTAuth\Facades\JWTFactory::class, + 'Twilio' => Aloha\Twilio\Support\Laravel\Facade::class, ], diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..f7da8d5 --- /dev/null +++ b/start.sh @@ -0,0 +1,3 @@ +#!/bin/bash +while ! nc -z db 3306; do sleep 3; done +php artisan serve --host=0.0.0.0 --port=8000 \ No newline at end of file diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php new file mode 100644 index 0000000..005d4aa --- /dev/null +++ b/tests/Feature/LoginTest.php @@ -0,0 +1,26 @@ +json('POST', '/api/login', ['phone' => '01234567899','password' => '123']); + + $response + ->assertStatus(201) + ->assertJson([ + 'created' => true, + ]); + } +} diff --git a/tests/Feature/RegisterTest.php b/tests/Feature/RegisterTest.php new file mode 100644 index 0000000..af24b74 --- /dev/null +++ b/tests/Feature/RegisterTest.php @@ -0,0 +1,26 @@ +json('POST', '/api/register', ['name' => 'Sally']); + + $response + ->assertStatus(201) + ->assertJson([ + 'created' => true, + ]); + } +}