9 changed files with 168 additions and 143 deletions
-
39app/Http/Controllers/AuthController.php
-
52app/Http/Controllers/InstallationController.php
-
2app/Http/Requests/Accounts/RegisterRequest.php
-
12resources/views/auth/login.blade.php
-
48resources/views/auth/register.blade.php
-
8routes/web/account.php
-
74tests/Feature/Auth/InstallationTest.php
-
14tests/Feature/Auth/LoginTest.php
-
62tests/Feature/Auth/RegistrationTest.php
@ -1,39 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace App\Http\Controllers; |
|
||||
|
|
||||
use App\Entities\Users\User; |
|
||||
use App\Http\Requests\Accounts\RegisterRequest; |
|
||||
use Auth; |
|
||||
use Illuminate\Contracts\Auth\Guard; |
|
||||
use Illuminate\Contracts\Auth\PasswordBroker; |
|
||||
|
|
||||
class AuthController extends Controller |
|
||||
{ |
|
||||
public function __construct(Guard $auth, PasswordBroker $passwords) |
|
||||
{ |
|
||||
$this->auth = $auth; |
|
||||
$this->passwords = $passwords; |
|
||||
|
|
||||
$this->middleware('guest'); |
|
||||
} |
|
||||
|
|
||||
public function getRegister() |
|
||||
{ |
|
||||
return view('auth.register'); |
|
||||
} |
|
||||
|
|
||||
public function postRegister(RegisterRequest $request) |
|
||||
{ |
|
||||
$registerData = $request->only('name', 'email', 'password'); |
|
||||
|
|
||||
$registerData['api_token'] = str_random(32); |
|
||||
|
|
||||
$user = User::create($registerData); |
|
||||
|
|
||||
Auth::login($user); |
|
||||
|
|
||||
flash()->success(trans('auth.welcome', ['name' => $user->name])); |
|
||||
return redirect()->route('home'); |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,52 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace App\Http\Controllers; |
||||
|
|
||||
|
use App\Entities\Users\User; |
||||
|
use App\Http\Requests\Accounts\RegisterRequest; |
||||
|
use Auth; |
||||
|
|
||||
|
/** |
||||
|
* Installation Controller |
||||
|
* |
||||
|
* @author Nafies Luthfi <nafiesl@gmail.com> |
||||
|
*/ |
||||
|
class InstallationController extends Controller |
||||
|
{ |
||||
|
public function __construct() |
||||
|
{ |
||||
|
$this->middleware('guest'); |
||||
|
} |
||||
|
|
||||
|
public function getRegister() |
||||
|
{ |
||||
|
if (User::count()) { |
||||
|
return redirect()->route('auth.login'); |
||||
|
} |
||||
|
return view('auth.register'); |
||||
|
} |
||||
|
|
||||
|
public function postRegister(RegisterRequest $request) |
||||
|
{ |
||||
|
$adminData = $request->only('name', 'email', 'password'); |
||||
|
|
||||
|
$adminData['api_token'] = str_random(32); |
||||
|
|
||||
|
$admin = User::create($adminData); |
||||
|
|
||||
|
Auth::login($admin); |
||||
|
|
||||
|
$agencyData = collect($request->only('agency_name', 'agency_website', 'email')) |
||||
|
->map(function ($value, $key) { |
||||
|
return [ |
||||
|
'key' => $key, |
||||
|
'value' => $value, |
||||
|
]; |
||||
|
})->toArray(); |
||||
|
|
||||
|
\DB::table('site_options')->insert($agencyData); |
||||
|
|
||||
|
flash()->success(trans('auth.welcome', ['name' => $admin->name])); |
||||
|
return redirect()->route('home'); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,74 @@ |
|||||
|
<?php |
||||
|
|
||||
|
namespace Tests\Feature\Auth; |
||||
|
|
||||
|
use App\Entities\Users\User; |
||||
|
use Tests\TestCase; |
||||
|
|
||||
|
/** |
||||
|
* Installation Feature Test |
||||
|
* |
||||
|
* @author Nafies Luthfi <nafiesl@gmail.com> |
||||
|
*/ |
||||
|
class InstallationTest extends TestCase |
||||
|
{ |
||||
|
/** @test */ |
||||
|
public function user_cannot_visit_register_page_if_user_already_exists_in_database() |
||||
|
{ |
||||
|
factory(User::class)->create(['email' => 'member@app.dev']); |
||||
|
$this->visit(route('app.install')); |
||||
|
$this->seePageIs(route('auth.login')); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function registration_validation() |
||||
|
{ |
||||
|
$this->visit(route('app.install')); |
||||
|
|
||||
|
$this->seePageIs(route('app.install')); |
||||
|
|
||||
|
$this->submitForm(trans('auth.register'), [ |
||||
|
'name' => 'Nama Member', |
||||
|
'email' => 'email', |
||||
|
'password' => 'password', |
||||
|
'password_confirmation' => 'password..', |
||||
|
]); |
||||
|
|
||||
|
$this->seePageIs(route('app.install')); |
||||
|
} |
||||
|
|
||||
|
/** @test */ |
||||
|
public function member_register_successfully() |
||||
|
{ |
||||
|
$this->visit(route('app.install')); |
||||
|
$this->seePageIs(route('app.install')); |
||||
|
|
||||
|
$this->submitForm(trans('auth.register'), [ |
||||
|
'agency_name' => 'Nama Agensi', |
||||
|
'agency_website' => 'https://example.com', |
||||
|
'name' => 'Nama Admin', |
||||
|
'email' => 'email@mail.com', |
||||
|
'password' => 'password.111', |
||||
|
'password_confirmation' => 'password.111', |
||||
|
]); |
||||
|
|
||||
|
$this->seePageIs(route('home')); |
||||
|
|
||||
|
$this->see(trans('auth.welcome', ['name' => 'Nama Admin'])); |
||||
|
|
||||
|
$this->seeInDatabase('users', [ |
||||
|
'name' => 'Nama Admin', |
||||
|
'email' => 'email@mail.com', |
||||
|
]); |
||||
|
|
||||
|
$this->seeInDatabase('site_options', [ |
||||
|
'key' => 'agency_name', |
||||
|
'value' => 'Nama Agensi', |
||||
|
]); |
||||
|
|
||||
|
$this->seeInDatabase('site_options', [ |
||||
|
'key' => 'agency_website', |
||||
|
'value' => 'https://example.com', |
||||
|
]); |
||||
|
} |
||||
|
} |
||||
@ -1,62 +0,0 @@ |
|||||
<?php |
|
||||
|
|
||||
namespace Tests\Feature\Auth; |
|
||||
|
|
||||
use App\Entities\Users\User; |
|
||||
use Tests\TestCase; |
|
||||
|
|
||||
class RegistrationTest extends TestCase |
|
||||
{ |
|
||||
/** @test */ |
|
||||
public function registration_validation() |
|
||||
{ |
|
||||
factory(User::class)->create(['email' => 'member@app.dev']); |
|
||||
|
|
||||
$this->visit(route('auth.register')); |
|
||||
|
|
||||
$this->submitForm(trans('auth.register'), [ |
|
||||
'name' => '', |
|
||||
'email' => 'member@app.dev', |
|
||||
'password' => '', |
|
||||
'password_confirmation' => '', |
|
||||
]); |
|
||||
|
|
||||
$this->seePageIs(route('auth.register')); |
|
||||
$this->see('Nama harus diisi.'); |
|
||||
$this->see('Email ini sudah terdaftar.'); |
|
||||
$this->see('Password harus diisi.'); |
|
||||
$this->see('Konfirmasi password harus diisi.'); |
|
||||
|
|
||||
$this->submitForm(trans('auth.register'), [ |
|
||||
'name' => 'Nama Member', |
|
||||
'email' => 'email', |
|
||||
'password' => 'password', |
|
||||
'password_confirmation' => 'password..', |
|
||||
]); |
|
||||
|
|
||||
$this->seePageIs(route('auth.register')); |
|
||||
$this->see('Email tidak valid.'); |
|
||||
$this->see('Konfirmasi password tidak sesuai.'); |
|
||||
} |
|
||||
|
|
||||
/** @test */ |
|
||||
public function member_register_successfully() |
|
||||
{ |
|
||||
$this->visit(route('auth.register')); |
|
||||
$this->submitForm(trans('auth.register'), [ |
|
||||
'name' => 'Nama Member', |
|
||||
'email' => 'email@mail.com', |
|
||||
'password' => 'password.111', |
|
||||
'password_confirmation' => 'password.111', |
|
||||
]); |
|
||||
|
|
||||
$this->seePageIs(route('home')); |
|
||||
|
|
||||
$this->see(trans('auth.welcome', ['name' => 'Nama Member'])); |
|
||||
|
|
||||
$this->seeInDatabase('users', [ |
|
||||
'name' => 'Nama Member', |
|
||||
'email' => 'email@mail.com', |
|
||||
]); |
|
||||
} |
|
||||
} |
|
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue