Demo project

This commit is contained in:
Lasse Hassing committed 2021-06-06 15:15:08 +02:00
1 parent 5e4f3540e8
commit a68267d0f0
146 files changed
+41587

No files matched your search

@@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\LoginRequest;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class AuthenticatedSessionController extends Controller
{
/**
* Display the login view.
*
* @return \Illuminate\View\View
*/
public function create()
{
return view('auth.login');
}
/**
* Handle an incoming authentication request.
*
* @param \App\Http\Requests\Auth\LoginRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(LoginRequest $request)
{
$request->authenticate();
$request->session()->regenerate();
return redirect()->intended(RouteServiceProvider::HOME);
}
/**
* Destroy an authenticated session.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function destroy(Request $request)
{
Auth::guard('web')->logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/');
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\ValidationException;
class ConfirmablePasswordController extends Controller
{
/**
* Show the confirm password view.
*
* @return \Illuminate\View\View
*/
public function show()
{
return view('auth.confirm-password');
}
/**
* Confirm the user's password.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function store(Request $request)
{
if (! Auth::guard('web')->validate([
'email' => $request->user()->email,
'password' => $request->password,
])) {
throw ValidationException::withMessages([
'password' => __('auth.password'),
]);
}
$request->session()->put('auth.password_confirmed_at', time());
return redirect()->intended(RouteServiceProvider::HOME);
}
}
@@ -0,0 +1,27 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
class EmailVerificationNotificationController extends Controller
{
/**
* Send a new email verification notification.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function store(Request $request)
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME);
}
$request->user()->sendEmailVerificationNotification();
return back()->with('status', 'verification-link-sent');
}
}
@@ -0,0 +1,23 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Http\Request;
class EmailVerificationPromptController extends Controller
{
/**
* Display the email verification prompt.
*
* @param \Illuminate\Http\Request $request
* @return mixed
*/
public function __invoke(Request $request)
{
return $request->user()->hasVerifiedEmail()
? redirect()->intended(RouteServiceProvider::HOME)
: view('auth.verify-email');
}
}
@@ -0,0 +1,65 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Str;
use Illuminate\Validation\Rules;
class NewPasswordController extends Controller
{
/**
* Display the password reset view.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\View\View
*/
public function create(Request $request)
{
return view('auth.reset-password', ['request' => $request]);
}
/**
* Handle an incoming new password request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request)
{
$request->validate([
'token' => 'required',
'email' => 'required|email',
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
// Here we will attempt to reset the user's password. If it is successful we
// will update the password on an actual user model and persist it to the
// database. Otherwise we will parse the error and return the response.
$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function ($user) use ($request) {
$user->forceFill([
'password' => Hash::make($request->password),
'remember_token' => Str::random(60),
])->save();
event(new PasswordReset($user));
}
);
// If the password was successfully reset, we will redirect the user back to
// the application's home authenticated view. If there is an error we can
// redirect them back to where they came from with their error message.
return $status == Password::PASSWORD_RESET
? redirect()->route('login')->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
class PasswordResetLinkController extends Controller
{
/**
* Display the password reset link request view.
*
* @return \Illuminate\View\View
*/
public function create()
{
return view('auth.forgot-password');
}
/**
* Handle an incoming password reset link request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request)
{
$request->validate([
'email' => 'required|email',
]);
// We will send the password reset link to this user. Once we have attempted
// to send the link, we will examine the response then see the message we
// need to show to the user. Finally, we'll send out a proper response.
$status = Password::sendResetLink(
$request->only('email')
);
return $status == Password::RESET_LINK_SENT
? back()->with('status', __($status))
: back()->withInput($request->only('email'))
->withErrors(['email' => __($status)]);
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Validation\Rules;
class RegisteredUserController extends Controller
{
/**
* Display the registration view.
*
* @return \Illuminate\View\View
*/
public function create()
{
return view('auth.register');
}
/**
* Handle an incoming registration request.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\RedirectResponse
*
* @throws \Illuminate\Validation\ValidationException
*/
public function store(Request $request)
{
$request->validate([
'name' => 'required|string|max:255',
'email' => 'required|string|email|max:255|unique:users',
'password' => ['required', 'confirmed', Rules\Password::defaults()],
]);
$user = User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
event(new Registered($user));
Auth::login($user);
return redirect(RouteServiceProvider::HOME);
}
}
@@ -0,0 +1,30 @@
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Auth\EmailVerificationRequest;
class VerifyEmailController extends Controller
{
/**
* Mark the authenticated user's email address as verified.
*
* @param \Illuminate\Foundation\Auth\EmailVerificationRequest $request
* @return \Illuminate\Http\RedirectResponse
*/
public function __invoke(EmailVerificationRequest $request)
{
if ($request->user()->hasVerifiedEmail()) {
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
}
if ($request->user()->markEmailAsVerified()) {
event(new Verified($request->user()));
}
return redirect()->intended(RouteServiceProvider::HOME.'?verified=1');
}
}
+13
View File
@@ -0,0 +1,13 @@
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
+66
View File
@@ -0,0 +1,66 @@
<?php
namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel
{
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
// \App\Http\Middleware\TrustHosts::class,
\App\Http\Middleware\TrustProxies::class,
\Fruitcake\Cors\HandleCors::class,
\App\Http\Middleware\PreventRequestsDuringMaintenance::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
];
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
// \Illuminate\Session\Middleware\AuthenticateSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'api' => [
'throttle:api',
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'cache.headers' => \Illuminate\Http\Middleware\SetCacheHeaders::class,
'can' => \Illuminate\Auth\Middleware\Authorize::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'password.confirm' => \Illuminate\Auth\Middleware\RequirePassword::class,
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
];
}
+269
View File
@@ -0,0 +1,269 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Actual extends Component
{
protected $listeners = [
'$refresh'
];
// General data
public int $year;
public array $activeMonths;
public int $activeMonthCount;
// Quick add
public string $quickValue;
public int $quickPostID;
public int $quickMonth;
// Clear month
public string $columnName;
public int $columnMonth;
// Edit field
public string $fieldName;
public string $fieldMonthName;
public string $fieldTypeHTML;
public string $fieldHistoryHTML;
public int $fieldPostID;
public int $fieldMonth;
public string $fieldAddValue;
// Delete value
public int $deleteValueID;
public string $deleteValueHTML;
// View mode switch
public string $switchValuesCSS;
public string $switchDifferenceCSS;
public string $switchMode;
// Modals
public bool $modalFieldUpdate;
public bool $modalColumnUpdate;
public bool $modalDelete;
public function mount() {
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first();
$this->quickValue = "";
$this->quickPostID = $category->posts->where('year', $this->year)->count() > 0 ? $category->posts->where('year', $this->year)->first()->id : -1;
$this->quickMonth = intval((new \Datetime())->format("m"));
$this->columnName = "January";
$this->columnMonth = 1;
$this->fieldName = "";
$this->fieldMonthName = $this->columnName;
$this->fieldTypeHTML = "expense";
$this->fieldHistoryHTML = "Nothing";
$this->fieldPostID = $this->quickPostID;
$this->fieldAddValue = "";
$this->month = $this->columnMonth;
$this->deleteValueID = 0;
$this->deleteValueHTML = "";
$this->modalFieldUpdate = false;
$this->modalColumnUpdate = false;
$this->modalDelete = false;
$this->switchMode("values");
}
public function render()
{
$this->activeMonths = \Auth::user()->activeActualMonths($this->year);
$this->activeMonthCount = 0;
foreach($this->activeMonths as $month) {
if($month) {
$this->activeMonthCount++;
}
}
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
if($this->quickPostID == -1) {
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first();
$this->quickPostID = $category->posts->where('year', $this->year)->count() > 0 ? $category->posts->where('year', $this->year)->first()->id : -1;
}
$hf = new \App\Http\Livewire\Helper();
return view('livewire.actual', ["categories" => $categories, "hf" => $hf]);
}
public function quickinput() {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $this->quickPostID)->first();
$value = null;
if($this->quickValue != null && trim($this->quickValue) != "" && is_numeric(trim($this->quickValue))) {
$value = floatval($this->quickValue);
}
if($value != 0) {
$transaction = new \App\Models\TransactionValue();
$transaction->post_id = $post->id;
$transaction->value = $value;
$transaction->month = $this->quickMonth;
$transaction->save();
}
$this->quickValue = "";
$this->emit("focusField", "quickValue");
}
public function openColumnUpdate($month) {
$this->columnName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
$this->columnMonth = $month;
$this->modalColumnUpdate = true;
}
public function closeColumnUpdate() {
$this->modalColumnUpdate = false;
}
public function updateColumn() {
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
foreach($categories as $category) {
foreach($category->posts->where("year", $this->year) as $post) {
foreach(\App\Models\TransactionValue::where("post_id", $post->id)->where("month", $this->columnMonth)->get() as $value) {
if($value != null) {
$value->delete();
}
}
}
}
$this->modalColumnUpdate = false;
}
public function openFieldUpdate($postID, $month) {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $postID)->first();
if($post) {
$this->fieldPostID = $post->id;
$this->fieldName = $post->name;
$this->fieldTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
$this->fieldMonth = $month;
$this->fieldMonthName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
$values = \App\Models\TransactionValue::where("post_id", $post->id)->where("month", $month);
if($values->count() > 0) {
$hf = new \App\Http\Livewire\Helper();
$this->fieldHistoryHTML = "<span class=\"text-sm text-gray-500\">";
$first = true;
foreach($values->get() as $value) {
$v = $value->value * ($post->is_expense ? -1.00 : 1.00);
if(!$first) {
if($value->value > 0) {
$this->fieldHistoryHTML .= " + ";
} else {
$this->fieldHistoryHTML .= " - ";
}
} else {
$first = false;
}
$this->fieldHistoryHTML .= "<span wire:click=\"openDelete(".$value->id.")\">";
$this->fieldHistoryHTML .= $hf->number($v);
$this->fieldHistoryHTML .= "</span>";
}
if($values->count() > 1) {
$this->fieldHistoryHTML .= " = <strong>" . $hf->number($post->monthActualValue($month))."</strong>";
}
$this->fieldHistoryHTML .= "</span>";
} else {
$this->fieldHistoryHTML = "<span class=\"text-sm text-gray-500\">Nothing ...</span>";
}
$this->modalFieldUpdate = true;
$this->emit("focusField", "fieldAddValue");
}
}
public function closeFieldUpdate() {
$this->modalFieldUpdate = false;
}
public function addValue() {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $this->fieldPostID)->first();
$value = null;
if($this->fieldAddValue != null && trim($this->fieldAddValue) != "" && is_numeric(trim($this->fieldAddValue))) {
$value = floatval($this->fieldAddValue);
}
if($value != 0) {
$transaction = new \App\Models\TransactionValue();
$transaction->post_id = $post->id;
$transaction->value = $value;
$transaction->month = $this->fieldMonth;
$transaction->save();
}
$this->fieldAddValue = "";
$this->openFieldUpdate($this->fieldPostID, $this->fieldMonth);
$this->emit("focusField", "fieldAddValue");
}
public function openDelete($valueID) {
$hf = new \App\Http\Livewire\Helper();
$this->deleteValueID = $valueID;
$value = \App\Models\TransactionValue::with("post")->whereHas('post', function ($query) {
return $query->whereHas('category', function($query2) {
return $query2->where('user_id', \Auth::user()->id);
});
})->where("id", $this->deleteValueID)->first();
$this->deleteValueHTML = $hf->number($value->value * ($value->post->is_expense ? -1.0 : 1.0));
$this->modalFieldUpdate = false;
$this->modalDelete = true;
}
public function closeDelete() {
$this->modalFieldUpdate = true;
$this->modalDelete = false;
}
public function deleteValue() {
$value = \App\Models\TransactionValue::with("post")->whereHas('post', function ($query) {
return $query->whereHas('category', function($query2) {
return $query2->where('user_id', \Auth::user()->id);
});
})->where("id", $this->deleteValueID)->first();
if($value != null) {
$value->delete();
}
$this->modalDelete = false;
$this->openFieldUpdate($this->fieldPostID, $this->fieldMonth);
}
public function switchMode($mode) {
$this->switchMode = $mode;
if($mode == "values") {
$this->switchValuesCSS = "bg-blue-700";
$this->switchDifferenceCSS = "bg-gray-300";
} else {
$this->switchValuesCSS = "bg-gray-300";
$this->switchDifferenceCSS = "bg-blue-700";
}
}
}
+65
View File
@@ -0,0 +1,65 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Categories extends Component
{
public $name;
public $deleteID;
public function render()
{
return view('livewire.categories', [
'categories' => \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get()
]);
}
public function create() {
if(trim($this->name) == "") {
$this->name = ""; return;
}
$existing = \App\Models\Category::where("user_id", \Auth::user()->id)->where("name", $this->name)->first();
if($existing != null) {
$this->name = ""; return;
}
$highest = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority", "desc")->first();
if($highest != null) {
$highest = $highest->priority;
} else {
$highest = 0;
}
$cat = new \App\Models\Category();
$cat->user_id = \Auth::user()->id;
$cat->name = trim($this->name);
$cat->priority = $highest + 1;
$cat->save();
$this->name = "";
}
public function delete() {
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->deleteID)->first();
if($cat) {
$cat->delete();
}
}
public function moveUp($catID) {
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
if($cat) {
$cat->move(true);
}
}
public function moveDown($catID) {
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
if($cat) {
$cat->move(false);
}
}
}
+10
View File
@@ -0,0 +1,10 @@
<?php
namespace App\Http\Livewire;
class Helper {
public function Number($value) {
return '<span class="'.(round($value) == 0 ? 'col-zero' : (round($value) > 0 ? 'col-pos' : 'col-neg')) .'">'.number_format(abs(round($value)), 0).'</span>';
}
}
+296
View File
@@ -0,0 +1,296 @@
<?php
namespace App\Http\Livewire;
use Livewire\Component;
class Projected extends Component
{
// General data
public int $year;
public array $activeMonths;
public int $activeMonthCount;
// Creating posts
public string $createName;
public string $createType;
public int $createCategoryID;
// Updating rows
public string $rowName;
public string $rowTypeHTML;
public string $rowValue;
public int $rowPostID;
// Updating fields
public string $fieldName;
public string $fieldTypeHTML;
public int $fieldMonth;
public string $fieldMonthName;
public string $fieldValue;
public int $fieldPostID;
// Update column
public string $columnName;
public int $columnMonth;
// Delete row
public int $deletePostID;
public string $deleteName;
// Copy year
public int $copyYear;
public string $copyMethod;
// Modals
public bool $modalRowUpdate;
public bool $modalFieldUpdate;
public bool $modalColumnUpdate;
public bool $modalDelete;
public function mount() {
$this->createName = "";
$this->createType = "expense";
$this->createCategoryID = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first()->id;
$this->rowName = "";
$this->rowTypeHTML = "expense";
$this->rowValue = "";
$this->rowPostID = 0;
$this->fieldName = "";
$this->fieldTypeHTML = "expense";
$this->fieldMonth = 1;
$this->fieldMonthName = "January";
$this->fieldValue = "";
$this->fieldPostID = 0;
$this->columnName = "January";
$this->columnMonth = 1;
$this->deletePostID = 0;
$this->deleteName = "";
$this->modalRowUpdate = false;
$this->modalFieldUpdate = false;
$this->modalColumnUpdate = false;
$this->modalDelete = false;
$this->copyYear = 0;
$this->copyMethod = "full";
}
public function render()
{
$this->activeMonths = \Auth::user()->activeMonths($this->year);
$this->activeMonthCount = 0;
foreach($this->activeMonths as $month) {
if($month) {
$this->activeMonthCount++;
}
}
$categories = \App\Models\Category::with(["posts" => function($query) {
$query->where("year", $this->year);
}])->where("user_id", \Auth::user()->id)->orderBy("priority")->get();
$yearList = [];
if(!\Auth::user()->hasPosts($this->year)) {
$results = \DB::select(
\DB::raw("SELECT DISTINCT posts.year
FROM posts
INNER JOIN categories ON posts.category_id = categories.id
WHERE
categories.user_id = :user_id
ORDER BY posts.year DESC"),
array('user_id' => \Auth::user()->id));
foreach($results as $result) {
if($this->copyYear == 0) {
$this->copyYear = $result->year;
}
$yearList[] = $result->year;
}
}
$hf = new \App\Http\Livewire\Helper();
return view('livewire.projected', ['categories' => $categories, 'yearList' => $yearList, 'hf' => $hf]);
}
public function openDelete() {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $this->rowPostID)->first();
if($post) {
$this->deletePostID = $post->id;
$this->deleteName = $post->name;
$this->modalDelete = true;
$this->modalRowUpdate = false;
}
}
public function deletePost() {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $this->deletePostID)->first();
if($post) {
$post->delete();
$this->emitTo('actual', '$refresh');
}
$this->modalDelete = false;
}
public function closeDelete() {
$this->modalDelete = false;
}
public function openColumnUpdate($month) {
$this->columnName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
$this->columnMonth = $month;
$this->modalColumnUpdate = true;
}
public function updateColumn() {
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
foreach($categories as $category) {
foreach($category->posts->where("year", $this->year) as $post) {
$value = \App\Models\PostValue::where("post_id", $post->id)->where("month", $this->columnMonth)->first();
if($value != null) {
$value->delete();
}
}
}
$this->emitTo('actual', '$refresh');
$this->modalColumnUpdate = false;
}
public function closeColumnUpdate() {
$this->modalColumnUpdate = false;
}
public function openFieldUpdate($id, $month) {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $id)->first();
if($post) {
$this->fieldPostID = $post->id;
$this->fieldName = $post->name;
$this->fieldTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
$this->fieldMonth = $month;
$this->fieldMonthName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
$this->fieldValue = $post->monthValue($month) * ($post->is_expense ? -1.00 : 1.00);
if($this->fieldValue == "-0") {
$this->fieldValue = "0";
}
$this->modalFieldUpdate = true;
$this->emit("focusField", "fieldValue");
}
}
public function updateField() {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $this->fieldPostID)->first();
$value = null;
if($this->fieldValue != null && trim($this->fieldValue) != "" && is_numeric(trim($this->fieldValue))) {
$value = floatval($this->fieldValue);
}
if($post != null && $value !== null) {
$post->setMonthValue($this->fieldMonth, $value);
}
$this->emitTo('actual', '$refresh');
$this->modalFieldUpdate = false;
}
public function closeFieldUpdate() {
$this->modalFieldUpdate = false;
}
public function openRowUpdate($id) {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $id)->first();
if($post) {
$this->rowPostID = $post->id;
$this->rowName = $post->name;
$this->rowTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
$this->modalRowUpdate = true;
$this->emit("focusField", "rowValue");
}
}
public function updateRow() {
$post = \App\Models\Post::whereHas('category', function ($query) {
return $query->where('user_id', \Auth::user()->id);
})->where("id", $this->rowPostID)->first();
$value = null;
if($this->rowValue != null && trim($this->rowValue) != "" && is_numeric(trim($this->rowValue))) {
$value = floatval($this->rowValue);
}
if($post != null && $value !== null) {
for($m=1;$m<=12;$m++) {
$post->setMonthValue($m, $value);
}
}
$this->emitTo('actual', '$refresh');
$this->rowValue = "";
$this->modalRowUpdate = false;
}
public function closeRowUpdate() {
$this->modalRowUpdate = false;
}
public function createPost() {
if(trim($this->createName) == "") {
$this->createName = ""; return;
}
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->createCategoryID)->first();
if($category == null) {
return;
}
$expense = $this->createType != "income";
$post = new \App\Models\Post();
$post->year = $this->year;
$post->name = trim($this->createName);
$post->is_expense = $expense;
$post->category_id = $this->createCategoryID;
$post->save();
$this->createName = "";
$this->emitTo('actual', '$refresh');
$this->emit("focusField", "createName");
}
public function copyBudget() {
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
foreach($categories as $category) {
foreach($category->posts->where("year", $this->copyYear) as $post) {
$newPost = new \App\Models\Post();
$newPost->category_id = $category->id;
$newPost->year = $this->year;
$newPost->name = $post->name;
$newPost->is_expense = $post->is_expense;
$newPost->save();
if($this->copyMethod == "full") {
for($m=1; $m <= 12; $m++) {
$newPost->setMonthValue($m, $post->monthValue($m) * ($newPost->is_expense ? -1.00 : 1.00));
}
}
}
}
$this->emitTo('actual', '$refresh');
}
}
+21
View File
@@ -0,0 +1,21 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Auth\Middleware\Authenticate as Middleware;
class Authenticate extends Middleware
{
/**
* Get the path the user should be redirected to when they are not authenticated.
*
* @param \Illuminate\Http\Request $request
* @return string|null
*/
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
class EncryptCookies extends Middleware
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
//
];
}
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
class PreventRequestsDuringMaintenance extends Middleware
{
/**
* The URIs that should be reachable while maintenance mode is enabled.
*
* @var array
*/
protected $except = [
//
];
}
@@ -0,0 +1,32 @@
<?php
namespace App\Http\Middleware;
use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class RedirectIfAuthenticated
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @param string|null ...$guards
* @return mixed
*/
public function handle(Request $request, Closure $next, ...$guards)
{
$guards = empty($guards) ? [null] : $guards;
foreach ($guards as $guard) {
if (Auth::guard($guard)->check()) {
return redirect(RouteServiceProvider::HOME);
}
}
return $next($request);
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
class TrimStrings extends Middleware
{
/**
* The names of the attributes that should not be trimmed.
*
* @var array
*/
protected $except = [
'current_password',
'password',
'password_confirmation',
];
}
+20
View File
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Http\Middleware\TrustHosts as Middleware;
class TrustHosts extends Middleware
{
/**
* Get the host patterns that should be trusted.
*
* @return array
*/
public function hosts()
{
return [
$this->allSubdomainsOfApplicationUrl(),
];
}
}
+23
View File
@@ -0,0 +1,23 @@
<?php
namespace App\Http\Middleware;
use Fideloper\Proxy\TrustProxies as Middleware;
use Illuminate\Http\Request;
class TrustProxies extends Middleware
{
/**
* The trusted proxies for this application.
*
* @var array|string|null
*/
protected $proxies;
/**
* The headers that should be used to detect proxies.
*
* @var int
*/
protected $headers = Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_HOST | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO | Request::HEADER_X_FORWARDED_AWS_ELB;
}
+17
View File
@@ -0,0 +1,17 @@
<?php
namespace App\Http\Middleware;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
class VerifyCsrfToken extends Middleware
{
/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
//
];
}
+93
View File
@@ -0,0 +1,93 @@
<?php
namespace App\Http\Requests\Auth;
use Illuminate\Auth\Events\Lockout;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use Illuminate\Validation\ValidationException;
class LoginRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'email' => 'required|string|email',
'password' => 'required|string',
];
}
/**
* Attempt to authenticate the request's credentials.
*
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
public function authenticate()
{
$this->ensureIsNotRateLimited();
if (! Auth::attempt($this->only('email', 'password'), $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => __('auth.failed'),
]);
}
RateLimiter::clear($this->throttleKey());
}
/**
* Ensure the login request is not rate limited.
*
* @return void
*
* @throws \Illuminate\Validation\ValidationException
*/
public function ensureIsNotRateLimited()
{
if (! RateLimiter::tooManyAttempts($this->throttleKey(), 5)) {
return;
}
event(new Lockout($this));
$seconds = RateLimiter::availableIn($this->throttleKey());
throw ValidationException::withMessages([
'email' => trans('auth.throttle', [
'seconds' => $seconds,
'minutes' => ceil($seconds / 60),
]),
]);
}
/**
* Get the rate limiting throttle key for the request.
*
* @return string
*/
public function throttleKey()
{
return Str::lower($this->input('email')).'|'.$this->ip();
}
}