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 @@
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 @@