diff --git a/Dockerfile b/Dockerfile index 32df4f4..1db0872 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,8 @@ FROM php:7 -RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat +RUN apt-get update -y && apt-get install -y openssl zip unzip git netcat libpng-dev RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer RUN docker-php-ext-install pdo pdo_mysql +RUN docker-php-ext-install gd WORKDIR /app COPY . /app RUN composer update diff --git a/app/Company.php b/app/Company.php index af4bf8d..ee6bb6c 100644 --- a/app/Company.php +++ b/app/Company.php @@ -9,4 +9,9 @@ class Company extends Model // protected $fillable = ['company_profile', 'reg_cert', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person']; //protected $guarded = []; + + public function user() + { + return $this->belongsTo('App\User'); + } } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 48d0639..17ba3f3 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -7,6 +7,7 @@ use App\PasswordResets; use JWTAuth; use Auth; use App\Role; +use App\Company; use Aloha\Twilio\Twilio; use Tymon\JWTAuth\Exceptions\JWTException; @@ -41,20 +42,20 @@ class AuthController extends Controller $user->save(); // create token if not exist, update if exist - $token = mt_rand(0000,9999); + $token = mt_rand(0000,9999); - // for testing + // for testing if($request->phone == '0123456789'){ $token = "1234"; } - + $user_verification = $user->phoneVerification()->firstOrNew([ 'user_id' => $user->id, ]); $user_verification->token = $token; $user_verification->save(); - // TODO: send token to phone + // TODO: send token to phone //$message = "RM0.00 IZYIM: Verification code : ". $token; //$twilio = new Twilio(env('TWILIO_ACC'), env('TWILIO_TOKEN'), env('TWILIO_NUMBER')); //$twilio->message($request->phone, $message); @@ -99,7 +100,10 @@ class AuthController extends Controller if (!$userToken=JWTAuth::fromUser($check_user)) { return response()->json(['error' => 'invalid_credentials'], 401); } - + + // TODO : Create company for user + + $expiration = JWTAuth::setToken($userToken)->getPayload()->get('exp'); // all good so return the token return response()->json(['success' => true, 'token' => $userToken, @@ -129,7 +133,7 @@ class AuthController extends Controller if($validator->fails()) { return response()->json(['success'=> false, 'error'=> $validator->messages()]); } - + $name = $request->name; $password = $request->password; $role = $request->role; @@ -142,6 +146,12 @@ class AuthController extends Controller // attach role to user $user->attachRole($role); $user->update(['name' => $name, 'password' => Hash::make($password)]); + + // TODO : create company for user + $company = new Company; + $company->user = $user; + $company->save(); + return response()->json(['success'=> true, 'message'=> 'Profile updated.']); } diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index aba4fdc..e95914b 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -6,23 +6,16 @@ use Illuminate\Http\Request; use App\Company; use Illuminate\Support\Facades\Storage; use Validator; +use Auth; class CompanyController extends Controller { - public function store(Request $request) + public function update(Request $request) { - $input = $request->all(); - Company::create($input); - return response()->json(['input'=>$input],201); - //return redirect('/'); - } - - public function update(Request $request, $id) - { - $company = Company::find($id); + $company = Company::where("user_id", Auth::user()->id)->first(); if (!$company) { - return response()->json(['message'=>'company not found'],200); + return response()->json(['message'=>'company not found'], 404); } $company->company_name=$request->input('company_name'); @@ -41,9 +34,9 @@ class CompanyController extends Controller return response()->json(['company'=>$company],200); } - public function companyProfile(Request $request, $id) + public function companyProfile(Request $request) { - $company = Company::find($id);//find the company first + $company = Company::where("user_id", Auth::user()->id)->first(); if (!$company) { return response()->json(['message'=>'company for company_prof not found'],200); @@ -75,12 +68,12 @@ class CompanyController extends Controller return response()->json(['company'=>$company],200); }//end of companyProfile() - public function regCert(Request $request, $id) + public function regCert(Request $request) { - $company = Company::find($id); //find the company first + $company = Company::where("user_id", Auth::user()->id)->first(); if (!$company) { - return response()->json(['message'=>'company for reg_cert not found'],200); + return response()->json(['message'=>'Company not found'], 404); } //validating file types diff --git a/app/User.php b/app/User.php index e82ca32..a5bb95e 100644 --- a/app/User.php +++ b/app/User.php @@ -54,4 +54,9 @@ class User extends Authenticatable implements JWTSubject return $this->hasOne('App\UserVerification', 'user_id'); } + public function company() + { + return $this->hasOne('App\Company'); + } + } diff --git a/database/factories/CompanyFactory.php b/database/factories/CompanyFactory.php new file mode 100644 index 0000000..ccbfa28 --- /dev/null +++ b/database/factories/CompanyFactory.php @@ -0,0 +1,30 @@ +define(App\Company::class, function (Faker $faker) { + return [ + 'company_name'=>'testing', + 'registration_no'=>'testing', + 'tax_no'=>'testing', + 'tel_no'=>'12345', + 'fax'=>'12345', + 'address'=>'testing', + 'city'=>'testing', + 'postcode'=>'testing', + 'state'=>'testing', + 'country'=>'testing', + 'contact_person'=>'testing' + ]; +}); diff --git a/database/migrations/2018_04_25_084609_change_email_to_mobile_from_user.php b/database/migrations/2018_04_25_084609_change_email_to_mobile_from_user.php index b8f59c1..5ce9b11 100644 --- a/database/migrations/2018_04_25_084609_change_email_to_mobile_from_user.php +++ b/database/migrations/2018_04_25_084609_change_email_to_mobile_from_user.php @@ -25,6 +25,6 @@ class ChangeEmailToMobileFromUser extends Migration */ public function down() { - $table->renameColumn('phone', 'email'); + //$table->renameColumn('phone', 'email'); } } diff --git a/database/migrations/2018_05_26_014004_add_user_to_company_table.php b/database/migrations/2018_05_26_014004_add_user_to_company_table.php new file mode 100644 index 0000000..39ecc01 --- /dev/null +++ b/database/migrations/2018_05_26_014004_add_user_to_company_table.php @@ -0,0 +1,31 @@ +unsignedInteger('user_id'); + $table->foreign('user_id')->references('id')->on('users'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/public/index.html b/public/index.html index 7368ba3..8f29008 100644 --- a/public/index.html +++ b/public/index.html @@ -46,7 +46,6 @@
Sign In - Sign In
diff --git a/public/profile-first-setup.html b/public/profile-first-setup.html index c0e53f9..737f734 100644 --- a/public/profile-first-setup.html +++ b/public/profile-first-setup.html @@ -47,48 +47,38 @@
- +
- +
- +
+
- +
- +
+
- +
- +
-
-
- -
- -
-
-
- -
- -
-
- FINISH + FINISH
@@ -104,6 +94,28 @@ - + + \ No newline at end of file diff --git a/public/signup.html b/public/signup.html deleted file mode 100644 index 12689cb..0000000 --- a/public/signup.html +++ /dev/null @@ -1,100 +0,0 @@ - - - - AzureUI - SIGNUP - - - AzureUI - SIGN-IN - - - - - - -
-
- - -
- -

Sign-up

-
- - -
-
- -
- - -
-
-
-
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
-
- -
- -
-
- -
-
- Request verification number -
- -
-
-
- -
- -
-
-
- Send -
-
-
- -
- Sign Up -
- -
- Already have an account? Sign-in -
- -
-
-
- - -
-
- - - \ No newline at end of file diff --git a/public/verify-code-number.html b/public/verify-code-number.html index a28e144..02cc3c1 100644 --- a/public/verify-code-number.html +++ b/public/verify-code-number.html @@ -15,11 +15,11 @@
- Verify +60 19-795-1905 + Verify Phone
- Waiting to automatically detect an SMS sent to +60 19-795 1905. Wrong number? + A verification code has been send to .
Wrong number?
@@ -32,15 +32,15 @@
- + -
-
+
+
- NEXT + NEXT
@@ -51,6 +51,47 @@
+ + \ No newline at end of file diff --git a/public/verify-phone-number.html b/public/verify-phone-number.html index ec7ab00..a1d65af 100644 --- a/public/verify-phone-number.html +++ b/public/verify-phone-number.html @@ -8,8 +8,8 @@ - +
@@ -19,15 +19,16 @@
- IZYIM will send an SMS message to verify your phone number. Enter your country code and phone number: + IZYIM will send an SMS message to verify your phone number. Enter your country code and phone number:
- +
-
+
+ @csrf
@@ -45,7 +46,7 @@
- +
@@ -53,7 +54,7 @@
- NEXT + NEXT
@@ -61,14 +62,47 @@ Carrier SMS charges may apply
-
- - + + + + + \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index bffebdb..1beaaec 100644 --- a/routes/api.php +++ b/routes/api.php @@ -26,10 +26,10 @@ Route::group(['middleware' => ['jwt.auth']], function() { Route::get('test', function(Request $request){ return response()->json(['user'=> $request->user()]); }); + + /* Company */ + Route::patch('/company', 'CompanyController@update'); //update company information + Route::post('/company/company_profile/', 'CompanyController@companyProfile');//upload company profile picture + Route::post('/company/reg_cert/', 'CompanyController@regCert'); //upload registration certificaate }); -/* Company */ -Route::post('/company', 'CompanyController@store'); //store company information -Route::put('/company/{company}', 'CompanyController@update'); //update company information -Route::post('/company/company_profile/{companyID}', 'CompanyController@companyProfile');//upload company profile picture -Route::post('/company/reg_cert/{companyID}', 'CompanyController@regCert'); //upload registration certificaate \ No newline at end of file diff --git a/tests/Unit/CompanyTest.php b/tests/Feature/CompanyTest.php similarity index 50% rename from tests/Unit/CompanyTest.php rename to tests/Feature/CompanyTest.php index 89f4249..1a4a7fc 100644 --- a/tests/Unit/CompanyTest.php +++ b/tests/Feature/CompanyTest.php @@ -7,40 +7,31 @@ use Illuminate\Foundation\Testing\WithFaker; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Http\UploadedFile; use Illuminate\Support\Facades\Storage; +use Artisan; +use App\User; +use App\Company; class CompanyTest extends TestCase { - /** - * A basic test example. - * - * @return void - */ - public function testExample() + protected $company; + protected $user; + + public function setUp() { - $this->assertTrue(true); + parent::setUp(); + Artisan::call('db:seed'); + $this->user = factory(User::class)->create(); + $this->company = $this->user->each(function ($u) { + factory(Company::class)->create([ + 'user_id' => $u->id, + ]); + }); } - public function testPOST() + public function testUpdateCompany() { - $response = $this->json('POST', '/api/company', [ - 'company_name'=>'testing', - 'registration_no'=>'testing', - 'tax_no'=>'testing', - 'tel_no'=>'12345', - 'fax'=>'12345', - 'address'=>'testing', - 'city'=>'testing', - 'postcode'=>'testing', - 'state'=>'testing', - 'country'=>'testing', - 'contact_person'=>'testing', - ]); - $response->assertStatus(201); - } - - public function testPUT() - { - $response = $this->json('PUT', '/api/company/2', [ + $response = $this->actingAs($this->user) + ->patchJson('/api/company', [ 'company_name'=>'changed testing', 'registration_no'=>'testing', 'tax_no'=>'testing', @@ -52,29 +43,32 @@ class CompanyTest extends TestCase 'state'=>'testing', 'country'=>'testing', 'contact_person'=>'testing', + ]); $response->assertStatus(200); + } - public function testcompanyProfile() - { + public function testUploadCompanyProfile() + { Storage::fake('company_profile'); - - $response = $this->json('POST', '/api/company/company_profile/2', [ + + $response = $this->actingAs($this->user) + ->json('POST', '/api/company/company_profile/', [ 'company_profile' => UploadedFile::fake()->image('comp.jpg') ]); - dd($response->getContent()); + // dd($response->getContent()); $response->assertStatus(200); } - public function testregCert() + public function testUploadRegCert() { Storage::fake('reg_cert'); - $response = $this->json('POST', '/api/company/reg_cert/2', [ + $response = $this->actingAs($this->user) + ->json('POST', '/api/company/reg_cert/', [ 'reg_cert' => UploadedFile::fake()->create('document.pdf')//, $sizeInKilobytes) ]); - dd($response->getContent()); $response->assertStatus(200); } } diff --git a/tests/Feature/LoginTest.php b/tests/Feature/LoginTest.php index 34e9cce..7d0cce8 100644 --- a/tests/Feature/LoginTest.php +++ b/tests/Feature/LoginTest.php @@ -13,7 +13,7 @@ class LoginTest extends TestCase * * @return void */ - public function testExample() + public function testLogin() { $response = $this->json('POST', '/api/login', ['phone' => '0123456789','password' => 'secret']); $response diff --git a/tests/Feature/RegisterTest.php b/tests/Feature/RegisterTest.php index f0e600b..8d47119 100644 --- a/tests/Feature/RegisterTest.php +++ b/tests/Feature/RegisterTest.php @@ -26,7 +26,7 @@ class RegisterTest extends TestCase 'success' => true, ]); - $response = $this->json('POST', '/api/verify', ['phone' => '0123456789', 'token' => '1234']); + $response = $this->json('POST', '/api/verify-phone', ['phone' => '0123456789', 'token' => '1234']); $response ->assertStatus(200) ->assertJson([ diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php deleted file mode 100644 index e9fe19c..0000000 --- a/tests/Unit/ExampleTest.php +++ /dev/null @@ -1,19 +0,0 @@ -assertTrue(true); - } -}