diff --git a/app/Http/Controllers/Auth/ConfirmPasswordController.php b/app/Http/Controllers/Auth/ConfirmPasswordController.php new file mode 100644 index 0000000..138c1f0 --- /dev/null +++ b/app/Http/Controllers/Auth/ConfirmPasswordController.php @@ -0,0 +1,40 @@ +middleware('auth'); + } +} diff --git a/app/Http/Controllers/Auth/ForgotPasswordController.php b/app/Http/Controllers/Auth/ForgotPasswordController.php new file mode 100644 index 0000000..465c39c --- /dev/null +++ b/app/Http/Controllers/Auth/ForgotPasswordController.php @@ -0,0 +1,22 @@ +middleware('guest')->except('logout'); + } + + public function username() + { + return 'name'; + } +} diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php new file mode 100644 index 0000000..c6a6de6 --- /dev/null +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -0,0 +1,73 @@ +middleware('guest'); + } + + /** + * Get a validator for an incoming registration request. + * + * @param array $data + * @return \Illuminate\Contracts\Validation\Validator + */ + protected function validator(array $data) + { + return Validator::make($data, [ + 'name' => ['required', 'string', 'max:255'], + 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'], + 'password' => ['required', 'string', 'min:8', 'confirmed'], + ]); + } + + /** + * Create a new user instance after a valid registration. + * + * @param array $data + * @return \App\User + */ + protected function create(array $data) + { + return User::create([ + 'name' => $data['name'], + 'email' => $data['email'], + 'password' => Hash::make($data['password']), + ]); + } +} diff --git a/app/Http/Controllers/Auth/ResetPasswordController.php b/app/Http/Controllers/Auth/ResetPasswordController.php new file mode 100644 index 0000000..b1726a3 --- /dev/null +++ b/app/Http/Controllers/Auth/ResetPasswordController.php @@ -0,0 +1,30 @@ +middleware('auth'); + $this->middleware('signed')->only('verify'); + $this->middleware('throttle:6,1')->only('verify', 'resend'); + } +} diff --git a/app/Http/Controllers/ProductoController.php b/app/Http/Controllers/ProductoController.php new file mode 100644 index 0000000..981861d --- /dev/null +++ b/app/Http/Controllers/ProductoController.php @@ -0,0 +1,28 @@ +middleware('auth'); + } + + /** + * Show the application dashboard. + * + * @return \Illuminate\Contracts\Support\Renderable + */ + public function index() + { + return view('productos'); + } +} diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 36ced13..8fdf11b 100644 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -3,6 +3,7 @@ namespace App\Http; use Illuminate\Foundation\Http\Kernel as HttpKernel; +use Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful; class Kernel extends HttpKernel { @@ -40,6 +41,7 @@ class Kernel extends HttpKernel ], 'api' => [ + EnsureFrontendRequestsAreStateful::class, 'throttle:60,1', \Illuminate\Routing\Middleware\SubstituteBindings::class, ], diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index 540d17b..3a816d8 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -21,7 +21,7 @@ class RouteServiceProvider extends ServiceProvider * * @var string */ - public const HOME = '/home'; + public const HOME = '/'; /** * Define your route model bindings, pattern filters, etc. diff --git a/composer.json b/composer.json index c580243..3778816 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,9 @@ "fruitcake/laravel-cors": "^2.0", "guzzlehttp/guzzle": "^6.3.1|^7.0.1", "laravel/framework": "^7.29", + "laravel/sanctum": "^2.13", "laravel/tinker": "^2.5", + "laravel/ui": "*", "league/csv": "^9.8" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 7146bea..eb23c75 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "29ba109acea0ebdbcafb4cf531e83199", + "content-hash": "8389a7c37eb75068185ce61fe4270621", "packages": [ { "name": "asm89/stack-cors", @@ -1045,6 +1045,70 @@ }, "time": "2021-12-07T14:56:47+00:00" }, + { + "name": "laravel/sanctum", + "version": "v2.13.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/sanctum.git", + "reference": "b4c07d0014b78430a3c827064217f811f0708eaa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/sanctum/zipball/b4c07d0014b78430a3c827064217f811f0708eaa", + "reference": "b4c07d0014b78430a3c827064217f811f0708eaa", + "shasum": "" + }, + "require": { + "ext-json": "*", + "illuminate/contracts": "^6.9|^7.0|^8.0", + "illuminate/database": "^6.9|^7.0|^8.0", + "illuminate/support": "^6.9|^7.0|^8.0", + "php": "^7.2|^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.0", + "orchestra/testbench": "^4.0|^5.0|^6.0", + "phpunit/phpunit": "^8.0|^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + }, + "laravel": { + "providers": [ + "Laravel\\Sanctum\\SanctumServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Sanctum\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Sanctum provides a featherweight authentication system for SPAs and simple APIs.", + "keywords": [ + "auth", + "laravel", + "sanctum" + ], + "support": { + "issues": "https://github.com/laravel/sanctum/issues", + "source": "https://github.com/laravel/sanctum" + }, + "time": "2021-12-14T17:49:47+00:00" + }, { "name": "laravel/tinker", "version": "v2.6.3", @@ -1113,6 +1177,61 @@ }, "time": "2021-12-07T16:41:42+00:00" }, + { + "name": "laravel/ui", + "version": "v2.5.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/ui.git", + "reference": "d01a705763c243b07be795e9d1bb47f89260f73d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/ui/zipball/d01a705763c243b07be795e9d1bb47f89260f73d", + "reference": "d01a705763c243b07be795e9d1bb47f89260f73d", + "shasum": "" + }, + "require": { + "illuminate/console": "^7.0", + "illuminate/filesystem": "^7.0", + "illuminate/support": "^7.0", + "php": "^7.2.5|^8.0" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Ui\\UiServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Ui\\": "src/", + "Illuminate\\Foundation\\Auth\\": "auth-backend/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel UI utilities and presets.", + "keywords": [ + "laravel", + "ui" + ], + "support": { + "issues": "https://github.com/laravel/ui/issues", + "source": "https://github.com/laravel/ui/tree/v2.5.0" + }, + "time": "2020-11-03T19:45:19+00:00" + }, { "name": "league/commonmark", "version": "1.6.6", diff --git a/config/sanctum.php b/config/sanctum.php new file mode 100644 index 0000000..9281c92 --- /dev/null +++ b/config/sanctum.php @@ -0,0 +1,65 @@ + explode(',', env('SANCTUM_STATEFUL_DOMAINS', sprintf( + '%s%s', + 'localhost,localhost:3000,127.0.0.1,127.0.0.1:8000,::1', + env('APP_URL') ? ','.parse_url(env('APP_URL'), PHP_URL_HOST) : '' + ))), + + /* + |-------------------------------------------------------------------------- + | Sanctum Guards + |-------------------------------------------------------------------------- + | + | This array contains the authentication guards that will be checked when + | Sanctum is trying to authenticate a request. If none of these guards + | are able to authenticate the request, Sanctum will use the bearer + | token that's present on an incoming request for authentication. + | + */ + + 'guard' => ['web'], + + /* + |-------------------------------------------------------------------------- + | Expiration Minutes + |-------------------------------------------------------------------------- + | + | This value controls the number of minutes until an issued token will be + | considered expired. If this value is null, personal access tokens do + | not expire. This won't tweak the lifetime of first-party sessions. + | + */ + + 'expiration' => null, + + /* + |-------------------------------------------------------------------------- + | Sanctum Middleware + |-------------------------------------------------------------------------- + | + | When authenticating your first-party SPA with Sanctum you may need to + | customize some of the middleware Sanctum uses while processing the + | request. You may change the middleware listed below as required. + | + */ + + 'middleware' => [ + 'verify_csrf_token' => App\Http\Middleware\VerifyCsrfToken::class, + 'encrypt_cookies' => App\Http\Middleware\EncryptCookies::class, + ], + +]; diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index c8ca86e..a4de1a4 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -15,12 +15,11 @@ class CreateUsersTable extends Migration { Schema::create('users', function (Blueprint $table) { $table->id(); - $table->string('name'); - $table->string('email')->unique(); + $table->string('name')->unique(); + $table->string('email')->unique()->nullable(); $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); - $table->string('api_token',60); $table->timestamps(); }); } diff --git a/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php new file mode 100644 index 0000000..3ce0002 --- /dev/null +++ b/database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php @@ -0,0 +1,36 @@ +bigIncrements('id'); + $table->morphs('tokenable'); + $table->string('name'); + $table->string('token', 64)->unique(); + $table->text('abilities')->nullable(); + $table->timestamp('last_used_at')->nullable(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('personal_access_tokens'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index a9f8f0e..e4f9f84 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -12,7 +12,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - $this->call(UserSeeder::class); $this->call(GrupoDeCompraSeeder::class); $this->call(ProductoSeeder::class); } diff --git a/database/seeds/GrupoDeCompraSeeder.php b/database/seeds/GrupoDeCompraSeeder.php index eaf1052..2c16d48 100644 --- a/database/seeds/GrupoDeCompraSeeder.php +++ b/database/seeds/GrupoDeCompraSeeder.php @@ -17,21 +17,32 @@ class GrupoDeCompraSeeder extends Seeder $csv->setEnclosure("'"); $csv->setHeaderOffset(0); $registros = $csv->getRecords(); - $toInsert = []; + $gdcToInsert = []; + $usersToInsert = []; foreach($registros as $registro){ - $toInsert[] = [ + $gdcToInsert[] = [ 'nombre' => $registro['barrio'], 'region' => $registro['region'], 'telefono' => $registro['telefono'], 'correo' => $registro['correo'], 'referente_finanzas' => $registro['referente'] ]; + + $usersToInsert[] = [ + 'name' => $registro['barrio'], + 'password' => Hash::make($registro['barrio']) + ]; } - foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) + foreach (array_chunk($gdcToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) { DB::table('grupos_de_compra')->insert($chunk); } + + foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) + { + DB::table('users')->insert($chunk); + } } } diff --git a/database/seeds/UserSeeder.php b/database/seeds/UserSeeder.php deleted file mode 100644 index 561280d..0000000 --- a/database/seeds/UserSeeder.php +++ /dev/null @@ -1,27 +0,0 @@ -insert([ - 'name' => $web_client_name, - 'email' => env('WEB_CLIENT_EMAIL', 'informaticamps@buzon.uy'), - 'password' => Hash::make(env('WEB_CLIENT_PASS', 'pass')), - 'api_token' => $api_token - ]); - dump('Api token for ' . $web_client_name . ' is: ' . $api_token); - - $api_token = Str::random(60); - } -} diff --git a/package.json b/package.json index 557bd21..4cc881e 100644 --- a/package.json +++ b/package.json @@ -11,11 +11,16 @@ }, "devDependencies": { "axios": "^0.19", + "bootstrap": "^4.0.0", "cross-env": "^7.0", + "jquery": "^3.2", "laravel-mix": "^5.0.1", "lodash": "^4.17.19", - "resolve-url-loader": "^3.1.0", - "sass": "^1.15.2", - "sass-loader": "^8.0.0" + "popper.js": "^1.12", + "resolve-url-loader": "^2.3.1", + "sass": "^1.20.1", + "sass-loader": "^8.0.0", + "vue": "^2.5.17", + "vue-template-compiler": "^2.6.10" } } diff --git a/public/js/login.js b/public/js/login.js new file mode 100644 index 0000000..783b064 --- /dev/null +++ b/public/js/login.js @@ -0,0 +1,114 @@ +window.Event = new Vue(); + +Vue.component('region-select', { + template: ` +
+ +
+Si no la sabés, consultá a tus compañerxs.
+Bienvenidx a la aplicación de compras del Mercado Popular de Subsistencia
+ @error('name') +