23 Commits

Author SHA1 Message Date
54abd983aa Update js libraries 2021-02-14 23:20:43 -03:00
5d7aee7778 Showing tracker only in production 2020-08-22 20:01:58 -03:00
b767265200 Update NPM and compile assets 2020-08-22 14:14:46 -03:00
2ed6065901 Including the Tracking number directly 2020-08-22 14:10:59 -03:00
0b3f6d4837 Including my OWA Tracker 2020-08-22 11:44:03 -03:00
6339a23b02 Composer update 2020-08-22 01:26:20 -03:00
dc0c4e679b NPM Update 2020-08-22 01:26:08 -03:00
bb849dba4b npm updated 2020-04-05 12:19:23 -03:00
437e847cdd Updating npm and composer 2019-12-03 00:02:43 -03:00
vagrant
f31228843f Updating libraries 2019-07-18 22:56:17 +00:00
28520edee9 Merge branch 'master' of github.com:brunofontes/shareit 2019-07-18 19:46:11 -03:00
74eb254297 Including home.blade -> hasFocus test 2019-05-31 11:42:18 -03:00
2f16d4dc60 Composer update 2019-05-31 11:42:00 -03:00
130e47b198 Create test.php 2019-02-26 20:18:22 -03:00
6be295e25b Bug Fixing - forgot to add the use App\FlashMessage on AlertController 2018-10-21 13:13:09 -03:00
00c382e1cc Avoiding issues and refactoring code
I made the code more passive, avoiding issued at taking, returning,
storing alerts or removing alerts from an item.

Now they all check if it is with you before returning/deleting
alert etc. I am not sure if all cases are covered, but they are
better than before. I had one only issued on this on that time,
but I prefer to prioritize safety/security.

I took the opportunitie to move some code from Controllers to
the model itself, as they were changing with the DB.
2018-10-21 13:09:06 -03:00
2bc2792a24 Bug Fixed: avoiding item waiting_user across take/return
It happend once: a user asked to be added to the waiting
list at the same time other user was returning the item.

So the user ended up waiting for the user he was already
using.
2018-10-21 11:57:23 -03:00
3d6b0dbeca Fixed bug causing error 500 on production
Some PHP version or configuration were causing this error.

On app.blade.php of local branch, I could use "$usedItems ? :"
even if $usedItems were null, but I had to check an "isset" to the production.

On HomecController, I had to change the "object" parameter of getUsername
to "\Illuminate\Database\Eloquent\Collection" to make it work.

I took the chance to just show the number of itens in use
if it were greater than 0.
2018-10-16 20:28:59 -03:00
52223676dc Trying to fix an 500 error on production 2018-10-16 20:18:10 -03:00
7a8d5ccaff Refreshing and Including number of used items on Title
It was necessary to keep refreshing the page to
check if an item was returned when we did not
want to be alerted. So, now, the page refresh
itself every 2 minutes (while I do not know how
to use Laravel broadcasting) and the title shows
the number of items in use (including when used
by you).
2018-10-16 15:15:05 -03:00
8c4fe0a489 Refactoring
Including some use for classes;
REfactoring the HomeController, to make it cleaner
and avoid repeating code.
2018-10-10 00:46:28 -03:00
69f0722c79 Let me know if anyone subscribed during alpha
As the project is still alpha, I just want to know if someone
subscribed at it using a dummy e-mail address.
2018-10-03 19:42:35 -03:00
5667fd0a86 Composer update
Plugins updated with composer.
2018-10-03 00:32:23 -03:00
23 changed files with 12568 additions and 6602 deletions

View File

@@ -19,6 +19,8 @@ class ReturnItem
/** /**
* Create a new event instance. * Create a new event instance.
* *
* @param Item $item The returned item.
*
* @return void * @return void
*/ */
public function __construct(Item $item) public function __construct(Item $item)

View File

@@ -3,22 +3,43 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Auth; use Auth;
use Mail;
use \App\User; use \App\User;
use App\FlashMessage;
use \App\Mail\UserWaiting; use \App\Mail\UserWaiting;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class AlertController extends Controller class AlertController extends Controller
{ {
/**
* Store the waiting_user_id on db
* so the user can be alerted when
* the item is free
*
* @param Request $request Form data
*
* @return redirect to home
*/
public function store(Request $request) public function store(Request $request)
{ {
$item = User::loggedIn()->items()->find(request('item')); $item = User::loggedIn()->items()->find(request('item'));
$item->waiting_user_id = Auth::id(); if (!$item->used_by) {
$item->timestamps = false; session()->flash(
$item->save(); FlashMessage::PRIMARY,
__('Oh! This item has just being returned. Take it before anyone else!')
);
return redirect('home');
}
if ($item->used_by == Auth::id()) {
return redirect('home');
}
$item->storeAlert();
$loggedUser = Auth::user()->name; $loggedUser = Auth::user()->name;
$userWithItem = User::find($item->used_by); $userWithItem = User::find($item->used_by);
\Mail::to($userWithItem) Mail::to($userWithItem)
->locale($userWithItem->language) ->locale($userWithItem->language)
->send(new UserWaiting($loggedUser, $userWithItem->name, $item)); ->send(new UserWaiting($loggedUser, $userWithItem->name, $item));
@@ -28,10 +49,12 @@ class AlertController extends Controller
public function delete(Request $request) public function delete(Request $request)
{ {
$item = User::loggedIn()->items()->find(request('item')); $item = User::loggedIn()->items()->find(request('item'));
$item->waiting_user_id = null;
$item->timestamps = false;
$item->save();
if ($item->waiting_user_id != Auth::id()) {
return redirect('home');
}
$item->removeAlert();
return redirect('home'); return redirect('home');
} }
} }

View File

@@ -9,6 +9,7 @@ use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator; use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers; use Illuminate\Foundation\Auth\RegistersUsers;
use App\FlashMessage; use App\FlashMessage;
use Mail;
class RegisterController extends Controller class RegisterController extends Controller
{ {
@@ -71,7 +72,13 @@ class RegisterController extends Controller
'password' => Hash::make($data['password']), 'password' => Hash::make($data['password']),
]); ]);
\Mail::to($user)->send(new Welcome($user)); Mail::to($user)->send(new Welcome($user));
$text = "Share it! New user: {$user->name} ($user->email)";
Mail::raw($text, function ($message) use ($text) {
$message->to('brunofontes.shareit@mailnull.com');
$message->subject($text);
});
session()->flash(FlashMessage::PRIMARY, __('Thanks for registering. Please, do not forget to validate your e-mail address.')); session()->flash(FlashMessage::PRIMARY, __('Thanks for registering. Please, do not forget to validate your e-mail address.'));

View File

@@ -6,6 +6,8 @@ use \App\User;
class HomeController extends Controller class HomeController extends Controller
{ {
protected $activeUsers = [];
/** /**
* Create a new controller instance. * Create a new controller instance.
* *
@@ -16,6 +18,50 @@ class HomeController extends Controller
$this->middleware('auth'); $this->middleware('auth');
} }
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$items = User::loggedIn()->items()->with('users')->get();
$numberOfUsedItems = 0;
foreach ($items as $item) {
if (isset($item->used_by)) {
$numberOfUsedItems++;
}
$this->getUsername($item->users, $item->used_by);
$this->getUsername($item->users, $item->waiting_user_id);
}
$products = $items
->sortBy('product.name', SORT_NATURAL | SORT_FLAG_CASE)
->groupBy('product.name');
return view(
'home',
['products' => $products, 'users' => $this->activeUsers, 'usedItems' => $numberOfUsedItems]
);
}
/**
* Get the username from an specified user id.
*
* @param object $itemUsers Array with IDs and usernames
* @param int $id The user id to search for
*
* @return void
*/
protected function getUsername(\Illuminate\Database\Eloquent\Collection $itemUsers, ?int $id)
{
if ($id && !isset($this->activeUsers[$id])) {
$this->activeUsers[$id] = $this->findName($itemUsers, $id);
}
}
/** /**
* Get a name from a specific id in a array * Get a name from a specific id in a array
* *
@@ -32,41 +78,4 @@ class HomeController extends Controller
} }
} }
} }
/**
* Check if the user_id alreay exists on $users array.
*
* @param array $users The array with users
* @param int $user_id The user_id to try to find on array
*
* @return boolean
*/
public function isNewUser($users, $user_id)
{
return ($user_id && !isset($users[$user_id]));
}
/**
* Show the application dashboard.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = [];
$items = User::loggedIn()->items()->with('users')->get();
foreach ($items as $item) {
if ($this->isNewUser($users, $item->used_by)) {
$users[$item->used_by] = $this->findName($item->users, $item->used_by);
}
if ($this->isNewUser($users, $item->waiting_user_id)) {
$users[$item->waiting_user_id] = $this->findName($item->users, $item->waiting_user_id);
}
}
$products = $items->sortBy('product.name', SORT_NATURAL | SORT_FLAG_CASE)->groupBy('product.name');
return view('home', compact('products', 'users'));
}
} }

View File

@@ -2,33 +2,63 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use \App\Item; use Auth;
use \App\User; use Lang;
use Illuminate\Http\Request; use App\Item;
use App\User;
use App\Events\ReturnItem; use App\Events\ReturnItem;
use Illuminate\Http\Request;
use PhpParser\Node\Stmt\TryCatch;
/**
* Responsible to Take and Return an Item.
*/
class TakeController extends Controller class TakeController extends Controller
{ {
/**
* The user take an item
*
* @param Request $request The form data
*
* @return home view
*/
public function store(Request $request) public function store(Request $request)
{ {
$item = User::loggedIn()->items()->find(request('item')); $item = User::loggedIn()->items()->find(request('item'));
if ($item->used_by) {
try {
$item->takeItem();
} catch (\Exception $e) {
return back()->withErrors( return back()->withErrors(
\Lang::getFromJson( Lang::getFromJson('This item is already taken')
"This item is already taken"
)
); );
} }
$item->used_by = \Auth::id();
$item->save();
return redirect('home'); return redirect('home');
} }
/**
* User return an item
* Trigger an event: ReturnItem
*
* @param Request $request Form data
*
* @return View home
*/
public function delete(Request $request) public function delete(Request $request)
{ {
$item = User::loggedIn()->items()->find(request('item')); $item = User::loggedIn()->items()->find(request('item'));
try {
$item->returnItem();
} catch (\Exception $e) {
return back()->withErrors(
Lang::getFromJson("You cannot return an item that is not with you")
);
}
event(new ReturnItem($item)); event(new ReturnItem($item));
$item->returnItem();
return redirect('home'); return redirect('home');
} }
} }

View File

@@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use \Lang;
use \App\User; use \App\User;
use \App\Item; use \App\Item;
use \App\Product; use \App\Product;
@@ -43,7 +44,7 @@ class UserController extends Controller
if (count($userArray) == 0) { if (count($userArray) == 0) {
return back()->withErrors( return back()->withErrors(
\Lang::getFromJson("The e-mail address is not registered yet.") Lang::getFromJson("The e-mail address is not registered yet.")
); );
} }
@@ -54,7 +55,7 @@ class UserController extends Controller
->syncWithoutDetaching([request('item_id')]); ->syncWithoutDetaching([request('item_id')]);
} else { } else {
return back()->withErrors( return back()->withErrors(
\Lang::getFromJson( Lang::getFromJson(
"You cannot add a user to a product that is not yourse." "You cannot add a user to a product that is not yourse."
) )
); );
@@ -85,7 +86,7 @@ class UserController extends Controller
->detach([request('item_id')]); ->detach([request('item_id')]);
} else { } else {
return back()->withErrors( return back()->withErrors(
\Lang::getFromJson( Lang::getFromJson(
"You cannot remove a user from a product that is not yourse." "You cannot remove a user from a product that is not yourse."
) )
); );

View File

@@ -2,7 +2,10 @@
namespace App; namespace App;
use Auth;
use Lang;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Exception;
class Item extends Model class Item extends Model
{ {
@@ -36,7 +39,23 @@ class Item extends Model
*/ */
public static function fromAuthUser() public static function fromAuthUser()
{ {
return (new static)->where('user_id', \Auth::id()); return (new static)->where('user_id', Auth::id());
}
/**
* Take a specified item
*
* @return void
*/
public function takeItem()
{
if (isset($this->used_by)) {
throw new Exception("Trying to take an Item that is in use", 1);
}
$this->used_by = Auth::id();
$this->waiting_user_id = null;
$this->save();
} }
/** /**
@@ -46,8 +65,35 @@ class Item extends Model
*/ */
public function returnItem() public function returnItem()
{ {
if ($this->used_by != Auth::id()) {
throw new Exception("Trying to return an empty Item or from other user", 1);
}
$this->used_by = null; $this->used_by = null;
$this->save();
}
/**
* Store a waiting user to the item
*
* @return void
*/
public function storeAlert()
{
$this->waiting_user_id = Auth::id();
$this->timestamps = false;
$this->save();
}
/**
* Remove a waiting user to the item
*
* @return void
*/
public function removeAlert()
{
$this->waiting_user_id = null; $this->waiting_user_id = null;
$this->timestamps = false;
$this->save(); $this->save();
} }
} }

View File

@@ -25,7 +25,8 @@ class AlertReturnedItem
* Send an email to the user that * Send an email to the user that
* is waiting for the item * is waiting for the item
* *
* @param ReturnItem $item * @param ReturnItem $event The return event that contains an item
*
* @return void * @return void
*/ */
public function handle(ReturnItem $event) public function handle(ReturnItem $event)

2978
composer.lock generated

File diff suppressed because it is too large Load Diff

9869
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -10,13 +10,17 @@
"production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js" "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
}, },
"devDependencies": { "devDependencies": {
"axios": "^0.18", "axios": "^0.21",
"bootstrap": "^4.0.0", "bootstrap": "^4.6.0",
"cross-env": "^5.1", "cross-env": "^5.2.1",
"jquery": "^3.2", "jquery": "^3.5.1",
"laravel-mix": "^2.0", "laravel-mix": "^5.0.9",
"lodash": "^4.17.5", "lodash": "^4.17.20",
"popper.js": "^1.12", "popper.js": "^1.16.1",
"vue": "^2.5.7" "resolve-url-loader": "^3.1.2",
"sass": "^1.32.7",
"sass-loader": "^8.0.2",
"vue": "^2.6.12",
"vue-template-compiler": "^2.6.12"
} }
} }

14
public/css/app.css vendored

File diff suppressed because one or more lines are too long

3
public/js/app.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,77 @@
/*!
* Bootstrap v4.5.2 (https://getbootstrap.com/)
* Copyright 2011-2020 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
*/
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/
/*!
* Sizzle CSS Selector Engine v2.3.5
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://js.foundation/
*
* Date: 2020-03-14
*/
/*!
* Vue.js v2.6.12
* (c) 2014-2020 Evan You
* Released under the MIT License.
*/
/*!
* jQuery JavaScript Library v3.5.1
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright JS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2020-05-04T22:49Z
*/
/**
* @license
* Lodash <https://lodash.com/>
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
* Released under MIT license <https://lodash.com/license>
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
*/
/**!
* @fileOverview Kickass library to create and place poppers near their reference elements.
* @version 1.16.1
* @license
* Copyright (c) 2016 Federico Zivolo and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

4
public/mix-manifest.json Normal file
View File

@@ -0,0 +1,4 @@
{
"/js/app.js": "/js/app.js",
"/css/app.css": "/css/app.css"
}

View File

@@ -0,0 +1,15 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| 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.
|
*/
'failed' => 'These credentials do not match our records.',
'throttle' => 'Too many login attempts. Please try again in :seconds seconds.',
];

View File

@@ -32,7 +32,7 @@
":itemname is available!": ":itemname está disponível!", ":itemname is available!": ":itemname está disponível!",
"Hi, :username,": "Olá, :username,", "Hi, :username,": "Olá, :username,",
"Good news: :itemname is available!": "Uma boa notícia: :itemname está disponível!", "Good news: :itemname is available!": "Boa notícia: :itemname está disponível!",
"The item <em>:itemname (:productname)</em> is now available on **Share&nbsp;It**.": "O item <em>:itemname (:productname)</em> já está disponível no **Share&nbsp;It**.", "The item <em>:itemname (:productname)</em> is now available on **Share&nbsp;It**.": "O item <em>:itemname (:productname)</em> já está disponível no **Share&nbsp;It**.",
"**Take It** before anyone else at the website:": "Entre no nosso site para usar o item antes de todo mundo.", "**Take It** before anyone else at the website:": "Entre no nosso site para usar o item antes de todo mundo.",
@@ -46,5 +46,7 @@
"The item doesn't exist.": "O item não existe.", "The item doesn't exist.": "O item não existe.",
"The product doesn't exist or doesn't belongs to you.": "O produto não existe ou não é seu.", "The product doesn't exist or doesn't belongs to you.": "O produto não existe ou não é seu.",
"This item is already taken": "Esse item já está sendo usado" "This item is already taken": "Esse item já está sendo usado.",
"You cannot return an item that is not with you": "Você não pode devolver um item que não está com você.",
"Oh! This item has just being returned. Take it before anyone else!": "Opa! Esse item acabou de ser devolvido. Aproveite!"
} }

View File

@@ -1,6 +1,17 @@
@extends('layouts.app') @extends('layouts.app')
@section('content') @section('content')
<script type="text/javascript">
setInterval(
function() {
if (!document.hasFocus() ) {
window.location.reload(true);
}
},
2*60000); //NOTE: period is passed in milliseconds
</script>
<div class="container"> <div class="container">
<div class="row justify-content-center"> <div class="row justify-content-center">
<div class="col-md-8"> <div class="col-md-8">

View File

@@ -8,7 +8,7 @@
<!-- CSRF Token --> <!-- CSRF Token -->
<meta name="csrf-token" content="{{ csrf_token() }}"> <meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title> <title>{{ config('app.name', 'Laravel') }} {{ isset($usedItems) && $usedItems > 0 ? "(${usedItems})" : '' }}</title>
<!-- Scripts --> <!-- Scripts -->
<script src="{{ asset('js/app.js') }}" defer></script> <script src="{{ asset('js/app.js') }}" defer></script>

View File

@@ -16,4 +16,5 @@
</div> </div>
<!-- Copyright --> <!-- Copyright -->
</div> </div>
</footer> </footer>
@include('layouts.tracker')

View File

@@ -0,0 +1,5 @@
@production
<script type="text/javascript">
var owa_baseUrl='https://brunofontes.net/owa/';var owa_cmds=owa_cmds||[];owa_cmds.push(['setSiteId','15a38975230dfe7528d647a1419be7f7']);owa_cmds.push(['trackPageView']);owa_cmds.push(['trackClicks']);owa_cmds.push(['trackDomStream']);(function(){var _owa=document.createElement('script');_owa.type='text/javascript';_owa.async=true;owa_baseUrl=('https:'==document.location.protocol?window.owa_baseSecUrl||owa_baseUrl.replace(/http:/,'https:'):owa_baseUrl);_owa.src=owa_baseUrl+'modules/base/js/owa.tracker-combined-min.js';var _owa_s=document.getElementsByTagName('script')[0];_owa_s.parentNode.insertBefore(_owa,_owa_s)}());
</script>
@endproduction

View File

@@ -114,5 +114,6 @@
</div> </div>
</div> </div>
</div> </div>
@include('layouts.tracker')
</body> </body>
</html> </html>

5923
yarn.lock

File diff suppressed because it is too large Load Diff