Skip to content

Commit

Permalink
- Change app name into shorter on .env
Browse files Browse the repository at this point in the history
- Add script "test" on composer.json
- Enable to use email or username as credential input when login
- Change model name from Company to Branch with table name and migration file
- Create app log
- Create resources lang on bahasa indonesia
- Update authentication feature test
  • Loading branch information
ianriizky committed Jan 26, 2022
1 parent 049d243 commit 3e78ef5
Show file tree
Hide file tree
Showing 28 changed files with 299 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
APP_NAME="BCA CiN Educate Monitoring Achievement"
APP_NAME="BCA CiN"
APP_SHORTNAME=TB
APP_ENV=local
APP_KEY=
Expand Down
21 changes: 15 additions & 6 deletions app/Http/Requests/Auth/LoginRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;

Expand All @@ -20,7 +21,7 @@ class LoginRequest extends FormRequest
public function rules()
{
return [
'email' => ['required', 'string', 'email'],
'identifier' => ['required', 'string'],
'password' => ['required', 'string'],
];
}
Expand All @@ -31,7 +32,7 @@ public function rules()
public function attributes()
{
return [
'email' => trans('Email Address'),
'identifier' => trans('Email') . '/' . trans('Username'),
'password' => trans('Password'),
];
}
Expand All @@ -47,11 +48,19 @@ public function authenticate()
{
$this->ensureIsNotRateLimited();

if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
$credentials = $this->only('password');

if (!Validator::make($this->only('identifier'), ['identifier' => 'email'])->fails()) {
$credentials['email'] = $this->all('identifier');
} else {
$credentials['username'] = $this->all('identifier');
}

if (! Auth::attempt($credentials, $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());

throw ValidationException::withMessages([
'email' => __('auth.failed'),
'identifier' => __('auth.failed'),
]);
}

Expand All @@ -76,7 +85,7 @@ public function ensureIsNotRateLimited()
$seconds = RateLimiter::availableIn($this->throttleKey());

throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'identifier' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
Expand All @@ -90,6 +99,6 @@ public function ensureIsNotRateLimited()
*/
public function throttleKey()
{
return Str::lower($this->input('email')).'|'.$this->ip();
return Str::lower($this->input('identifier')).'|'.$this->ip();
}
}
12 changes: 6 additions & 6 deletions app/Http/Requests/Auth/RegisterRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Requests\Auth;

use App\Models\Company;
use App\Models\Branch;
use App\Models\User;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules;
Expand All @@ -17,7 +17,7 @@ class RegisterRequest extends FormRequest
public function rules()
{
return [
'company_name' => ['required', 'string', 'max:255'],
'branch_name' => ['required', 'string', 'max:255'],

'username' => ['required', 'string', 'max:255', new Rules\Unique(User::class)],
'name' => ['required', 'string', 'max:255'],
Expand All @@ -32,7 +32,7 @@ public function rules()
public function attributes()
{
return [
'company_name' => trans('Company Name'),
'branch_name' => trans('Branch Name'),

'username' => trans('Username'),
'name' => trans('Name'),
Expand All @@ -49,8 +49,8 @@ public function attributes()
*/
public function register(): User
{
$company = Company::create([
'name' => $this->input('company_name'),
$branch = Branch::firstOrCreate([
'name' => $this->input('branch_name'),
]);

/** @var \App\Models\User $user */
Expand All @@ -61,7 +61,7 @@ public function register(): User
'password' => $this->input('password'),
]);

$user->setCompanyRelationValue($company)->save();
$user->setBranchRelationValue($branch)->save();

return $user->fresh();
}
Expand Down
6 changes: 3 additions & 3 deletions app/Models/Company.php → app/Models/Branch.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
use App\Infrastructure\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class Company extends Model
class Branch extends Model
{
use HasFactory,
Concerns\Company\Attribute,
Concerns\Company\Relation;
Concerns\Branch\Attribute,
Concerns\Branch\Relation;

/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace App\Models\Concerns\Company;
namespace App\Models\Concerns\Branch;

/**
* @property string $name
*
* @see \App\Models\Company
* @see \App\Models\Branch
*/
trait Attribute
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace App\Models\Concerns\Company;
namespace App\Models\Concerns\Branch;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\HasMany;

/**
* @property-read \Illuminate\Database\Eloquent\Collection<\App\Models\User> $users
*
* @see \App\Models\Company
* @see \App\Models\Branch
*/
trait Relation
{
Expand Down
28 changes: 14 additions & 14 deletions app/Models/Concerns/User/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,46 @@

namespace App\Models\Concerns\User;

use App\Models\Company;
use App\Models\Branch;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

/**
* @property int $company_id Foreign key of \App\Models\Company.
* @property-read \App\Models\Company $company
* @property int $branch_id Foreign key of \App\Models\Branch.
* @property-read \App\Models\Branch $branch
*
* @see \App\Models\User
*/
trait Relation
{
/**
* Define an inverse one-to-one or many relationship with \App\Models\Company.
* Define an inverse one-to-one or many relationship with \App\Models\Branch.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function company(): BelongsTo
public function branch(): BelongsTo
{
return $this->belongsTo(Company::class);
return $this->belongsTo(Branch::class);
}

/**
* Return \App\Models\Company model relation value.
* Return \App\Models\Branch model relation value.
*
* @return \App\Models\Company
* @return \App\Models\Branch
*/
public function getCompanyRelationValue(): Company
public function getBranchRelationValue(): Branch
{
return $this->getRelationValue('company');
return $this->getRelationValue('branch');
}

/**
* Set \App\Models\Company model relation value.
* Set \App\Models\Branch model relation value.
*
* @param \App\Models\Company $company
* @param \App\Models\Branch $branch
* @return $this
*/
public function setCompanyRelationValue(Company $company)
public function setBranchRelationValue(Branch $branch)
{
$this->company()->associate($company);
$this->branch()->associate($branch);

return $this;
}
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
],
"post-create-project-cmd": [
"@php artisan key:generate --ansi"
]
],
"test": "vendor/bin/pest"
},
"extra": {
"laravel": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @see \App\Models\Company
* @see \App\Models\Branch
*/
class CompanyFactory extends Factory
class BranchFactory extends Factory
{
/**
* {@inheritDoc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Facades\Schema;

/**
* @see \App\Models\Company
* @see \App\Models\Branch
*/
return new class extends Migration
{
Expand All @@ -16,7 +16,7 @@
*/
public function up()
{
Schema::create('companies', function (Blueprint $table) {
Schema::create('branches', function (Blueprint $table) {
$table->id();

$table->string('name');
Expand Down
4 changes: 2 additions & 2 deletions database/migrations/2021_12_13_000002_create_users_table.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

use App\Models\Company;
use App\Models\Branch;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
Expand All @@ -19,7 +19,7 @@ public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->foreignIdFor(Company::class)->nullable()->constrained()->cascadeOnUpdate()->nullOnDelete();
$table->foreignIdFor(Branch::class)->nullable()->constrained()->cascadeOnUpdate()->nullOnDelete();

$table->string('username')->unique();
$table->string('name');
Expand Down
Binary file added public/img/logo-text.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/img/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/img/unsplash/login-bg-backup.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/img/unsplash/login-bg.jpg
100755 → 100644
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion resources/lang/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,5 +792,5 @@
"Unscheduled": "Belum Terjadwal",
"Order Code": "Kode Pesanan",
"Self Created": "Diri Sendiri",
"Company Name": "Nama Perusahaan"
"Branch Name": "Nama Cabang"
}
16 changes: 16 additions & 0 deletions resources/lang/id/admin-lang.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

return [
'transaction' => 'Transaksi',
'order' => 'Pesanan',
'master' => 'Master',
'user' => 'Staf',
'customer' => 'Pelanggan',
'denomination' => 'Nominal',
'branch' => 'Cabang',
'utility' => 'Utilitas',
'role' => 'Peran',
'configuration' => 'Konfigurasi',
'report' => 'Laporan',
'report-order' => 'Laporan Pesanan',
];
18 changes: 18 additions & 0 deletions resources/lang/id/auth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

/*
|--------------------------------------------------------------------------
| Authentication Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used during authentication for various
| messages that we need to display to the user. You are free to modify
| these language lines according to your application's requirements.
|
*/

return [
'failed' => 'Identitas tersebut tidak cocok dengan data kami.',
'password' => 'Kata sandi yang dimasukkan salah.',
'throttle' => 'Terlalu banyak upaya masuk. Silahkan coba lagi dalam :seconds detik.',
];
17 changes: 17 additions & 0 deletions resources/lang/id/pagination.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
|--------------------------------------------------------------------------
| Pagination Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used by the paginator library to build
| the simple pagination links. You are free to change them to anything
| you want to customize your views to better match your application.
|
*/

return [
'next' => 'Berikutnya &raquo;',
'previous' => '&laquo; Sebelumnya',
];
20 changes: 20 additions & 0 deletions resources/lang/id/passwords.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

/*
|--------------------------------------------------------------------------
| Password Reset Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are the default lines which match reasons
| that are given by the password broker for a password update attempt
| has failed, such as for an invalid token or invalid new password.
|
*/

return [
'reset' => 'Kata sandi Anda sudah direset!',
'sent' => 'Kami sudah mengirim surel yang berisi tautan untuk mereset kata sandi Anda!',
'throttled' => 'Harap tunggu sebelum mencoba lagi.',
'token' => 'Token pengaturan ulang kata sandi tidak sah.',
'user' => 'Kami tidak dapat menemukan pengguna dengan alamat surel tersebut.',
];
Loading

0 comments on commit 3e78ef5

Please sign in to comment.