├── public ├── favicon.ico ├── robots.txt ├── img │ ├── buka.jpg │ ├── barbrady.gif │ ├── kitchen.jpg │ ├── dancers │ │ ├── boy.gif │ │ ├── jump.gif │ │ ├── kenny.gif │ │ ├── mrbean.gif │ │ ├── beyonce.gif │ │ ├── gangnam.gif │ │ └── cartoon-twerk.gif │ ├── ijebu-garri.jpg │ └── default-food.jpg ├── .htaccess ├── web.config └── index.php ├── app ├── Listeners │ ├── .gitkeep │ ├── UpdateFreeLunchQuota.php │ ├── SaveAdminUser.php │ └── OrderPaymentProcessor.php ├── Policies │ └── .gitkeep ├── Events │ ├── Event.php │ ├── FreelunchQuotaUpdated.php │ ├── UserWasCreated.php │ ├── UserWasUpdated.php │ └── LunchWasOrdered.php ├── Http │ ├── Requests │ │ ├── Request.php │ │ ├── WalletBalanceRequest.php │ │ ├── FreelunchUpdateRequest.php │ │ ├── SlackCommandRequest.php │ │ ├── AdminUserUpdateRequest.php │ │ └── OrderRequest.php │ ├── Controllers │ │ ├── SlackCommands │ │ │ ├── Controller.php │ │ │ ├── FreeLunchController.php │ │ │ └── WalletController.php │ │ ├── GuestController.php │ │ ├── Controller.php │ │ ├── Auth │ │ │ ├── PasswordController.php │ │ │ └── AuthController.php │ │ ├── Admin │ │ │ ├── AdminController.php │ │ │ ├── AuthController.php │ │ │ ├── FreelunchController.php │ │ │ └── UserController.php │ │ └── HomeController.php │ ├── Middleware │ │ ├── EncryptCookies.php │ │ ├── VerifyAdminSession.php │ │ ├── VerifyValidOrderTime.php │ │ ├── VerifyAdminUser.php │ │ ├── RedirectIfAuthenticated.php │ │ ├── VerifyLunchboxID.php │ │ ├── SlackCommandUserExists.php │ │ ├── WalletSlackSubCommandExists.php │ │ ├── Authenticate.php │ │ ├── VerifyCsrfToken.php │ │ └── FreeLunchCommandVerifier.php │ ├── Kernel.php │ └── routes.php ├── Providers │ ├── BroadcastServiceProvider.php │ ├── SocialiteServiceProvider.php │ ├── CustomValidationServiceProvider.php │ ├── EventServiceProvider.php │ ├── RouteServiceProvider.php │ ├── AppServiceProvider.php │ └── AuthServiceProvider.php ├── Socialite │ ├── Socialite.php │ └── SlackProvider.php ├── Jobs │ └── Job.php ├── Lunch.php ├── Console │ ├── Commands │ │ └── Inspire.php │ └── Kernel.php ├── Traits │ └── SlackResponse.php ├── Buka.php ├── Exceptions │ └── Handler.php ├── Order.php ├── Lunch │ ├── Timekeeper.php │ └── OrderSummariser.php ├── Option.php └── Lunchbox.php ├── database ├── seeds │ ├── .gitkeep │ ├── BukasTableSeeder.php │ ├── DatabaseSeeder.php │ ├── FreelunchTableSeeder.php │ ├── LunchboxesTableSeeder.php │ ├── OrdersTableSeeder.php │ ├── UsersTableSeeder.php │ ├── OptionsTableSeeder.php │ └── LunchTableSeeder.php ├── .gitignore ├── migrations │ ├── .gitkeep │ ├── 2016_08_28_225114_create_options_table.php │ ├── 2016_06_24_000000_create_bukas_table.php │ ├── 2016_06_24_000000_create_lunches_table.php │ ├── 2016_06_24_000001_create_lunchboxes_table.php │ ├── 2016_06_24_044746_create_freelunches_table.php │ ├── 2016_06_24_042009_create_orders_table.php │ └── 2014_10_12_000000_create_users_table.php └── factories │ └── ModelFactory.php ├── resources ├── views │ ├── vendor │ │ └── .gitkeep │ ├── auth │ │ ├── emails │ │ │ └── password.blade.php │ │ ├── passwords │ │ │ ├── email.blade.php │ │ │ └── reset.blade.php │ │ ├── login.blade.php │ │ └── register.blade.php │ ├── welcome.blade.php │ ├── admin │ │ ├── overview.blade.php │ │ ├── login.blade.php │ │ └── freelunch-overview.blade.php │ ├── errors │ │ └── 503.blade.php │ ├── layouts │ │ ├── admin.blade.php │ │ └── app.blade.php │ └── order │ │ ├── completed.blade.php │ │ └── history.blade.php ├── lang │ └── en │ │ ├── app.php │ │ ├── pagination.php │ │ ├── auth.php │ │ ├── passwords.php │ │ └── validation.php └── assets │ └── sass │ └── app.scss ├── contributing.md ├── bootstrap ├── cache │ └── .gitignore ├── autoload.php ├── app.php └── helpers.php ├── storage ├── debugbar │ └── .gitignore ├── logs │ └── .gitignore ├── app │ ├── public │ │ └── .gitignore │ └── .gitignore └── framework │ ├── cache │ └── .gitignore │ ├── views │ └── .gitignore │ ├── sessions │ └── .gitignore │ └── .gitignore ├── Procfile ├── .gitattributes ├── config ├── food.php ├── compile.php ├── view.php ├── services.php ├── trustedproxy.php ├── broadcasting.php ├── filesystems.php ├── cache.php ├── queue.php ├── auth.php ├── mail.php ├── database.php └── session.php ├── .gitignore ├── phpspec.yml ├── package.json ├── .user.ini ├── spec ├── Http │ └── Controllers │ │ └── SlackCommands │ │ └── WalletControllerSpec.php └── Lunch │ ├── TimekeeperSpec.php │ └── OrderSummariserSpec.php ├── tests ├── ExampleTest.php └── TestCase.php ├── gulpfile.js ├── server.php ├── todo.md ├── .env.example ├── license.md ├── phpunit.xml ├── .travis.yml ├── readme.md ├── composer.json └── artisan /public/favicon.ico: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/Listeners/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /app/Policies/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /database/seeds/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /database/.gitignore: -------------------------------------------------------------------------------- 1 | *.sqlite 2 | -------------------------------------------------------------------------------- /database/migrations/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /resources/views/vendor/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /contributing.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines -------------------------------------------------------------------------------- /bootstrap/cache/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /storage/debugbar/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore -------------------------------------------------------------------------------- /storage/logs/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | User-agent: * 2 | Disallow: 3 | -------------------------------------------------------------------------------- /storage/app/public/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: vendor/bin/heroku-php-apache2 public/ 2 | -------------------------------------------------------------------------------- /resources/lang/en/app.php: -------------------------------------------------------------------------------- 1 | env('FREE_LUNCH_COST', 250), 6 | 7 | ]; -------------------------------------------------------------------------------- /public/img/dancers/jump.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoighodaro/hngfood/HEAD/public/img/dancers/jump.gif -------------------------------------------------------------------------------- /public/img/dancers/kenny.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoighodaro/hngfood/HEAD/public/img/dancers/kenny.gif -------------------------------------------------------------------------------- /public/img/dancers/mrbean.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoighodaro/hngfood/HEAD/public/img/dancers/mrbean.gif -------------------------------------------------------------------------------- /public/img/default-food.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/neoighodaro/hngfood/HEAD/public/img/default-food.jpg -------------------------------------------------------------------------------- /resources/assets/sass/app.scss: -------------------------------------------------------------------------------- 1 | // @import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap"; 2 | 3 | -------------------------------------------------------------------------------- /app/Events/Event.php: -------------------------------------------------------------------------------- 1 | getEmailForPasswordReset()) }}"> {{ $link }} 2 | -------------------------------------------------------------------------------- /app/Http/Requests/Request.php: -------------------------------------------------------------------------------- 1 | get('text'); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "scripts": { 4 | "prod": "gulp --production", 5 | "dev": "gulp watch" 6 | }, 7 | "devDependencies": { 8 | "gulp": "^3.9.1", 9 | "laravel-elixir": "^5.0.0", 10 | "bootstrap-sass": "^3.3.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /.user.ini: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------------------------- 2 | # Custom PHP Configuration for Heroku 3 | # @see: https://devcenter.heroku.com/articles/custom-php-settings#php-runtime-settings 4 | # @see: http://docs.php.net/en/configuration.file.per-user.php 5 | # ------------------------------------------------------------------------------------------- 6 | -------------------------------------------------------------------------------- /app/Http/Middleware/EncryptCookies.php: -------------------------------------------------------------------------------- 1 | app->singleton('Laravel\Socialite\Contracts\Factory', function ($app) { 11 | return new Socialite($app); 12 | }); 13 | } 14 | } -------------------------------------------------------------------------------- /spec/Http/Controllers/SlackCommands/WalletControllerSpec.php: -------------------------------------------------------------------------------- 1 | shouldHaveType('HNG\Http\Controllers\SlackCommands\WalletController'); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /database/seeds/BukasTableSeeder.php: -------------------------------------------------------------------------------- 1 | 'Whitehouse'], 17 | ['name' => 'Commint'], 18 | ]; 19 | 20 | foreach ($bukas as $buka) Buka::create($buka); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/ExampleTest.php: -------------------------------------------------------------------------------- 1 | visit('/')->see('Sign in with slack'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /app/Socialite/Socialite.php: -------------------------------------------------------------------------------- 1 | buildProvider(SlackProvider::class, $config); 17 | } 18 | } -------------------------------------------------------------------------------- /app/Http/Controllers/GuestController.php: -------------------------------------------------------------------------------- 1 | middleware('guest'); 13 | } 14 | 15 | /** 16 | * Display the welcome page. 17 | * 18 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View 19 | */ 20 | public function index() 21 | { 22 | return view('welcome'); 23 | } 24 | } -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var elixir = require('laravel-elixir'); 2 | 3 | /* 4 | |-------------------------------------------------------------------------- 5 | | Elixir Asset Management 6 | |-------------------------------------------------------------------------- 7 | | 8 | | Elixir provides a clean, fluent API for defining some basic Gulp tasks 9 | | for your Laravel application. By default, we are compiling the Sass 10 | | file for our application, as well as publishing vendor resources. 11 | | 12 | */ 13 | 14 | elixir(function(mix) { 15 | mix.sass('app.scss'); 16 | }); 17 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyAdminSession.php: -------------------------------------------------------------------------------- 1 | oldQuota = $oldQuota; 26 | $this->newQuota = $newQuota; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Listeners/UpdateFreeLunchQuota.php: -------------------------------------------------------------------------------- 1 | newQuota); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyValidOrderTime.php: -------------------------------------------------------------------------------- 1 | isWithinLunchOrderHours()) { 19 | abort(403); 20 | } 21 | 22 | return $next($request); 23 | } 24 | } -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyAdminUser.php: -------------------------------------------------------------------------------- 1 | user(); 19 | 20 | if ( ! $user OR ! $user->hasRole('admin')) { 21 | return redirect(route('home')); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Jobs/Job.php: -------------------------------------------------------------------------------- 1 | '« Previous', 17 | 'next' => 'Next »', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /database/seeds/DatabaseSeeder.php: -------------------------------------------------------------------------------- 1 | call(UsersTableSeeder::class); 15 | $this->call(BukasTableSeeder::class); 16 | $this->call(LunchboxesTableSeeder::class); 17 | $this->call(LunchTableSeeder::class); 18 | $this->call(OrdersTableSeeder::class); 19 | $this->call(FreelunchTableSeeder::class); 20 | $this->call(OptionsTableSeeder::class); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /public/.htaccess: -------------------------------------------------------------------------------- 1 | 2 | 3 | Options -MultiViews 4 | 5 | 6 | RewriteEngine On 7 | 8 | # Redirect Trailing Slashes If Not A Folder... 9 | RewriteCond %{REQUEST_FILENAME} !-d 10 | RewriteRule ^(.*)/$ /$1 [L,R=301] 11 | 12 | # Handle Front Controller... 13 | RewriteCond %{REQUEST_FILENAME} !-d 14 | RewriteCond %{REQUEST_FILENAME} !-f 15 | RewriteRule ^ index.php [L] 16 | 17 | # Handle Authorization Header 18 | RewriteCond %{HTTP:Authorization} . 19 | RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 20 | 21 | -------------------------------------------------------------------------------- /server.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | $uri = urldecode( 11 | parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) 12 | ); 13 | 14 | // This file allows us to emulate Apache's "mod_rewrite" functionality from the 15 | // built-in PHP web server. This provides a convenient way to test a Laravel 16 | // application without having installed a "real" web server software here. 17 | if ($uri !== '/' && file_exists(__DIR__.'/public'.$uri)) { 18 | return false; 19 | } 20 | 21 | require_once __DIR__.'/public/index.php'; 22 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | make(Illuminate\Contracts\Console\Kernel::class)->bootstrap(); 22 | 23 | return $app; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /app/Http/Controllers/Controller.php: -------------------------------------------------------------------------------- 1 | check()) { 21 | return redirect(route('home')); 22 | } 23 | 24 | return $next($request); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/Lunch.php: -------------------------------------------------------------------------------- 1 | 'float']; 21 | 22 | /** 23 | * Buka that lunch belongs to. 24 | * 25 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 26 | */ 27 | public function buka() 28 | { 29 | return $this->belongsTo(Buka::class, 'buka_id'); 30 | } 31 | } -------------------------------------------------------------------------------- /resources/lang/en/auth.php: -------------------------------------------------------------------------------- 1 | 'These credentials do not match our records.', 17 | 'throttle' => 'Too many login attempts. Please try again in :seconds seconds.', 18 | 19 | ]; 20 | -------------------------------------------------------------------------------- /app/Events/UserWasCreated.php: -------------------------------------------------------------------------------- 1 | user = $user; 25 | } 26 | 27 | /** 28 | * Get the channels the event should be broadcast on. 29 | * 30 | * @return array 31 | */ 32 | public function broadcastOn() 33 | { 34 | return []; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyLunchboxID.php: -------------------------------------------------------------------------------- 1 | findOrFail($request->route('id')); 22 | } catch (ModelNotFoundException $e) { 23 | abort(404); 24 | } 25 | 26 | return $next($request); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Http/Middleware/SlackCommandUserExists.php: -------------------------------------------------------------------------------- 1 | get('user_id'))->first()) { 23 | return $this->slackResponse('Sorry! You are not a registered user.'); 24 | } 25 | 26 | return $next($request); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Events/UserWasUpdated.php: -------------------------------------------------------------------------------- 1 | oldUser = $details['oldUser']; 30 | $this->updatedUser = $details['updatedUser']; 31 | $this->updateRequest = $details['updateRequest']; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /database/factories/ModelFactory.php: -------------------------------------------------------------------------------- 1 | define(HNG\User::class, function (Faker\Generator $faker) { 15 | return [ 16 | 'name' => $faker->name, 17 | 'email' => $faker->safeEmail, 18 | 'password' => bcrypt(str_random(10)), 19 | 'remember_token' => str_random(10), 20 | ]; 21 | }); 22 | -------------------------------------------------------------------------------- /app/Console/Commands/Inspire.php: -------------------------------------------------------------------------------- 1 | comment(PHP_EOL.Inspiring::quote().PHP_EOL); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /app/Providers/CustomValidationServiceProvider.php: -------------------------------------------------------------------------------- 1 | command('inspire') 28 | // ->hourly(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /database/migrations/2016_08_28_225114_create_options_table.php: -------------------------------------------------------------------------------- 1 | increments('id'); 17 | $table->string('option')->unique(); 18 | $table->string('value'); 19 | }); 20 | } 21 | 22 | /** 23 | * Reverse the migrations. 24 | * 25 | * @return void 26 | */ 27 | public function down() 28 | { 29 | Schema::drop('options'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Http/Requests/FreelunchUpdateRequest.php: -------------------------------------------------------------------------------- 1 | ajax() && Gate::allows('free_lunch.manage'); 18 | } 19 | 20 | /** 21 | * Get the validation rules that apply to the request. 22 | * 23 | * @return array 24 | */ 25 | public function rules() 26 | { 27 | return [ 28 | 'freelunch' => 'required|numeric|between:0,500' 29 | ]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/Http/Middleware/WalletSlackSubCommandExists.php: -------------------------------------------------------------------------------- 1 | get('text'))) { 23 | return $this->slackResponse("Invalid command! */wallet help* to get valid list of responses!"); 24 | } 25 | 26 | return $next($request); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/Traits/SlackResponse.php: -------------------------------------------------------------------------------- 1 | json($text); 18 | } 19 | 20 | return response()->json([ 21 | 'text' => $text, 22 | 'attachments' => $attachments, 23 | 'response_type' => $private ? 'ephemeral' : 'in_channel', 24 | ]); 25 | } 26 | 27 | } 28 | 29 | -------------------------------------------------------------------------------- /app/Http/Middleware/Authenticate.php: -------------------------------------------------------------------------------- 1 | guest()) { 21 | if ($request->ajax() || $request->wantsJson()) { 22 | return response('Unauthorized.', 401); 23 | } else { 24 | return redirect()->guest('login'); 25 | } 26 | } 27 | 28 | return $next($request); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /todo.md: -------------------------------------------------------------------------------- 1 | # TODO 2 | 3 | Things to be done 4 | 5 | - [ ] Handle wrong slack team error in a better way... 6 | - [ ] Specified role can manage bukas 7 | - [ ] Specified role can manage bukas lunch 8 | - [ ] Specified role can view single & collective user orders for day(s) ranges 9 | - [ ] Specified role can print orders for the day 10 | - [ ] Fix bug where "cancel" during slack login loops. 11 | - [ ] [User list] filter by role 12 | - [ ] User can Cancel orders 13 | - [ ] How to place slack orders help page 14 | - [ ] Redirecting to get the user details should not happen immediately after logging in 15 | - [ ] /food order last -> Reorder your last meal 16 | - [ ] /food order saved rice -> Order one of your saved dishes 17 | - [ ] 100% Code coverage + Maximum code quality. 18 | - [ ] Complete the documentation. 19 | - [ ] Add localization. 20 | - [ ] Add installer. 21 | -------------------------------------------------------------------------------- /app/Listeners/SaveAdminUser.php: -------------------------------------------------------------------------------- 1 | user->id === 1) { 25 | $event->user->role = $event->user->getRoleIdFromName(User::SUPERADMIN); 26 | $event->user->save(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /resources/lang/en/passwords.php: -------------------------------------------------------------------------------- 1 | 'Passwords must be at least six characters and match the confirmation.', 17 | 'reset' => 'Your password has been reset!', 18 | 'sent' => 'We have e-mailed your password reset link!', 19 | 'token' => 'This password reset token is invalid.', 20 | 'user' => "We can't find a user with that e-mail address.", 21 | 22 | ]; 23 | -------------------------------------------------------------------------------- /resources/views/welcome.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Lunch Breaks Rock!') 4 | 5 | @section('content') 6 |
7 |
8 |
9 |
10 |
11 |

Lunch Order Management For Teams!

12 |
13 | 14 | Sign in with Slack 15 | 16 |
17 |
18 |
19 |
20 |
21 | @endsection 22 | -------------------------------------------------------------------------------- /app/Http/Requests/SlackCommandRequest.php: -------------------------------------------------------------------------------- 1 | get('token'), (array) option('SLACK_COMMAND_TOKENS')); 17 | } 18 | 19 | /** 20 | * Get the validation rules that apply to the request. 21 | * 22 | * @return array 23 | */ 24 | public function rules() 25 | { 26 | return [ 27 | 'team_id' => 'required', 28 | 'user_id' => 'required', 29 | 'token' => 'required', 30 | 'command' => 'required', 31 | 'text' => 'required', 32 | ]; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | APP_ENV=local 2 | APP_KEY=SomeRandomString 3 | APP_DEBUG=true 4 | APP_LOG_LEVEL=debug 5 | APP_URL=http://localhost 6 | APP_LOG=single 7 | 8 | DB_CONNECTION=mysql 9 | DB_HOST=127.0.0.1 10 | DB_PORT=3306 11 | DB_DATABASE=homestead 12 | DB_USERNAME=homestead 13 | DB_PASSWORD=secret 14 | 15 | SLACK_TEAM_DOMAIN= 16 | SLACK_CLIENT_ID= 17 | SLACK_CLIENT_SECRET= 18 | SLACK_REDIRECT_CALLBACK_URL= 19 | SLACK_DEFAULT_PERMISSIONS="identity.basic,identity.team,identity.email,identity.avatar" 20 | SLACK_COMMAND_TOKEN=token1,token2 21 | 22 | USER_SLACK_ID= 23 | USER_SLACK_EMAIL= 24 | USER_SLACK_NAME= 25 | USER_SLACK_AVATAR= 26 | 27 | CACHE_DRIVER=file 28 | SESSION_DRIVER=file 29 | QUEUE_DRIVER=sync 30 | 31 | REDIS_HOST=127.0.0.1 32 | REDIS_PASSWORD=null 33 | REDIS_PORT=6379 34 | 35 | MAIL_DRIVER=smtp 36 | MAIL_HOST=mailtrap.io 37 | MAIL_PORT=2525 38 | MAIL_USERNAME=null 39 | MAIL_PASSWORD=null 40 | MAIL_ENCRYPTION=null 41 | -------------------------------------------------------------------------------- /app/Events/LunchWasOrdered.php: -------------------------------------------------------------------------------- 1 | order = $order; 31 | 32 | $this->request = $request; 33 | } 34 | 35 | /** 36 | * Get the channels the event should be broadcast on. 37 | * 38 | * @return array 39 | */ 40 | public function broadcastOn() 41 | { 42 | return []; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/migrations/2016_06_24_000000_create_bukas_table.php: -------------------------------------------------------------------------------- 1 | engine = 'InnoDB'; 17 | $table->increments('id'); 18 | $table->string('name'); 19 | $table->string('avatar')->default(asset('/img/buka.jpg')); 20 | $table->float('base_cost')->default(0.00); 21 | $table->timestamps(); 22 | }); 23 | } 24 | 25 | /** 26 | * Reverse the migrations. 27 | * 28 | * @return void 29 | */ 30 | public function down() 31 | { 32 | Schema::drop('bukas'); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /app/Providers/EventServiceProvider.php: -------------------------------------------------------------------------------- 1 | [], 18 | Events\FreelunchQuotaUpdated::class => [Listeners\UpdateFreeLunchQuota::class], 19 | Events\UserWasCreated::class => [Listeners\SaveAdminUser::class], 20 | Events\LunchWasOrdered::class => [Listeners\OrderPaymentProcessor::class], 21 | ]; 22 | 23 | /** 24 | * Register any other events for your application. 25 | * 26 | * @return void 27 | */ 28 | public function boot() 29 | { 30 | parent::boot(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/Buka.php: -------------------------------------------------------------------------------- 1 | 'float']; 16 | 17 | /** 18 | * @var array 19 | */ 20 | protected $with = ['lunches']; 21 | 22 | /** 23 | * Get lunches assigned to the buka. 24 | * 25 | * @return \Illuminate\Database\Eloquent\Relations\HasMany 26 | */ 27 | public function lunches() 28 | { 29 | return $this->hasMany(Lunch::class, 'buka_id'); 30 | } 31 | 32 | /** 33 | * Get lunchboxes. 34 | * 35 | * @return \Illuminate\Database\Eloquent\Relations\HasMany 36 | */ 37 | public function lunchboxes() 38 | { 39 | return $this->hasMany(Lunchbox::class, 'buka_id'); 40 | } 41 | } -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/PasswordController.php: -------------------------------------------------------------------------------- 1 | middleware($this->guestMiddleware()); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /public/web.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /app/Http/Requests/AdminUserUpdateRequest.php: -------------------------------------------------------------------------------- 1 | ajax() && Gate::allows('users.manage'); 19 | } 20 | 21 | /** 22 | * Get the validation rules that apply to the request. 23 | * 24 | * @return array 25 | */ 26 | public function rules() 27 | { 28 | return [ 29 | 'user_id' => 'required|exists:users,id', 30 | 'role' => 'permission:roles.manage|roleExists', 31 | 'wallet' => 'min:0|max:20000|permission:wallet.manage', 32 | 'freelunch' => 'between:0,20|permission:free_lunch.manage', 33 | ]; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/Listeners/OrderPaymentProcessor.php: -------------------------------------------------------------------------------- 1 | user = auth()->user(); 22 | 23 | $this->freelunch = new Freelunch; 24 | } 25 | 26 | /** 27 | * Handle the event. 28 | * 29 | * @param LunchWasOrdered $event 30 | */ 31 | public function handle(LunchWasOrdered $event) 32 | { 33 | $orderCost = $event->order->totalCost(); 34 | $availableCash = number_unformat($this->user->wallet); 35 | 36 | if ($event->request->wantsToRedeemFreelunch()) { 37 | $orderCost = $this->freelunch->deductRequiredToSettle($orderCost); 38 | } 39 | 40 | $this->user->wallet = $availableCash - $orderCost; 41 | $this->user->save(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /resources/views/admin/overview.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.admin') 2 | 3 | @section('admin-content') 4 |
5 |

Food Orders Overview

6 |
7 |
8 |

Today

9 | {{ $ordersOverview['today']->count() }} 10 |
11 |
12 |

This Month

13 | {{ $ordersOverview['month']->count() }} 14 |
15 |
16 |

This Year

17 | {{ $ordersOverview['year']->count() }} 18 |
19 |
20 |

This Century

21 | {{ $ordersOverview['century']->count() }} 22 |
23 |
24 |
25 | @endsection -------------------------------------------------------------------------------- /resources/views/admin/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Admin Login') 4 | 5 | @section('content') 6 |
7 |
8 |
9 |
10 |

Enter your account password and ye' may enter.

11 |
12 |
13 |
14 | {!! csrf_field() !!} 15 |
16 | 17 |
18 | 19 |
20 |
21 |
22 |
23 |
24 |
25 | @endsection -------------------------------------------------------------------------------- /database/migrations/2016_06_24_000000_create_lunches_table.php: -------------------------------------------------------------------------------- 1 | engine = 'InnoDB'; 17 | $table->increments('id'); 18 | $table->string('name'); 19 | $table->string('photo')->default('/img/default-food.jpg'); 20 | $table->float('cost'); 21 | $table->unsignedInteger('buka_id'); 22 | $table->timestamps(); 23 | 24 | $table->foreign('buka_id') 25 | ->references('id')->on('bukas') 26 | ->onDelete('cascade'); 27 | }); 28 | } 29 | 30 | /** 31 | * Reverse the migrations. 32 | * 33 | * @return void 34 | */ 35 | public function down() 36 | { 37 | Schema::drop('lunches'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /config/compile.php: -------------------------------------------------------------------------------- 1 | [ 17 | // 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled File Providers 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may list service providers which define a "compiles" function 26 | | that returns additional files that should be compiled, providing an 27 | | easy way to get common files from any packages you are utilizing. 28 | | 29 | */ 30 | 31 | 'providers' => [ 32 | // 33 | ], 34 | 35 | ]; 36 | -------------------------------------------------------------------------------- /app/Http/Middleware/VerifyCsrfToken.php: -------------------------------------------------------------------------------- 1 | except) . '#'; 30 | 31 | if ($this->isReading($request) OR $this->tokensMatch($request) OR preg_match($regex, $request->path())) 32 | { 33 | return $this->addCookieToResponse($request, $next($request)); 34 | } 35 | 36 | throw new TokenMismatchException; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/view.php: -------------------------------------------------------------------------------- 1 | [ 17 | realpath(base_path('resources/views')), 18 | ], 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Compiled View Path 23 | |-------------------------------------------------------------------------- 24 | | 25 | | This option determines where all the compiled Blade templates will be 26 | | stored for your application. Typically, this is within the storage 27 | | directory. However, as usual, you are free to change this value. 28 | | 29 | */ 30 | 31 | 'compiled' => realpath(storage_path('framework/views')), 32 | 33 | ]; 34 | -------------------------------------------------------------------------------- /database/seeds/FreelunchTableSeeder.php: -------------------------------------------------------------------------------- 1 | 'Because I can.', 'from_id' => 2, 'to_id' => 1, 'expires_at' => Carbon::tomorrow()], 18 | ['reason' => 'Because I can.', 'from_id' => 3, 'to_id' => 1, 'expires_at' => Carbon::tomorrow()], 19 | ['reason' => 'Because I can.', 'from_id' => 2, 'to_id' => 1, 'expires_at' => Carbon::tomorrow()], 20 | ['reason' => 'Because I can.', 'from_id' => 3, 'to_id' => 1, 'expires_at' => Carbon::tomorrow()], 21 | ['reason' => 'Because I can.', 'from_id' => 2, 'to_id' => 1, 'expires_at' => Carbon::tomorrow()], 22 | ['reason' => 'Because I can.', 'from_id' => 3, 'to_id' => 1, 'expires_at' => Carbon::tomorrow()], 23 | ]; 24 | 25 | foreach ($freelunches as $freelunch) { 26 | Freelunch::create($freelunch); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /license.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Neo Ighodaro 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. -------------------------------------------------------------------------------- /database/seeds/LunchboxesTableSeeder.php: -------------------------------------------------------------------------------- 1 | 1, 18 | 'buka_id' => 1, 19 | 'created_at' => Carbon\Carbon::create(2016, 06, 1), 20 | 'updated_at' => Carbon\Carbon::create(2016, 06, 1), 21 | ], 22 | [ 23 | 'user_id' => 1, 24 | 'buka_id' => 1, 25 | 'free_lunch' => true, 26 | 'created_at' => Carbon\Carbon::create(2016, 05, 1), 27 | 'updated_at' => Carbon\Carbon::create(2016, 05, 1), 28 | ], 29 | [ 30 | 'user_id' => 1, 31 | 'buka_id' => 1, 32 | 'created_at' => Carbon\Carbon::create(2016, 05, 2), 33 | 'updated_at' => Carbon\Carbon::create(2016, 05, 2), 34 | ], 35 | ]; 36 | 37 | foreach ($boxes as $box) Lunchbox::create($box); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 13 | ./tests 14 | 15 | 16 | 17 | 18 | ./app 19 | 20 | ./app/Http/routes.php 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /bootstrap/autoload.php: -------------------------------------------------------------------------------- 1 | [ 18 | 'domain' => env('MAILGUN_DOMAIN'), 19 | 'secret' => env('MAILGUN_SECRET'), 20 | ], 21 | 22 | 'mandrill' => [ 23 | 'secret' => env('MANDRILL_SECRET'), 24 | ], 25 | 26 | 'ses' => [ 27 | 'key' => env('SES_KEY'), 28 | 'secret' => env('SES_SECRET'), 29 | 'region' => 'us-east-1', 30 | ], 31 | 32 | 'sparkpost' => [ 33 | 'secret' => env('SPARKPOST_SECRET'), 34 | ], 35 | 36 | 'stripe' => [ 37 | 'model' => HNG\User::class, 38 | 'key' => env('STRIPE_KEY'), 39 | 'secret' => env('STRIPE_SECRET'), 40 | ], 41 | ]; 42 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - 5.6 4 | - 7.0 5 | before_script: 6 | - curl -s http://getcomposer.org/installer | php 7 | - php composer.phar install --dev 8 | script: 9 | - vendor/bin/phpunit 10 | - vendor/bin/phpspec run 11 | cache: 12 | directories: 13 | - $HOME/.composer/cache 14 | notifications: 15 | email: 16 | recipients: 17 | - neo@hng.tech 18 | - lynda@hotels.ng 19 | on_success: change 20 | on_failure: always 21 | deploy: 22 | app: hngfood 23 | provider: heroku 24 | api_key: 25 | secure: nvQqeycsJWQ7D6+85kPY1h37OqNvYgcFEsX49Zwo7Kkj5NstDONWehzSa6NmQ9vxLAiafpQ82DWhUAhrfJPS6uBZLpoD+D/jKh+lOoeG8DjPu7b8Hg1jZNaOgIoBZj9y4/bcFojhES/kN6dgfD3jsG/Sta5NEOQYOa2eBlGzQZxOnb2hkO62ykbDoHMk6DK7Wqzw588JFvijyNiFX+NXyogcb96WpCXUEC8j+YDJEdxobL+OwlvxqFxLgfVfKAeMmDbvLPjM7TmZYE1aDcXTs+/JN6aNC6thmbP1So9wA5hZGG5LyGWHSf/lL/cUIjeYfqYZITbjmSB5vUBK4AZsh85uwMC1kq6SwD559SGWhiYkC0lTjsV01Dni1YnVa43bg5VhIZsPeLSGh8ofb4yBSFD56wVnpw/Ik5p03A132HbiHgdWZWbwaix38DXze5jN8EnLBO+QYIhj0EMtdUZybF18eA600OaGEheFQY7G4lRXfdM9h5CM2cLCe5LjPD3/ufw6jAoAWBfucBOC41BUPbk8LdWpZModSgqEgLv+ytZEq/RuyuMF7ng7Q+a0GKJZxm7a02NjbZbjIUKMwS4y6vFTtP0SBnC0A20hTZw9JNhEXpgfx8yTF+Z++bYiEthyunFfO5NqN7uz+CarOHJWSgncIc2dcZVrjPixgoVBOoY= 26 | on: 27 | tags: true 28 | branch: master 29 | php: 5.6 30 | -------------------------------------------------------------------------------- /database/migrations/2016_06_24_000001_create_lunchboxes_table.php: -------------------------------------------------------------------------------- 1 | engine = 'InnoDB'; 17 | $table->increments('id'); 18 | $table->unsignedInteger('user_id'); 19 | $table->unsignedInteger('buka_id'); 20 | $table->boolean('free_lunch')->default(0); 21 | $table->unsignedInteger('plate_number')->default(0); 22 | $table->timestamps(); 23 | 24 | $table->foreign('user_id') 25 | ->references('id')->on('users') 26 | ->onDelete('cascade'); 27 | 28 | $table->foreign('buka_id') 29 | ->references('id')->on('bukas') 30 | ->onDelete('cascade'); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | * 37 | * @return void 38 | */ 39 | public function down() 40 | { 41 | Schema::drop('lunchboxes'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Http/Controllers/Admin/AdminController.php: -------------------------------------------------------------------------------- 1 | middleware('verifyAdmin'); 18 | //$this->middleware('verifyAdminSession'); 19 | } 20 | 21 | /** 22 | * Authenticate an admin account. 23 | * 24 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View 25 | */ 26 | public function index() 27 | { 28 | $carbon = new Carbon; 29 | 30 | $ordersOverview = [ 31 | 'today' => Lunchbox::ordersSince($carbon->startOfDay())->get(), 32 | 'month' => Lunchbox::ordersSince($carbon->startOfMonth())->get(), 33 | 'year' => Lunchbox::ordersSince($carbon->startOfYear())->get(), 34 | 'century' => Lunchbox::ordersSince($carbon->startOfCentury())->get() 35 | ]; 36 | 37 | return view('admin.overview', [ 38 | 'inPageTitle' => 'Admin Dashboard', 39 | 'ordersOverview' => $ordersOverview, 40 | ]); 41 | } 42 | } -------------------------------------------------------------------------------- /database/migrations/2016_06_24_044746_create_freelunches_table.php: -------------------------------------------------------------------------------- 1 | engine = 'InnoDB'; 17 | $table->increments('id'); 18 | $table->string('reason'); 19 | $table->unsignedInteger('from_id'); 20 | $table->unsignedInteger('to_id'); 21 | $table->boolean('redeemed')->default(false); 22 | $table->dateTime('expires_at'); 23 | $table->timestamps(); 24 | 25 | $table->foreign('from_id') 26 | ->references('id')->on('users') 27 | ->onDelete('cascade'); 28 | 29 | $table->foreign('to_id') 30 | ->references('id')->on('users') 31 | ->onDelete('cascade'); 32 | }); 33 | } 34 | 35 | /** 36 | * Reverse the migrations. 37 | * 38 | * @return void 39 | */ 40 | public function down() 41 | { 42 | Schema::drop('freelunches'); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /resources/views/errors/503.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Be right back. 5 | 6 | 7 | 8 | 39 | 40 | 41 |
42 |
43 |
Be right back.
44 |
45 |
46 | 47 | 48 | -------------------------------------------------------------------------------- /spec/Lunch/TimekeeperSpec.php: -------------------------------------------------------------------------------- 1 | beConstructedWith(Carbon::now()); 15 | $this->beAnInstanceOf(Timekeeper::class); 16 | } 17 | 18 | function it_returns_an_instance_of_carbon() 19 | { 20 | $this->carbon()->shouldBeAnInstanceOf(Carbon::class); 21 | } 22 | 23 | function it_should_return_false_for_is_weekend(Carbon $carbon) 24 | { 25 | $carbon->isWeekend()->willReturn(false); 26 | $this->beConstructedWith($carbon); 27 | $this->isWeekend()->shouldReturn(false); 28 | $carbon->isWeekend()->shouldHaveBeenCalled(); 29 | } 30 | 31 | function it_should_return_false_for_is_weekday(Carbon $carbon) 32 | { 33 | $carbon->isWeekend()->willReturn(true); 34 | $this->beConstructedWith($carbon); 35 | $this->isWeekday()->shouldReturn(false); 36 | } 37 | 38 | function it_should_return_true_if_hour_is_between_two_specified_hours() 39 | { 40 | $eightAm = Carbon::now()->setTime(8, 0, 0); 41 | $this->beConstructedWith($eightAm); 42 | $this->isHoursBetween(7, 10)->shouldReturn(true); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /database/migrations/2016_06_24_042009_create_orders_table.php: -------------------------------------------------------------------------------- 1 | engine = 'InnoDB'; 17 | $table->increments('id'); 18 | $table->unsignedInteger('lunch_id'); 19 | $table->unsignedInteger('lunchbox_id'); 20 | $table->string('name'); 21 | $table->float('cost')->default(0.00); 22 | $table->float('cost_variation')->default(0); 23 | $table->text('note')->nullable(); 24 | $table->timestamps(); 25 | 26 | $table->foreign('lunch_id') 27 | ->references('id')->on('lunches') 28 | ->onDelete('cascade'); 29 | 30 | $table->foreign('lunchbox_id') 31 | ->references('id')->on('lunchboxes') 32 | ->onDelete('cascade'); 33 | }); 34 | } 35 | 36 | /** 37 | * Reverse the migrations. 38 | * 39 | * @return void 40 | */ 41 | public function down() 42 | { 43 | Schema::drop('orders'); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /app/Http/Controllers/Admin/AuthController.php: -------------------------------------------------------------------------------- 1 | middleware('verifyAdmin'); 17 | } 18 | 19 | /** 20 | * Authenticate an admin account. 21 | * 22 | * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View 23 | */ 24 | public function authForm() 25 | { 26 | return redirect()->route('admin.dashboard'); 27 | // return view('admin.login'); 28 | } 29 | 30 | /** 31 | * Authenticate the admin account. 32 | * 33 | * @param Request $request 34 | * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector 35 | */ 36 | public function authProcess(Request $request) 37 | { 38 | $validAdmin = auth()->validate([ 39 | 'email' => auth()->user()->email, 40 | 'password' => $request->get('password'), 41 | ]); 42 | 43 | if ($validAdmin) { 44 | session(['administrator' => true]); 45 | } 46 | 47 | return $validAdmin ? redirect()->route('admin.dashboard') : back(); 48 | } 49 | } -------------------------------------------------------------------------------- /database/migrations/2014_10_12_000000_create_users_table.php: -------------------------------------------------------------------------------- 1 | engine = 'InnoDB'; 17 | $table->increments('id'); 18 | $table->string('slack_id')->unique(); 19 | $table->string('username')->nullable(); 20 | $table->string('email')->unique(); 21 | $table->string('password')->nullable(); 22 | $table->string('name'); 23 | $table->string('avatar')->nullable(); 24 | $table->float("wallet")->default(0.00); 25 | $table->string('slack_scopes') 26 | ->default("identity.basic,identity.team,identity.email,identity.avatar"); 27 | $table->unsignedInteger('role')->default(1); 28 | $table->rememberToken(); 29 | $table->softDeletes(); 30 | $table->timestamps(); 31 | }); 32 | } 33 | 34 | /** 35 | * Reverse the migrations. 36 | * 37 | * @return void 38 | */ 39 | public function down() 40 | { 41 | Schema::drop('users'); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/Http/Controllers/Admin/FreelunchController.php: -------------------------------------------------------------------------------- 1 | 'Free Lunch Overview', 21 | 'freelunchOverview' => [ 22 | 'unused' => Freelunch::activeAll()->count(), 23 | 'remaining' => (int) option('FREELUNCH_QUOTA'), 24 | ] 25 | ]); 26 | } 27 | 28 | /** 29 | * Update the free lunch quota. 30 | * 31 | * @param Requests\FreelunchUpdateRequest $request 32 | * @return array 33 | */ 34 | public function update(Requests\FreelunchUpdateRequest $request) 35 | { 36 | $newQuota = $request->get('freelunch'); 37 | $oldQuota = (int) option('FREELUNCH_QUOTA'); 38 | 39 | if ($saved = add_option('FREELUNCH_QUOTA', $newQuota)) { 40 | event(new FreelunchQuotaUpdated($oldQuota, $newQuota)); 41 | } 42 | 43 | return ['status' => ($saved ? 'success' : 'error')]; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /config/trustedproxy.php: -------------------------------------------------------------------------------- 1 | '*', 17 | 18 | /* 19 | * Or, to trust all proxies, uncomment this: 20 | */ 21 | # 'proxies' => '*', 22 | 23 | /* 24 | * Default Header Names 25 | * 26 | * Change these if the proxy does 27 | * not send the default header names. 28 | * 29 | * Note that headers such as X-Forwarded-For 30 | * are transformed to HTTP_X_FORWARDED_FOR format. 31 | * 32 | * The following are Symfony defaults, found in 33 | * \Symfony\Component\HttpFoundation\Request::$trustedHeaders 34 | */ 35 | 'headers' => [ 36 | Illuminate\Http\Request::HEADER_FORWARDED => null, // don't trust Forwarded 37 | Illuminate\Http\Request::HEADER_CLIENT_IP => 'X_FORWARDED_FOR', 38 | Illuminate\Http\Request::HEADER_CLIENT_HOST => 'X_FORWARDED_HOST', 39 | Illuminate\Http\Request::HEADER_CLIENT_PROTO => 'X_FORWARDED_PROTO', 40 | Illuminate\Http\Request::HEADER_CLIENT_PORT => 'X_FORWARDED_PORT', 41 | ] 42 | ]; -------------------------------------------------------------------------------- /app/Exceptions/Handler.php: -------------------------------------------------------------------------------- 1 | 'Beans', 'lunch_id' => 3, 'cost' => 50.00]), 18 | new Order(['name' => 'Beef', 'lunch_id' => 7, 'cost' => 0.00]), 19 | new Order(['name' => 'Beef', 'lunch_id' => 7, 'cost' => 0.00]), 20 | new Order(['name' => 'Jollof Rice', 'lunch_id' => 1, 'cost' => 100.00, 'note' => 'Jollof or Fried.']), 21 | ]; 22 | 23 | $orders2 = [ 24 | new Order(['name' => 'Plantain', 'lunch_id' => 4, 'cost' => 50.00]), 25 | new Order(['name' => 'Beef', 'lunch_id' => 7, 'cost' => 0.00]), 26 | new Order(['name' => 'Jollof Rice', 'lunch_id' => 1, 'cost' => 100.00, 'note' => 'Jollof or Fried.']), 27 | ]; 28 | 29 | $orders3 = [ 30 | new Order(['name' => 'Beef', 'lunch_id' => 7, 'cost' => 0.00]), 31 | new Order(['name' => 'Jollof Rice', 'lunch_id' => 1, 'cost' => 100.00, 'note' => 'Jollof or Fried.']), 32 | ]; 33 | 34 | Lunchbox::find(1)->orders()->saveMany($orders1); 35 | Lunchbox::find(2)->orders()->saveMany($orders2); 36 | Lunchbox::find(3)->orders()->saveMany($orders3); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/Http/Controllers/Admin/UserController.php: -------------------------------------------------------------------------------- 1 | 'User Management', 22 | 'searchQuery' => request()->get('q'), 23 | 'users' => $user->filteredList(), 24 | ]); 25 | } 26 | 27 | /** 28 | * Update the user. 29 | * 30 | * @param Requests\AdminUserUpdateRequest $request 31 | * @return array 32 | */ 33 | public function update(Requests\AdminUserUpdateRequest $request) 34 | { 35 | $user = User::find($request->get('user_id')); 36 | 37 | $oldUser = clone $user; 38 | 39 | $user->updateRoleWalletAndFreelunches( 40 | $request->only(['role', 'wallet', 'freelunch']) 41 | ); 42 | 43 | event(new UserWasUpdated([ 44 | 'oldUser' => $oldUser, 45 | 'updateRequest' => $request, 46 | 'updatedUser' => User::find($user->id), 47 | ])); 48 | 49 | return ['status' => 'success']; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /database/seeds/UsersTableSeeder.php: -------------------------------------------------------------------------------- 1 | env('USER_SLACK_ID'), 25 | 'username' => 'neo', 26 | 'email' => env('USER_SLACK_EMAIL'), 27 | 'password' => bcrypt('samplepassword'), 28 | 'role' => (new User)->getRoleIdFromName('Super Admin'), 29 | 'name' => env('USER_SLACK_NAME'), 30 | 'avatar' => env('USER_SLACK_AVATAR'), 31 | 'wallet' => 1000.00, 32 | ]); 33 | 34 | User::create([ 35 | 'slack_id' => str_random(), 36 | 'email' => "dev@hng.tech", 37 | 'name' => "dev", 38 | 'avatar' => env('USER_SLACK_AVATAR'), 39 | 'wallet' => 0.00, 40 | ]); 41 | 42 | User::create([ 43 | 'slack_id' => str_random(), 44 | 'email' => 'dev2@hng.tech', 45 | 'name' => "dev2", 46 | 'avatar' => env('USER_SLACK_AVATAR'), 47 | 'wallet' => 0.00, 48 | ]); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /database/seeds/OptionsTableSeeder.php: -------------------------------------------------------------------------------- 1 | 'HNGFood', 16 | 'SITE_LOGO' => '/img/logo.svg', 17 | 'SITE_FOOTER_TEXT' => 'Created by the HNG.tech team', 18 | 'LANGUAGE' => 'en', 19 | 'CURRENCY' => '₦', 20 | 'FREELUNCH_QUOTA' => 100, 21 | 'PERMISSIONS' => \HNG\Providers\AuthServiceProvider::PERMISSIONS, 22 | 'ALLOW_ANYTIME_FOOD_ORDERS' => 'true', 23 | 'WORK_RESUMES' => 8, 24 | 'WORK_CLOSES' => 6, 25 | 'ORDER_RESUMES' => 6, 26 | 'ORDER_CLOSES' => 9, 27 | 'SLACK_CREDENTIALS' => [ 28 | 'client_id' => env('SLACK_CLIENT_ID'), 29 | 'domain' => env('SLACK_TEAM_DOMAIN'), 30 | 'client_secret' => env('SLACK_CLIENT_SECRET'), 31 | 'redirect' => env('SLACK_REDIRECT_CALLBACK_URL'), 32 | ], 33 | 'SLACK_COMMAND_TOKENS' => explode(',', env('SLACK_COMMAND_TOKENS')), 34 | 'SLACK_DEFAULT_PERMISSIONS' => explode(',', env('SLACK_DEFAULT_PERMISSIONS')), 35 | ]; 36 | 37 | foreach ($options as $name => $value) { 38 | add_option($name, $value); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /app/Providers/RouteServiceProvider.php: -------------------------------------------------------------------------------- 1 | mapWebRoutes($router); 38 | 39 | // 40 | } 41 | 42 | /** 43 | * Define the "web" routes for the application. 44 | * 45 | * These routes all receive session state, CSRF protection, etc. 46 | * 47 | * @param \Illuminate\Routing\Router $router 48 | * @return void 49 | */ 50 | protected function mapWebRoutes(Router $router) 51 | { 52 | $router->group([ 53 | 'namespace' => $this->namespace, 'middleware' => 'web', 54 | ], function ($router) { 55 | require app_path('Http/routes.php'); 56 | }); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /app/Providers/AppServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->environment() === 'local') { 20 | $this->app->register(GeneratorsServiceProvider::class); 21 | } 22 | 23 | $this->registerBladeDirectives(); 24 | } 25 | 26 | /** 27 | * Register any application services. 28 | * 29 | * @return void 30 | */ 31 | public function register() 32 | { 33 | // 34 | } 35 | 36 | /** 37 | * Register custom blade directives. 38 | */ 39 | protected function registerBladeDirectives() 40 | { 41 | Blade::directive('cash', function ($cash) { 42 | $curr = option('CURRENCY'); 43 | 44 | return ""; 45 | }); 46 | 47 | Blade::directive('currency', function () { 48 | $curr = option('CURRENCY'); 49 | 50 | return ""; 51 | }); 52 | 53 | Blade::directive('wallet', function () { 54 | $curr = option('CURRENCY'); 55 | $wallet = auth()->user() ? auth()->user()->wallet : 0; 56 | 57 | return ""; 58 | }); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/Http/Controllers/SlackCommands/FreeLunchController.php: -------------------------------------------------------------------------------- 1 | middleware(['SlackUserExists', 'verifyFreeLunchRequest']); 19 | } 20 | 21 | /** 22 | * Give free lunch to a user 23 | * 24 | * @param Request $request 25 | * @return \Illuminate\Http\Response 26 | */ 27 | public function give(Request $request) 28 | { 29 | $from = $request->slack('from'); 30 | 31 | $to = $request->slack('to'); 32 | 33 | $reason = $request->slack('reason'); 34 | 35 | $freelunch_quota = $request->slack('freelunch_quota'); 36 | 37 | if ((new Freelunch)->give($from->id, $to->id, $reason)) 38 | { 39 | event(new FreelunchQuotaUpdated($freelunch_quota, $freelunch_quota - 1)); 40 | 41 | return $this->slackResponse([ 42 | 'text' => "Great! Free lunch alert!", 43 | 'response_type' => 'in_channel', 44 | 'attachments' => [ 45 | 'text' => "{$from->username} just gave {$to->username} a free lunch {$reason}" 46 | ] 47 | ]); 48 | } 49 | 50 | $msg = "Oops! Seems you messed up the commands, use */freelunch help* to see a list of commands you can run"; 51 | 52 | return $this->slackResponse($msg); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /app/Providers/AuthServiceProvider.php: -------------------------------------------------------------------------------- 1 | 'HNG\Policies\ModelPolicy', 19 | ]; 20 | 21 | /** 22 | * @const array Permissions 23 | */ 24 | const PERMISSIONS = [ 25 | 'free_lunch.grant' => HNG\User::SUPERUSER, 26 | 'inventory.manage' => HNG\User::ADMIN, 27 | 'users.manage' => HNG\User::ADMIN, 28 | 'wallet.manage' => HNG\User::ADMIN, 29 | 'free_lunch.view' => HNG\User::ADMIN, 30 | 'free_lunch.manage' => HNG\User::SUPERADMIN, 31 | 'roles.manage' => HNG\User::SUPERADMIN, 32 | '*' => HNG\User::SUPERADMIN, 33 | ]; 34 | 35 | /** 36 | * Register any application authentication / authorization services. 37 | * 38 | * @param \Illuminate\Contracts\Auth\Access\Gate $gate 39 | * @return void 40 | */ 41 | public function boot(GateContract $gate) 42 | { 43 | $this->registerPolicies($gate); 44 | 45 | foreach (static::PERMISSIONS as $permission => $role) { 46 | Gate::define($permission, function (HNG\User $user) use ($role) { 47 | return $user->hasRole($role); 48 | }); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /database/seeds/LunchTableSeeder.php: -------------------------------------------------------------------------------- 1 | 'Jollof Rice', 'cost' => 0.00, 'buka_id' => 1], 18 | ['name' => 'Fried Rice', 'cost' => 0.00, 'buka_id' => 1], 19 | ['name' => 'Beans', 'cost' => 0.00, 'buka_id' => 1], 20 | ['name' => 'Plantain', 'cost' => 0.00, 'buka_id' => 1], 21 | ['name' => 'Amala', 'cost' => 0.00, 'buka_id' => 1], 22 | ['name' => 'Chicken', 'cost' => 100.00, 'buka_id' => 1], 23 | ['name' => 'Beef', 'cost' => 50.00, 'buka_id' => 1], 24 | 25 | // Commint 26 | ['name' => 'Jollof Rice', 'cost' => 150.00, 'buka_id' => 2], 27 | ['name' => 'Fried Rice', 'cost' => 150.00, 'buka_id' => 2], 28 | ['name' => 'Yam Pottage', 'cost' => 250.00, 'buka_id' => 2], 29 | ['name' => 'Beans', 'cost' => 150.00, 'buka_id' => 2], 30 | ['name' => 'Plantain', 'cost' => 100.00, 'buka_id' => 2], 31 | ['name' => 'Chicken', 'cost' => 500.00, 'buka_id' => 2], 32 | ['name' => 'Beef', 'cost' => 100.00, 'buka_id' => 2], 33 | ['name' => 'Goat Meat', 'cost' => 900.00, 'buka_id' => 2], 34 | ['name' => 'Amala', 'cost' => 150.00, 'buka_id' => 2], 35 | ]; 36 | 37 | foreach ($lunches as $lunch) { 38 | Lunch::create($lunch); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Food Order Management for Teams! 2 | 3 | [![Travis Status][badge_build]][link-travis] 4 | [![Codeship Status][badge_codeship]][link-codeship] 5 | [![Codacy Badge][badge_codacy]][link-codacy] 6 | [![Software License][badge_license]](LICENSE.md) 7 | 8 | HNGFood is a food order management app for teams. 9 | 10 | ### TODOS 11 | List of todos are available [here](todo.md). 12 | 13 | ## Contribution 14 | Any ideas are welcome. Feel free to submit any issues or pull requests, please check the [contribution guidelines](contributing.md). 15 | 16 | ## Security 17 | If you discover any security related issues, please email neo@hng.tech instead of using the issue tracker. 18 | 19 | ## Credits 20 | Thanks to all those who were instrumental in the creation of this application. 21 | - [Neo Ighodaro][link-author] 22 | - [All Contributors][link-contributors] 23 | 24 | [badge_build]: https://travis-ci.org/neoighodaro/hngfood.svg 25 | [badge_codeship]: https://codeship.com/projects/86128440-51ea-0134-1c4d-325cd45b0ee2/status 26 | [badge_codacy]: https://api.codacy.com/project/badge/Grade/273c130d0b674f71b6fed7cb00a12a6e 27 | [badge_license]: https://img.shields.io/badge/license-MIT-brightgreen.svg 28 | 29 | [link-travis]: https://travis-ci.org/neoighodaro/hngfood 30 | [link-codeship]: https://codeship.com/projects/171407 31 | [link-codacy]: https://www.codacy.com/app/neo_2/hngfood?utm_source=github.com&utm_medium=referral&utm_content=neoighodaro/hngfood&utm_campaign=Badge_Grade 32 | [link-author]: http://neoighodaro.com 33 | [link-contributors]: https://github.com/neoighodaro/hngfood/graphs/contributors 34 | -------------------------------------------------------------------------------- /config/broadcasting.php: -------------------------------------------------------------------------------- 1 | env('BROADCAST_DRIVER', 'pusher'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Broadcast Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the broadcast connections that will be used 26 | | to broadcast events to other systems or over websockets. Samples of 27 | | each available type of connection are provided inside this array. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'pusher' => [ 34 | 'driver' => 'pusher', 35 | 'key' => env('PUSHER_KEY'), 36 | 'secret' => env('PUSHER_SECRET'), 37 | 'app_id' => env('PUSHER_APP_ID'), 38 | 'options' => [ 39 | // 40 | ], 41 | ], 42 | 43 | 'redis' => [ 44 | 'driver' => 'redis', 45 | 'connection' => 'default', 46 | ], 47 | 48 | 'log' => [ 49 | 'driver' => 'log', 50 | ], 51 | 52 | ], 53 | 54 | ]; 55 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel/laravel", 3 | "description": "The Laravel Framework.", 4 | "keywords": ["framework", "laravel"], 5 | "license": "MIT", 6 | "type": "project", 7 | "require": { 8 | "php": ">=5.6.4", 9 | "laravel/framework": "5.3.*", 10 | "laravel/socialite": "~2.0", 11 | "vluzrmos/slack-api": "^0.4.7", 12 | "fideloper/proxy": "^3.1", 13 | "barryvdh/laravel-debugbar": "^2.2" 14 | }, 15 | "require-dev": { 16 | "fzaninotto/faker": "~1.4", 17 | "mockery/mockery": "0.9.*", 18 | "phpunit/phpunit": "~4.0", 19 | "symfony/css-selector": "2.8.*|3.0.*", 20 | "symfony/dom-crawler": "2.8.*|3.0.*", 21 | "phpspec/phpspec": "^2.5", 22 | "laracasts/generators": "^1.1" 23 | }, 24 | "autoload": { 25 | "files": [ 26 | "bootstrap/helpers.php" 27 | ], 28 | "classmap": [ 29 | "database" 30 | ], 31 | "psr-4": { 32 | "HNG\\": "app/" 33 | } 34 | }, 35 | "autoload-dev": { 36 | "classmap": [ 37 | "tests/TestCase.php" 38 | ] 39 | }, 40 | "scripts": { 41 | "post-root-package-install": [ 42 | "php -r \"copy('.env.example', '.env');\"" 43 | ], 44 | "post-create-project-cmd": [ 45 | "php artisan key:generate" 46 | ], 47 | "post-install-cmd": [ 48 | "Illuminate\\Foundation\\ComposerScripts::postInstall", 49 | "php artisan optimize" 50 | ], 51 | "post-update-cmd": [ 52 | "Illuminate\\Foundation\\ComposerScripts::postUpdate", 53 | "php artisan optimize" 54 | ] 55 | }, 56 | "config": { 57 | "preferred-install": "dist" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /bootstrap/app.php: -------------------------------------------------------------------------------- 1 | singleton( 30 | Illuminate\Contracts\Http\Kernel::class, 31 | HNG\Http\Kernel::class 32 | ); 33 | 34 | $app->singleton( 35 | Illuminate\Contracts\Console\Kernel::class, 36 | HNG\Console\Kernel::class 37 | ); 38 | 39 | $app->singleton( 40 | Illuminate\Contracts\Debug\ExceptionHandler::class, 41 | HNG\Exceptions\Handler::class 42 | ); 43 | 44 | /* 45 | |-------------------------------------------------------------------------- 46 | | Return The Application 47 | |-------------------------------------------------------------------------- 48 | | 49 | | This script returns the application instance. The instance is given to 50 | | the calling script so we can separate the building of the instances 51 | | from the actual running of the application and sending responses. 52 | | 53 | */ 54 | 55 | return $app; 56 | -------------------------------------------------------------------------------- /artisan: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | make(Illuminate\Contracts\Console\Kernel::class); 32 | 33 | $status = $kernel->handle( 34 | $input = new Symfony\Component\Console\Input\ArgvInput, 35 | new Symfony\Component\Console\Output\ConsoleOutput 36 | ); 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Shutdown The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once Artisan has finished running. We will fire off the shutdown events 44 | | so that any final work may be done by the application before we shut 45 | | down the process. This is the last thing to happen to the request. 46 | | 47 | */ 48 | 49 | $kernel->terminate($input, $status); 50 | 51 | exit($status); 52 | -------------------------------------------------------------------------------- /app/Order.php: -------------------------------------------------------------------------------- 1 | 'float', 'cost_variation' => 'float']; 24 | 25 | /** 26 | * @var array 27 | */ 28 | protected $with = ['lunch']; 29 | 30 | /** 31 | * Create a new order from Lunch. 32 | * 33 | * @param Lunch $lunch 34 | * @return static 35 | */ 36 | public function createFromLunch(Lunch $lunch) 37 | { 38 | return new static([ 39 | 'lunch_id' => $lunch->id, 40 | 'name' => $lunch->name, 41 | ]); 42 | } 43 | 44 | /** 45 | * Get the cost of an order. 46 | * 47 | * @return mixed 48 | */ 49 | public function getCostAttribute() 50 | { 51 | if ( ! $this->exists) { 52 | return false; 53 | } 54 | 55 | $fixedCost = $this->lunch->attributes['cost']; 56 | 57 | return $fixedCost > 0 ? $fixedCost : $this->attributes['cost']; 58 | } 59 | 60 | /** 61 | * Lunchbox relationship. 62 | * 63 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 64 | */ 65 | public function lunchbox() 66 | { 67 | return $this->belongsTo(Lunchbox::class, 'lunchbox_id'); 68 | } 69 | 70 | /** 71 | * Lunch relationship. 72 | * 73 | * @return \Illuminate\Database\Eloquent\Relations\HasOne 74 | */ 75 | public function lunch() 76 | { 77 | return $this->belongsTo(Lunch::class, 'lunch_id'); 78 | } 79 | } -------------------------------------------------------------------------------- /spec/Lunch/OrderSummariserSpec.php: -------------------------------------------------------------------------------- 1 | beConstructedWith($this->_orders()); 14 | $this->orders()->shouldBe($this->_orders()); 15 | } 16 | 17 | function it_should_throw_an_error_if_name_key_is_not_found() 18 | { 19 | $orders = $this->_orders() + ['id' => 1]; 20 | $this->shouldThrow(InvalidArgumentException::class)->during('__construct', [$orders]); 21 | } 22 | 23 | function it_is_countable() 24 | { 25 | $this->beConstructedWith($this->_orders()); 26 | $this->count()->shouldBe(5); 27 | } 28 | 29 | function it_should_return_one_dish_explicitly() 30 | { 31 | $this->beConstructedWith([ 32 | ['name' => 'Jollof Rice'] 33 | ]); 34 | 35 | $this->summary()->shouldBe('Jollof Rice'); 36 | } 37 | 38 | function it_should_return_two_dishes_explicitly() { 39 | $this->beConstructedWith([ 40 | ['name' => 'Jollof Rice'], 41 | ['name' => 'Beans'], 42 | ]); 43 | 44 | $this->summary()->shouldBe('Jollof Rice and Beans'); 45 | } 46 | 47 | function it_should_return_aggregate_readable_for_three_or_more_dishes() 48 | { 49 | $this->beConstructedWith($this->_orders()); 50 | $this->summary()->shouldReturn('Jollof Rice and 4 more dishes'); 51 | } 52 | 53 | private function _orders() 54 | { 55 | return [ 56 | ['name' => 'Jollof Rice'], 57 | ['name' => 'Beans'], 58 | ['name' => 'Beef'], 59 | ['name' => 'Amala'], 60 | ['name' => 'Fried Rice'], 61 | ]; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /app/Http/Controllers/SlackCommands/WalletController.php: -------------------------------------------------------------------------------- 1 | middleware(['SlackUserExists', 'WalletSlackSubCommandExists']); 19 | } 20 | 21 | /** 22 | * Route to the proper method. 23 | * 24 | * @param Request $request 25 | * @return mixed 26 | */ 27 | public function router(Request $request) 28 | { 29 | $method = $request->getSlackText(); 30 | 31 | return $this->{$method}($request); 32 | } 33 | 34 | /** 35 | * Gets the users wallet balance. 36 | * 37 | * @param Request $request 38 | * @return \Illuminate\Http\Response 39 | */ 40 | public function balance(Request $request) 41 | { 42 | $user = User::whereSlackId($request->get('user_id'))->first(); 43 | 44 | $attachments = []; 45 | 46 | if ($freelunches = $user->freelunches()->active($user->id)->count()) { 47 | $msg = sprintf( 48 | "You stud! You currently have %d free %s.", 49 | $freelunches, 50 | str_plural('lunch', $freelunches) 51 | ); 52 | 53 | $attachments[]['text'] = $msg; 54 | } 55 | 56 | $message = "You have NGN{$user->wallet} in your wallet!"; 57 | 58 | return $this->slackResponse($message, $attachments); 59 | } 60 | 61 | /** 62 | * Coming soon... 63 | * 64 | * @return \Illuminate\Http\Response 65 | */ 66 | public function transfer() 67 | { 68 | return $this->slackResponse("This feature is not available yet!"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /public/index.php: -------------------------------------------------------------------------------- 1 | 8 | */ 9 | 10 | /* 11 | |-------------------------------------------------------------------------- 12 | | Register The Auto Loader 13 | |-------------------------------------------------------------------------- 14 | | 15 | | Composer provides a convenient, automatically generated class loader for 16 | | our application. We just need to utilize it! We'll simply require it 17 | | into the script here so that we don't have to worry about manual 18 | | loading any of our classes later on. It feels nice to relax. 19 | | 20 | */ 21 | 22 | require __DIR__.'/../bootstrap/autoload.php'; 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Turn On The Lights 27 | |-------------------------------------------------------------------------- 28 | | 29 | | We need to illuminate PHP development, so let us turn on the lights. 30 | | This bootstraps the framework and gets it ready for use, then it 31 | | will load up this application so that we can run it and send 32 | | the responses back to the browser and delight our users. 33 | | 34 | */ 35 | 36 | $app = require_once __DIR__.'/../bootstrap/app.php'; 37 | 38 | /* 39 | |-------------------------------------------------------------------------- 40 | | Run The Application 41 | |-------------------------------------------------------------------------- 42 | | 43 | | Once we have the application, we can handle the incoming request 44 | | through the kernel, and send the associated response back to 45 | | the client's browser allowing them to enjoy the creative 46 | | and wonderful application we have prepared for them. 47 | | 48 | */ 49 | 50 | $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class); 51 | 52 | $response = $kernel->handle( 53 | $request = Illuminate\Http\Request::capture() 54 | ); 55 | 56 | $response->send(); 57 | 58 | $kernel->terminate($request, $response); 59 | -------------------------------------------------------------------------------- /app/Socialite/SlackProvider.php: -------------------------------------------------------------------------------- 1 | scopes = (array) option('SLACK_DEFAULT_PERMISSIONS'); 21 | 22 | parent::__construct($request, $clientId, $clientSecret, $redirectUrl); 23 | } 24 | 25 | /** 26 | * {@inheritdoc} 27 | */ 28 | protected function getAuthUrl($state) 29 | { 30 | return $this->buildAuthUrlFromBase('https://slack.com/oauth/authorize', $state); 31 | } 32 | 33 | /** 34 | * {@inheritdoc} 35 | */ 36 | protected function getTokenUrl() 37 | { 38 | return 'https://slack.com/api/oauth.access'; 39 | } 40 | 41 | /** 42 | * {@inheritdoc} 43 | */ 44 | protected function getUserByToken($token) 45 | { 46 | $options = ['headers' => ['Accept' => 'application/json']]; 47 | $endpoint = 'https://slack.com/api/users.identity?token='.$token; 48 | 49 | $response = $this->getHttpClient()->get($endpoint, $options)->getBody()->getContents(); 50 | $response = json_decode($response, true); 51 | 52 | return $response; 53 | } 54 | 55 | /** 56 | * {@inheritdoc} 57 | */ 58 | protected function mapUserToObject(array $user) 59 | { 60 | return (new User)->setRaw($user)->map([ 61 | 'id' => array_get($user, 'user.id'), 62 | 'name' => array_get($user, 'user.name'), 63 | 'email' => array_get($user, 'user.email'), 64 | 'avatar' => array_get($user, 'user.image_192'), 65 | ]); 66 | } 67 | } -------------------------------------------------------------------------------- /resources/views/auth/passwords/email.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | 4 | @section('content') 5 |
6 |
7 |
8 |
9 |
Reset Password
10 |
11 | @if (session('status')) 12 |
13 | {{ session('status') }} 14 |
15 | @endif 16 | 17 |
18 | {{ csrf_field() }} 19 | 20 |
21 | 22 | 23 |
24 | 25 | 26 | @if ($errors->has('email')) 27 | 28 | {{ $errors->first('email') }} 29 | 30 | @endif 31 |
32 |
33 | 34 |
35 |
36 | 39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 | @endsection 48 | -------------------------------------------------------------------------------- /config/filesystems.php: -------------------------------------------------------------------------------- 1 | 'local', 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Default Cloud Filesystem Disk 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Many applications store files both locally and in the cloud. For this 26 | | reason, you may specify a default "cloud" driver here. This driver 27 | | will be bound as the Cloud disk implementation in the container. 28 | | 29 | */ 30 | 31 | 'cloud' => 's3', 32 | 33 | /* 34 | |-------------------------------------------------------------------------- 35 | | Filesystem Disks 36 | |-------------------------------------------------------------------------- 37 | | 38 | | Here you may configure as many filesystem "disks" as you wish, and you 39 | | may even configure multiple disks of the same driver. Defaults have 40 | | been setup for each driver as an example of the required options. 41 | | 42 | */ 43 | 44 | 'disks' => [ 45 | 46 | 'local' => [ 47 | 'driver' => 'local', 48 | 'root' => storage_path('app'), 49 | ], 50 | 51 | 'public' => [ 52 | 'driver' => 'local', 53 | 'root' => storage_path('app/public'), 54 | 'visibility' => 'public', 55 | ], 56 | 57 | 's3' => [ 58 | 'driver' => 's3', 59 | 'key' => 'your-key', 60 | 'secret' => 'your-secret', 61 | 'region' => 'your-region', 62 | 'bucket' => 'your-bucket', 63 | ], 64 | 65 | ], 66 | 67 | ]; 68 | -------------------------------------------------------------------------------- /app/Http/Requests/OrderRequest.php: -------------------------------------------------------------------------------- 1 | user() && $this->userWalletCanHandleOrder(); 16 | } 17 | 18 | /** 19 | * Get the validation rules that apply to the request. 20 | * 21 | * @return array 22 | */ 23 | public function rules() 24 | { 25 | $rules = [ 26 | 'free_lunch' => 'required|in:0,1', 27 | 'buka_id' => 'required|exists:bukas,id', 28 | ]; 29 | 30 | // Get the buka ID expected from this order 31 | $buka_id = $this->input('buka_id'); 32 | 33 | // Get all orders (array) 34 | $orders = (array) $this->get('orders'); 35 | 36 | // Set validation rules for certain keys in each order in the array 37 | foreach (array_keys($orders) as $key) { 38 | $rules["orders.{$key}.note"] = "between:1,255"; 39 | $rules["orders.{$key}.servings"] = "required|numeric|between:1,5"; 40 | $rules["orders.{$key}.id"] = "required|exists:lunches,id,buka_id,{$buka_id}"; 41 | } 42 | 43 | return $rules; 44 | } 45 | 46 | /** 47 | * Check if the request wants to redeem freelunches. 48 | * 49 | * @return boolean 50 | */ 51 | public function wantsToRedeemFreelunch() 52 | { 53 | return $this->get('free_lunch') == 1; 54 | } 55 | 56 | /** 57 | * Checks if the user wallet cannot handle the order. 58 | * 59 | * @return boolean 60 | */ 61 | private function userWalletCanHandleOrder() 62 | { 63 | $totalCost = 0; 64 | $availableCash = number_unformat(auth()->user()->wallet); 65 | 66 | if ($this->wantsToRedeemFreelunch()) { 67 | $availableCash += (new Freelunch)->worth(); 68 | } 69 | 70 | $orders = (array) $this->get('orders'); 71 | 72 | foreach ($orders as $order) { 73 | $lunch = Lunch::find($order['id']); 74 | $totalCost += ($lunch->cost > 0 ? $lunch->cost : $order['cost']) * $order['servings']; 75 | } 76 | 77 | return $availableCash >= $totalCost; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /app/Http/Middleware/FreeLunchCommandVerifier.php: -------------------------------------------------------------------------------- 1 | get('user_id'))->first(); 24 | 25 | if ( ! $from OR ! Gate::forUser($from)->allows('free_lunch.grant')) { 26 | return $this->slackResponse("Sorry! You can't give free lunches."); 27 | } 28 | 29 | $username = $this->getUsernameFromRequest($request); 30 | 31 | if (empty($username) OR ! $to = User::whereUsername($username)->first()) { 32 | return $this->slackResponse("Oops! Can't find {$username} in your team!"); 33 | } 34 | 35 | if ( ! $reason = $this->getFreeLunchReason($request)) { 36 | return $this->slackResponse("You have to tell what the free lunch is for!"); 37 | } 38 | 39 | if(!$freelunch_quota = option('freelunch_quota')) 40 | { 41 | return $this->slackResponse("Sorry your team's out of free lunches. Maybe next time."); 42 | } 43 | 44 | $request->attributes->add(['from' => $from, 'to' => $to, 'reason' => $reason, 'freelunch_quota' => 45 | $freelunch_quota]); 46 | 47 | return $next($request); 48 | } 49 | 50 | /** 51 | * Get reciever username from text & remove the @ from the username. 52 | * 53 | * @param $request 54 | * @return string 55 | */ 56 | private function getUsernameFromRequest($request) 57 | { 58 | preg_match('/\s*@\w+/', $request->get('text'), $receiver); 59 | 60 | return str_replace('@', '', array_get($receiver, 0, '')); 61 | } 62 | 63 | /** 64 | * Get freelunch reason from text. 65 | * 66 | * @param $request 67 | * @return string 68 | */ 69 | private function getFreeLunchReason($request) 70 | { 71 | $reason = preg_replace('/\s*@\w+/', '', $request->get('text')); 72 | 73 | return trim($reason); 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /app/Http/Kernel.php: -------------------------------------------------------------------------------- 1 | [ 29 | Middleware\EncryptCookies::class, 30 | \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, 31 | \Illuminate\Session\Middleware\StartSession::class, 32 | \Illuminate\View\Middleware\ShareErrorsFromSession::class, 33 | Middleware\VerifyCsrfToken::class, 34 | \Illuminate\Routing\Middleware\SubstituteBindings::class, 35 | ], 36 | 37 | 'api' => [ 38 | 'throttle:60,1', 39 | 'bindings', 40 | ], 41 | ]; 42 | 43 | /** 44 | * The application's route middleware. 45 | * 46 | * These middleware may be assigned to groups or used individually. 47 | * 48 | * @var array 49 | */ 50 | protected $routeMiddleware = [ 51 | 'auth' => Middleware\Authenticate::class, 52 | 'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class, 53 | 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 54 | 'can' => \Illuminate\Auth\Middleware\Authorize::class, 55 | 'guest' => Middleware\RedirectIfAuthenticated::class, 56 | 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, 57 | 'verifyOrderId' => Middleware\VerifyLunchboxID::class, 58 | 'timekeeper' => Middleware\VerifyValidOrderTime::class, 59 | 'verifyAdmin' => Middleware\VerifyAdminUser::class, 60 | 'verifyAdminSession' => Middleware\VerifyAdminSession::class, 61 | 'SlackUserExists' => Middleware\SlackCommandUserExists::class, 62 | 'verifyFreeLunchRequest' => Middleware\FreeLunchCommandVerifier::class, 63 | 'WalletSlackSubCommandExists' => Middleware\WalletSlackSubCommandExists::class, 64 | ]; 65 | } 66 | -------------------------------------------------------------------------------- /app/Lunch/Timekeeper.php: -------------------------------------------------------------------------------- 1 | carbon = $carbon ? $carbon : Carbon::now(); 20 | } 21 | 22 | /** 23 | * Check if we are in a weekend. 24 | * 25 | * @return bool 26 | */ 27 | public function isWeekend() 28 | { 29 | return $this->carbon()->isWeekend(); 30 | } 31 | 32 | /** 33 | * Check if we are in a weekday 34 | * 35 | * @return bool 36 | */ 37 | public function isWeekday() 38 | { 39 | return ! $this->isWeekend(); 40 | } 41 | 42 | /** 43 | * Check if the current hour is between two hours. 44 | * 45 | * @param $firstHour 46 | * @param $secondHour 47 | * @return bool 48 | */ 49 | public function isHoursBetween($firstHour, $secondHour) 50 | { 51 | $currentHour = $this->carbon()->hour; 52 | 53 | return $currentHour >= $firstHour && $currentHour < $secondHour; 54 | } 55 | 56 | /** 57 | * Are we during normal working hours? 58 | * 59 | * @return bool 60 | */ 61 | public function duringWorkingHours() 62 | { 63 | $sob = option('WORK_RESUMES'); 64 | $cob = option('WORK_CLOSES'); 65 | 66 | return $this->isWeekday() && $this->isHoursBetween($sob, $cob); 67 | } 68 | 69 | /** 70 | * Is within the lunch order hours. 71 | * 72 | * @return bool 73 | */ 74 | public function isWithinLunchOrderHours() 75 | { 76 | $soo = option('ORDER_RESUMES'); 77 | $coo = option('ORDER_CLOSES'); 78 | 79 | return $this->allowOrdersAtAnytime() OR ($this->isWeekday() && $this->isHoursBetween($soo, $coo)); 80 | } 81 | 82 | /** 83 | * Carbon instance. 84 | * 85 | * @return Carbon 86 | */ 87 | public function carbon() 88 | { 89 | return $this->carbon; 90 | } 91 | 92 | /** 93 | * Checks if the environment is local. 94 | * 95 | * @return boolean 96 | */ 97 | private function allowOrdersAtAnytime() 98 | { 99 | return (bool) get_option('ALLOW_ANYTIME_FOOD_ORDERS'); 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /config/cache.php: -------------------------------------------------------------------------------- 1 | env('CACHE_DRIVER', 'file'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Cache Stores 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may define all of the cache "stores" for your application as 26 | | well as their drivers. You may even define multiple stores for the 27 | | same cache driver to group types of items stored in your caches. 28 | | 29 | */ 30 | 31 | 'stores' => [ 32 | 33 | 'apc' => [ 34 | 'driver' => 'apc', 35 | ], 36 | 37 | 'array' => [ 38 | 'driver' => 'array', 39 | ], 40 | 41 | 'database' => [ 42 | 'driver' => 'database', 43 | 'table' => 'cache', 44 | 'connection' => null, 45 | ], 46 | 47 | 'file' => [ 48 | 'driver' => 'file', 49 | 'path' => storage_path('framework/cache'), 50 | ], 51 | 52 | 'memcached' => [ 53 | 'driver' => 'memcached', 54 | 'servers' => [ 55 | [ 56 | 'host' => env('MEMCACHED_HOST', '127.0.0.1'), 57 | 'port' => env('MEMCACHED_PORT', 11211), 58 | 'weight' => 100, 59 | ], 60 | ], 61 | ], 62 | 63 | 'redis' => [ 64 | 'driver' => 'redis', 65 | 'connection' => 'default', 66 | ], 67 | 68 | ], 69 | 70 | /* 71 | |-------------------------------------------------------------------------- 72 | | Cache Key Prefix 73 | |-------------------------------------------------------------------------- 74 | | 75 | | When utilizing a RAM based store such as APC or Memcached, there might 76 | | be other applications utilizing the same cache. So, we'll specify a 77 | | value to get prefixed to all our keys so we can avoid collisions. 78 | | 79 | */ 80 | 81 | 'prefix' => 'laravel', 82 | 83 | ]; 84 | -------------------------------------------------------------------------------- /app/Lunch/OrderSummariser.php: -------------------------------------------------------------------------------- 1 | orders = $orders; 28 | } 29 | 30 | /** 31 | * Return the orders. 32 | * 33 | * @return array 34 | */ 35 | public function orders() 36 | { 37 | return $this->orders; 38 | } 39 | 40 | /** 41 | * Returns a human readable summary of the orders. 42 | * 43 | * @return string 44 | */ 45 | public function summary() 46 | { 47 | if ($this->count() >= 3) { 48 | $str = $this->createReadableStringForThreeOrMoreDishes(); 49 | } else { 50 | $str = $this->createReadableStringForOneOrTwoDishes(); 51 | } 52 | 53 | return $str; 54 | } 55 | 56 | /** 57 | * Object to string conversion. 58 | * 59 | * @return string 60 | */ 61 | public function __toString() 62 | { 63 | return $this->summary(); 64 | } 65 | 66 | /** 67 | * Return a count of the orders. 68 | * 69 | * @return int 70 | */ 71 | public function count() 72 | { 73 | return count($this->orders()); 74 | } 75 | 76 | /** 77 | * Create readable string for one or two dishes. 78 | * 79 | * @return string 80 | */ 81 | private function createReadableStringForOneOrTwoDishes() 82 | { 83 | $str = ''; 84 | 85 | for ($i = 0; $i < $this->count(); $i ++) { 86 | $str .= $this->orders()[$i]['name']; 87 | 88 | if ($i < $this->count() - 1) { 89 | $str .= ($this->count() == 2) ? " and " : ", "; 90 | } 91 | } 92 | 93 | return $str; 94 | } 95 | 96 | /** 97 | * Create readable string for three or more dishes 98 | * 99 | * @return string 100 | */ 101 | private function createReadableStringForThreeOrMoreDishes() 102 | { 103 | $firstDish = $this->orders()[0]['name']; 104 | 105 | $remaining = ($this->count() - 1); 106 | 107 | $str = $firstDish . " and " . $remaining . " more dishes"; 108 | 109 | return $str; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /resources/views/layouts/admin.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Admin Dashboard') 4 | @section('content') 5 |
6 |
7 |
8 |
9 | {{--
--}} 10 | {{----}} 11 | {{--
--}} 12 |
13 | 48 |
49 |
50 |
51 |
52 | @yield('admin-content') 53 |
54 |
55 |
56 | @endsection -------------------------------------------------------------------------------- /config/queue.php: -------------------------------------------------------------------------------- 1 | env('QUEUE_DRIVER', 'sync'), 19 | 20 | /* 21 | |-------------------------------------------------------------------------- 22 | | Queue Connections 23 | |-------------------------------------------------------------------------- 24 | | 25 | | Here you may configure the connection information for each server that 26 | | is used by your application. A default configuration has been added 27 | | for each back-end shipped with Laravel. You are free to add more. 28 | | 29 | */ 30 | 31 | 'connections' => [ 32 | 33 | 'sync' => [ 34 | 'driver' => 'sync', 35 | ], 36 | 37 | 'database' => [ 38 | 'driver' => 'database', 39 | 'table' => 'jobs', 40 | 'queue' => 'default', 41 | 'retry_after' => 60, 42 | ], 43 | 44 | 'beanstalkd' => [ 45 | 'driver' => 'beanstalkd', 46 | 'host' => 'localhost', 47 | 'queue' => 'default', 48 | 'retry_after' => 60, 49 | ], 50 | 51 | 'sqs' => [ 52 | 'driver' => 'sqs', 53 | 'key' => 'your-public-key', 54 | 'secret' => 'your-secret-key', 55 | 'prefix' => 'https://sqs.us-east-1.amazonaws.com/your-account-id', 56 | 'queue' => 'your-queue-name', 57 | 'region' => 'us-east-1', 58 | ], 59 | 60 | 'redis' => [ 61 | 'driver' => 'redis', 62 | 'connection' => 'default', 63 | 'queue' => 'default', 64 | 'retry_after' => 60, 65 | ], 66 | 67 | ], 68 | 69 | /* 70 | |-------------------------------------------------------------------------- 71 | | Failed Queue Jobs 72 | |-------------------------------------------------------------------------- 73 | | 74 | | These options configure the behavior of failed queue job logging so you 75 | | can control which database and table are used to store the jobs that 76 | | have failed. You may change them to any database / table you wish. 77 | | 78 | */ 79 | 80 | 'failed' => [ 81 | 'database' => env('DB_CONNECTION', 'mysql'), 82 | 'table' => 'failed_jobs', 83 | ], 84 | 85 | ]; 86 | -------------------------------------------------------------------------------- /bootstrap/helpers.php: -------------------------------------------------------------------------------- 1 | summary(); 27 | } 28 | } 29 | 30 | if ( ! function_exists('lunchbox_cost')) 31 | { 32 | /** 33 | * Get the lunchbox total cost. 34 | * 35 | * @param int|HNG\Lunchbox $lunchbox 36 | * @return mixed 37 | */ 38 | function lunchbox_cost($lunchbox) 39 | { 40 | $lunchbox = $lunchbox instanceof HNG\Lunchbox 41 | ? $lunchbox 42 | : (new HNG\Lunchbox)->find($lunchbox); 43 | 44 | return $lunchbox->totalCost(); 45 | } 46 | } 47 | 48 | if ( ! function_exists('get_option')) 49 | { 50 | /** 51 | * Read an option from the database. 52 | * 53 | * @param $name 54 | * @param bool $default 55 | * @return bool|mixed 56 | */ 57 | function get_option($name, $default = false) 58 | { 59 | if (strpos($name, '.') !== false) { 60 | $key = explode('.', $name)[0]; 61 | 62 | $option = (new HNG\Option)->name($key, HNG\Option::READONLY, $default); 63 | 64 | $value = array_get($option, str_replace($key.'.', '', $name)); 65 | } else { 66 | $value = (new HNG\Option)->name($name, HNG\Option::READONLY, $default); 67 | } 68 | 69 | return $value; 70 | } 71 | } 72 | 73 | if ( ! function_exists('add_option')) 74 | { 75 | /** 76 | * Write new option to the database. 77 | * 78 | * @param $name 79 | * @param $value 80 | * @return bool|mixed 81 | */ 82 | function add_option($name, $value) 83 | { 84 | return (new HNG\Option)->name($name, $value); 85 | } 86 | } 87 | 88 | if ( ! function_exists('option')) 89 | { 90 | /** 91 | * Get or set an option. 92 | * 93 | * @param $name 94 | * @param string $value 95 | * @param bool $default 96 | * @return bool|mixed 97 | */ 98 | function option($name, $value = HNG\Option::READONLY, $default = false) 99 | { 100 | if ($value === HNG\Option::READONLY) { 101 | return get_option($name, $default); 102 | } 103 | 104 | return add_option($name, $value); 105 | } 106 | } -------------------------------------------------------------------------------- /app/Http/Controllers/HomeController.php: -------------------------------------------------------------------------------- 1 | middleware('auth'); 23 | $this->middleware('timekeeper')->only('order'); 24 | $this->middleware('verifyOrderId')->only('orderCompleted'); 25 | 26 | parent::__construct(); 27 | } 28 | 29 | /** 30 | * Show the application dashboard. 31 | * 32 | * @param Timekeeper $timekeeper 33 | * @param Buka $buka 34 | * @param Freelunch $freelunch 35 | * @return \Illuminate\Http\Response 36 | */ 37 | public function index(Timekeeper $timekeeper, Buka $buka, Freelunch $freelunch) 38 | { 39 | return view('home', [ 40 | 'inPageTitle' => 'Dashboard', 41 | 'timekeeper' => $timekeeper, 42 | 'bukas' => $buka->all(), 43 | 'freelunch' => $freelunch->active(), 44 | ]); 45 | } 46 | 47 | /** 48 | * Create an order. 49 | * 50 | * @param OrderRequest $request 51 | * @param Lunchbox $lunchbox 52 | * @return array 53 | */ 54 | public function order(OrderRequest $request, Lunchbox $lunchbox) 55 | { 56 | $order = $lunchbox->createWithOrders($request); 57 | 58 | event(new LunchWasOrdered($order, $request)); 59 | 60 | return Lunchbox::without('buka,lunches')->findOrFail($order->id); 61 | } 62 | 63 | /** 64 | * Completed an order successfully. 65 | * 66 | * @param int $id 67 | * @return \Illuminate\Http\Response 68 | */ 69 | public function orderCompleted($id) 70 | { 71 | $order = Lunchbox::find($id); 72 | 73 | $dancers = config('app.dancers'); 74 | $dancer = $dancers[array_rand($dancers)]; 75 | 76 | return view('order.completed', compact('order', 'dancer')); 77 | } 78 | 79 | 80 | /** 81 | * Get order history. 82 | * 83 | * @param Request $request 84 | * @return Response 85 | * @todo Create a filter system for the UI 86 | */ 87 | public function orderHistory(Request $request) 88 | { 89 | $end = $request->get('end'); 90 | $start = $request->get('start', Carbon::now()->startOfMonth()); 91 | 92 | $orders = Lunchbox::ordersBetween($start, $end) 93 | ->without('orders') 94 | ->with('buka') 95 | ->orderBy('created_at', 'DESC') 96 | ->paginate(10); 97 | 98 | return view('order.history', [ 99 | 'orders' => $orders, 100 | 'inPageTitle' => 'Orders History', 101 | ]); 102 | } 103 | 104 | } 105 | -------------------------------------------------------------------------------- /resources/views/auth/passwords/reset.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Reset Password
9 | 10 |
11 |
12 | {{ csrf_field() }} 13 | 14 | 15 | 16 |
17 | 18 | 19 |
20 | 21 | 22 | @if ($errors->has('email')) 23 | 24 | {{ $errors->first('email') }} 25 | 26 | @endif 27 |
28 |
29 | 30 |
31 | 32 | 33 |
34 | 35 | 36 | @if ($errors->has('password')) 37 | 38 | {{ $errors->first('password') }} 39 | 40 | @endif 41 |
42 |
43 | 44 |
45 | 46 |
47 | 48 | 49 | @if ($errors->has('password_confirmation')) 50 | 51 | {{ $errors->first('password_confirmation') }} 52 | 53 | @endif 54 |
55 |
56 | 57 |
58 |
59 | 62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | @endsection 71 | -------------------------------------------------------------------------------- /resources/views/order/completed.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Order Completed - '.option('APP_NAME')) 4 | 5 | @section('content') 6 |
7 |
8 |
9 |
10 | 12 | 15 | 18 | 19 |

Order Completed! View Order.

20 |
21 | Order Completed 22 |
23 |
24 |
25 |
26 | 27 | 28 | 71 | @endsection -------------------------------------------------------------------------------- /resources/views/auth/login.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 | 5 | 6 | 7 | Sign in with Slack 8 | 9 | 10 |
11 |
12 |
13 |
14 |
Login
15 |
16 |
17 | {{ csrf_field() }} 18 | 19 |
20 | 21 | 22 |
23 | 24 | 25 | @if ($errors->has('email')) 26 | 27 | {{ $errors->first('email') }} 28 | 29 | @endif 30 |
31 |
32 | 33 |
34 | 35 | 36 |
37 | 38 | 39 | @if ($errors->has('password')) 40 | 41 | {{ $errors->first('password') }} 42 | 43 | @endif 44 |
45 |
46 | 47 |
48 |
49 |
50 | 53 |
54 |
55 |
56 | 57 |
58 |
59 | 62 | 63 | Forgot Your Password? 64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | @endsection 73 | -------------------------------------------------------------------------------- /resources/views/admin/freelunch-overview.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.admin') 2 | 3 | @section('admin-content') 4 |
5 |

Free Lunch Overview

6 |
7 |
8 |

Unused

9 | {{ $freelunchOverview['unused'] }} 10 |
11 |
12 |

Available Quota [Manage]

13 | {{ $freelunchOverview['remaining'] }} 14 |
15 |
16 |
17 | 18 | 19 | 65 | 66 | @endsection -------------------------------------------------------------------------------- /resources/views/order/history.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('title', 'Order History - '.option('APP_NAME')) 4 | 5 | @section('content') 6 | 7 | @if ($orders->count() > 0) 8 |
9 |
10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 | @foreach($orders as $lunchbox) 18 | 19 | 20 | 32 | 33 | 34 | @endforeach 35 | 36 |
SummaryCost
21 |

22 | 27 | {{ summarise_order($lunchbox->ordersGrouped()->toArray()) }} 28 | 29 | {{$lunchbox->created_at->diffForHumans()}} 30 |

31 |
@cash($lunchbox->totalCost())
37 |
38 | {{$orders->links()}} 39 |
40 |
41 | 42 | 43 | 75 | @else 76 |
77 |
78 |
79 |
80 | Nothing to see 81 |
82 |

Move along, there's nothing to see here.

83 |
84 |
85 |
86 | @endif 87 | @endsection -------------------------------------------------------------------------------- /app/Http/routes.php: -------------------------------------------------------------------------------- 1 | group(['prefix' => 'auth/slack', 'namespace' => 'Auth'], function ($router) { 19 | $router->get('/callback/user', ['as' =>'auth.slack.callback.user', 'uses' => 'AuthController@handleProviderCallbackUser']); 20 | $router->get('/callback', 'AuthController@handleProviderCallback'); 21 | $router->get('/', ['as' => 'auth.slack', 'uses' => 'AuthController@redirectToProvider']); 22 | }); 23 | 24 | 25 | // ------------------------------------------------------------------------ 26 | // SLACK COMMANDS 27 | // ------------------------------------------------------------------------ 28 | 29 | $router->group(['prefix' => 'slack/commands', 'namespace' => 'SlackCommands'], function ($router) { 30 | $router->group(['prefix' => 'wallet'], function ($router) { 31 | $router->post('balance', ['as' => 'slack.cmd.wallet.balance', 'uses' => 'WalletController@balance']); 32 | }); 33 | 34 | $router->post('freelunch',['as' => 'slack.cmd.freelunch', 'uses' => 'FreeLunchController@give']); 35 | }); 36 | 37 | 38 | // ------------------------------------------------------------------------ 39 | // ADMINISTRATION 40 | // ------------------------------------------------------------------------ 41 | 42 | $router->group(['prefix' => 'admin', 'namespace' => 'Admin'], function ($router) { 43 | $router->get('/login', ['as' => 'admin.login', 'uses' => 'AuthController@authForm']); 44 | $router->post('/login', ['uses' => 'AuthController@authProcess']); 45 | 46 | $router->group(['prefix' => 'freelunch'], function ($router) { 47 | $router->post('/update', ['as' => 'admin.freelunch.update', 'uses' => 'FreelunchController@update']); 48 | $router->get('/overview', ['as' => 'admin.freelunch.overview', 'uses' => 'FreelunchController@overview']); 49 | }); 50 | 51 | $router->group(['prefix' => 'users'], function ($router) { 52 | $router->get('/manage', ['as' => 'admin.users.manage', 'uses' => 'UserController@userlist']); 53 | $router->post('/update', ['as' => 'admin.users.update', 'uses' => 'UserController@update']); 54 | }); 55 | 56 | $router->get('/dashboard', ['as' => 'admin.dashboard.overview', 'uses' => 'AdminController@index']); 57 | $router->get('/', ['as' => 'admin.dashboard', function () { return redirect()->route('admin.dashboard.overview'); }]); 58 | }); 59 | 60 | 61 | // ------------------------------------------------------------------------ 62 | // OTHER ROUTES 63 | // ------------------------------------------------------------------------ 64 | 65 | $router->get('/login', function () { return redirect('/'); }); 66 | $router->get('/logout', ['as' => 'logout', 'uses' => 'Auth\AuthController@logout',]); 67 | $router->get('/home', ['as' => 'home', 'uses' => 'HomeController@index',]); 68 | $router->get('/order/completed/{id}', ['as' => 'order.completed', 'uses' => 'HomeController@orderCompleted']); 69 | $router->get('/order/history', ['as' => 'order.history', 'uses' => 'HomeController@orderHistory']); 70 | $router->post('/order/complete', ['as' => 'order', 'uses' => 'HomeController@order']); 71 | 72 | // ------------------------------------------------------------------------ 73 | // HOME PAGE 74 | // ------------------------------------------------------------------------ 75 | 76 | $router->get('/', ['as' => 'guest.home', 'uses' => 'GuestController@index']); 77 | 78 | -------------------------------------------------------------------------------- /config/auth.php: -------------------------------------------------------------------------------- 1 | [ 17 | 'guard' => 'web', 18 | 'passwords' => 'users', 19 | ], 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Authentication Guards 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Next, you may define every authentication guard for your application. 27 | | Of course, a great default configuration has been defined for you 28 | | here which uses session storage and the Eloquent user provider. 29 | | 30 | | All authentication drivers have a user provider. This defines how the 31 | | users are actually retrieved out of your database or other storage 32 | | mechanisms used by this application to persist your user's data. 33 | | 34 | | Supported: "session", "token" 35 | | 36 | */ 37 | 38 | 'guards' => [ 39 | 'web' => [ 40 | 'driver' => 'session', 41 | 'provider' => 'users', 42 | ], 43 | 44 | 'api' => [ 45 | 'driver' => 'token', 46 | 'provider' => 'users', 47 | ], 48 | ], 49 | 50 | /* 51 | |-------------------------------------------------------------------------- 52 | | User Providers 53 | |-------------------------------------------------------------------------- 54 | | 55 | | All authentication drivers have a user provider. This defines how the 56 | | users are actually retrieved out of your database or other storage 57 | | mechanisms used by this application to persist your user's data. 58 | | 59 | | If you have multiple user tables or models you may configure multiple 60 | | sources which represent each model / table. These sources may then 61 | | be assigned to any extra authentication guards you have defined. 62 | | 63 | | Supported: "database", "eloquent" 64 | | 65 | */ 66 | 67 | 'providers' => [ 68 | 'users' => [ 69 | 'driver' => 'eloquent', 70 | 'model' => HNG\User::class, 71 | ], 72 | 73 | // 'users' => [ 74 | // 'driver' => 'database', 75 | // 'table' => 'users', 76 | // ], 77 | ], 78 | 79 | /* 80 | |-------------------------------------------------------------------------- 81 | | Resetting Passwords 82 | |-------------------------------------------------------------------------- 83 | | 84 | | Here you may set the options for resetting passwords including the view 85 | | that is your password reset e-mail. You may also set the name of the 86 | | table that maintains all of the reset tokens for your application. 87 | | 88 | | You may specify multiple password reset configurations if you have more 89 | | than one user table or model in the application and you want to have 90 | | separate password reset settings based on the specific user types. 91 | | 92 | | The expire time is the number of minutes that the reset token should be 93 | | considered valid. This security feature keeps tokens short-lived so 94 | | they have less time to be guessed. You may change this as needed. 95 | | 96 | */ 97 | 98 | 'passwords' => [ 99 | 'users' => [ 100 | 'provider' => 'users', 101 | 'email' => 'auth.emails.password', 102 | 'table' => 'password_resets', 103 | 'expire' => 60, 104 | ], 105 | ], 106 | 107 | ]; 108 | -------------------------------------------------------------------------------- /app/Option.php: -------------------------------------------------------------------------------- 1 | readOptionFromFileCache($name, $default) 45 | : $this->readOptionFromDatabase($name, $default); 46 | } 47 | 48 | $option = $this->whereOption($name); 49 | 50 | $updatedOrCreatedAnOption = (bool) $option->first() 51 | ? $option->update(['value' => $value]) 52 | : static::create(['option' => $name, 'value' => $value]); 53 | 54 | if ($updatedOrCreatedAnOption == true) { 55 | $this->recacheOptions(); 56 | } 57 | 58 | return $updatedOrCreatedAnOption; 59 | } 60 | 61 | /** 62 | * Read this option from database. 63 | * 64 | * @param $name 65 | * @param $default 66 | * @return mixed 67 | */ 68 | protected function readOptionFromDatabase($name, $default) 69 | { 70 | $this->recacheOptions(); 71 | 72 | $option = static::select('value')->whereOption($name)->first(); 73 | 74 | return $option ? $option->value : $default; 75 | } 76 | 77 | /** 78 | * Read the option from the file cache. 79 | * 80 | * @param $option 81 | * @param $default 82 | * @return mixed 83 | */ 84 | protected function readOptionFromFileCache($option, $default) 85 | { 86 | if ($options = Cache::get(static::CACHE_KEY)) { 87 | $optionValue = $options->where('option', $option)->first()->toArray(); 88 | 89 | return $optionValue ? array_get($optionValue, 'value', $default) : $default; 90 | } 91 | 92 | return $default; 93 | } 94 | 95 | /** 96 | * Get a value attribute. 97 | * 98 | * @param $value 99 | * @return mixed 100 | */ 101 | public function getValueAttribute($value) 102 | { 103 | return $this->isJsonString($value) ? json_decode($value, true) : $value; 104 | } 105 | 106 | /** 107 | * Set the value attribute. 108 | * 109 | * @param $value 110 | */ 111 | public function setValueAttribute($value) 112 | { 113 | if (is_array($value) OR is_object($value)) { 114 | $value = json_encode($value); 115 | } 116 | 117 | $this->attributes['value'] = $value; 118 | } 119 | 120 | /** 121 | * Checks to see if valid JSON string. 122 | * 123 | * @param $string 124 | * @return bool 125 | */ 126 | protected function isJsonString($string) 127 | { 128 | $string = json_decode($string); 129 | return json_last_error() === JSON_ERROR_NONE; 130 | } 131 | 132 | /** 133 | * Cache the options table. 134 | */ 135 | protected function recacheOptions() 136 | { 137 | if (static::USE_CACHE === true) { 138 | Cache::has(static::CACHE_KEY) AND Cache::forget(static::CACHE_KEY); 139 | Cache::put(static::CACHE_KEY, static::all(), static::CACHE_EXPIRY); 140 | } 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /resources/views/auth/register.blade.php: -------------------------------------------------------------------------------- 1 | @extends('layouts.app') 2 | 3 | @section('content') 4 |
5 |
6 |
7 |
8 |
Register
9 |
10 |
11 | {{ csrf_field() }} 12 | 13 |
14 | 15 | 16 |
17 | 18 | 19 | @if ($errors->has('name')) 20 | 21 | {{ $errors->first('name') }} 22 | 23 | @endif 24 |
25 |
26 | 27 |
28 | 29 | 30 |
31 | 32 | 33 | @if ($errors->has('email')) 34 | 35 | {{ $errors->first('email') }} 36 | 37 | @endif 38 |
39 |
40 | 41 |
42 | 43 | 44 |
45 | 46 | 47 | @if ($errors->has('password')) 48 | 49 | {{ $errors->first('password') }} 50 | 51 | @endif 52 |
53 |
54 | 55 |
56 | 57 | 58 |
59 | 60 | 61 | @if ($errors->has('password_confirmation')) 62 | 63 | {{ $errors->first('password_confirmation') }} 64 | 65 | @endif 66 |
67 |
68 | 69 |
70 |
71 | 74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | @endsection 83 | -------------------------------------------------------------------------------- /config/mail.php: -------------------------------------------------------------------------------- 1 | env('MAIL_DRIVER', 'smtp'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | SMTP Host Address 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may provide the host address of the SMTP server used by your 27 | | applications. A default option is provided that is compatible with 28 | | the Mailgun mail service which will provide reliable deliveries. 29 | | 30 | */ 31 | 32 | 'host' => env('MAIL_HOST', 'smtp.mailgun.org'), 33 | 34 | /* 35 | |-------------------------------------------------------------------------- 36 | | SMTP Host Port 37 | |-------------------------------------------------------------------------- 38 | | 39 | | This is the SMTP port used by your application to deliver e-mails to 40 | | users of the application. Like the host we have set this value to 41 | | stay compatible with the Mailgun e-mail application by default. 42 | | 43 | */ 44 | 45 | 'port' => env('MAIL_PORT', 587), 46 | 47 | /* 48 | |-------------------------------------------------------------------------- 49 | | Global "From" Address 50 | |-------------------------------------------------------------------------- 51 | | 52 | | You may wish for all e-mails sent by your application to be sent from 53 | | the same address. Here, you may specify a name and address that is 54 | | used globally for all e-mails that are sent by your application. 55 | | 56 | */ 57 | 58 | 'from' => ['address' => null, 'name' => null], 59 | 60 | /* 61 | |-------------------------------------------------------------------------- 62 | | E-Mail Encryption Protocol 63 | |-------------------------------------------------------------------------- 64 | | 65 | | Here you may specify the encryption protocol that should be used when 66 | | the application send e-mail messages. A sensible default using the 67 | | transport layer security protocol should provide great security. 68 | | 69 | */ 70 | 71 | 'encryption' => env('MAIL_ENCRYPTION', 'tls'), 72 | 73 | /* 74 | |-------------------------------------------------------------------------- 75 | | SMTP Server Username 76 | |-------------------------------------------------------------------------- 77 | | 78 | | If your SMTP server requires a username for authentication, you should 79 | | set it here. This will get used to authenticate with your server on 80 | | connection. You may also set the "password" value below this one. 81 | | 82 | */ 83 | 84 | 'username' => env('MAIL_USERNAME'), 85 | 86 | /* 87 | |-------------------------------------------------------------------------- 88 | | SMTP Server Password 89 | |-------------------------------------------------------------------------- 90 | | 91 | | Here you may set the password required by your SMTP server to send out 92 | | messages from your application. This will be given to the server on 93 | | connection so that the application will be able to send messages. 94 | | 95 | */ 96 | 97 | 'password' => env('MAIL_PASSWORD'), 98 | 99 | /* 100 | |-------------------------------------------------------------------------- 101 | | Sendmail System Path 102 | |-------------------------------------------------------------------------- 103 | | 104 | | When using the "sendmail" driver to send e-mails, we will need to know 105 | | the path to where Sendmail lives on this server. A default path has 106 | | been provided here, which will work well on most of your systems. 107 | | 108 | */ 109 | 110 | 'sendmail' => '/usr/sbin/sendmail -bs', 111 | 112 | ]; 113 | -------------------------------------------------------------------------------- /config/database.php: -------------------------------------------------------------------------------- 1 | PDO::FETCH_CLASS, 25 | 26 | /* 27 | |-------------------------------------------------------------------------- 28 | | Default Database Connection Name 29 | |-------------------------------------------------------------------------- 30 | | 31 | | Here you may specify which of the database connections below you wish 32 | | to use as your default connection for all database work. Of course 33 | | you may use many connections at once using the Database library. 34 | | 35 | */ 36 | 37 | 'default' => env('DB_CONNECTION', 'mysql'), 38 | 39 | /* 40 | |-------------------------------------------------------------------------- 41 | | Database Connections 42 | |-------------------------------------------------------------------------- 43 | | 44 | | Here are each of the database connections setup for your application. 45 | | Of course, examples of configuring each database platform that is 46 | | supported by Laravel is shown below to make development simple. 47 | | 48 | | 49 | | All database work in Laravel is done through the PHP PDO facilities 50 | | so make sure you have the driver for your particular database of 51 | | choice installed on your machine before you begin development. 52 | | 53 | */ 54 | 55 | 'connections' => [ 56 | 57 | 'sqlite' => [ 58 | 'driver' => 'sqlite', 59 | 'database' => env('DB_DATABASE', database_path('database.sqlite')), 60 | 'prefix' => env('DB_PREFIX', ''), 61 | ], 62 | 63 | 'mysql' => [ 64 | 'driver' => 'mysql', 65 | 'host' => env('DB_HOST', 'localhost'), 66 | 'port' => env('DB_PORT', '3306'), 67 | 'database' => env('DB_DATABASE', 'forge'), 68 | 'username' => env('DB_USERNAME', 'forge'), 69 | 'password' => env('DB_PASSWORD', ''), 70 | 'charset' => 'utf8', 71 | 'collation' => 'utf8_unicode_ci', 72 | 'prefix' => env('DB_PREFIX', ''), 73 | 'strict' => false, 74 | 'engine' => null, 75 | ], 76 | 77 | 'pgsql' => [ 78 | 'driver' => 'pgsql', 79 | 'host' => array_get($postgresUrl, 'host', env('DB_HOST', 'localhost')), 80 | 'port' => env('DB_PORT', '5432'), 81 | 'database' => $database, 82 | 'username' => array_get($postgresUrl, 'user', env('DB_USERNAME', 'forge')), 83 | 'password' => array_get($postgresUrl, 'pass', env('DB_PASSWORD', '')), 84 | 'charset' => 'utf8', 85 | 'prefix' => env('DB_PREFIX', ''), 86 | 'schema' => 'public', 87 | ], 88 | 89 | ], 90 | 91 | /* 92 | |-------------------------------------------------------------------------- 93 | | Migration Repository Table 94 | |-------------------------------------------------------------------------- 95 | | 96 | | This table keeps track of all the migrations that have already run for 97 | | your application. Using this information, we can determine which of 98 | | the migrations on disk haven't actually been run in the database. 99 | | 100 | */ 101 | 102 | 'migrations' => 'migrations', 103 | 104 | /* 105 | |-------------------------------------------------------------------------- 106 | | Redis Databases 107 | |-------------------------------------------------------------------------- 108 | | 109 | | Redis is an open source, fast, and advanced key-value store that also 110 | | provides a richer set of commands than a typical key-value systems 111 | | such as APC or Memcached. Laravel makes it easy to dig right in. 112 | | 113 | */ 114 | 115 | 'redis' => [ 116 | 117 | 'cluster' => false, 118 | 119 | 'default' => [ 120 | 'host' => env('REDIS_HOST', 'localhost'), 121 | 'password' => env('REDIS_PASSWORD', null), 122 | 'port' => env('REDIS_PORT', 6379), 123 | 'database' => 0, 124 | ], 125 | 126 | ], 127 | 128 | ]; 129 | -------------------------------------------------------------------------------- /resources/views/layouts/app.blade.php: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | @yield('title') 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 68 | 69 | @if ( (isset($inPageTitle) && $inPageTitle) || (isset($inPageSubTitle) && $inPageSubTitle) ) 70 |
71 |
72 |
73 | @if (isset($inPageTitle) && $inPageTitle)

{{ $inPageTitle }}

@endif 74 | @if (isset($inPageSubTitle) && $inPageSubTitle) {{ $inPageSubTitle }} @endif 75 |
76 |
77 |
78 | @endif 79 | 80 | @yield('content') 81 | 82 | 87 | 88 | 89 | 90 | 91 | 92 | @stack('scripts') 93 | 94 | 95 | -------------------------------------------------------------------------------- /app/Lunchbox.php: -------------------------------------------------------------------------------- 1 | 'boolean' 24 | ]; 25 | 26 | /** 27 | * @var array 28 | */ 29 | protected $with = ['orders']; 30 | 31 | /** 32 | * Create a new lunchbox with orders. 33 | * 34 | * @param Request $request 35 | * @return static 36 | */ 37 | public function createWithOrders(Request $request) 38 | { 39 | $lunchbox = static::create([ 40 | 'user_id' => $request->user()->id, 41 | 'buka_id' => $request->get('buka_id'), 42 | 'free_lunch' => $request->get('free_lunch'), 43 | ]); 44 | 45 | $orders = []; 46 | 47 | foreach ($request->get('orders') as $order) { 48 | for ($i = 0; $i < $order['servings']; $i++) { 49 | $lunch = Lunch::find($order['id']); 50 | 51 | // Create a new order 52 | $newOrder = (new Order)->createFromLunch($lunch); 53 | 54 | // Add note 55 | if ($additionalNote = array_get($order, 'note')) { 56 | $newOrder->note = $additionalNote; 57 | } 58 | 59 | // If the lunch does not have a fixed price, then enter the variable 60 | // price which would be used to calculate the final cost. 61 | if ($lunch->cost <= 0) { 62 | $newOrder->cost = $order['cost']; 63 | } 64 | 65 | $orders[] = $newOrder; 66 | } 67 | } 68 | 69 | $lunchbox->orders()->saveMany($orders); 70 | 71 | return $lunchbox; 72 | } 73 | 74 | /** 75 | * Get the total cost of the entire order. 76 | * 77 | * @return bool|float 78 | */ 79 | public function totalCost() 80 | { 81 | if ( ! $this->exists) { 82 | return false; 83 | } 84 | 85 | $totalCost = 0.00; 86 | 87 | $ordersGrouped = $this->ordersGrouped(); 88 | 89 | foreach ($ordersGrouped as $order) { 90 | $totalCost += (float) ($order->cost * $order->servings); 91 | } 92 | 93 | if ($this->buka->base_cost > 0) { 94 | $totalCost += (float) $this->buka->base_cost; 95 | } 96 | 97 | return $totalCost; 98 | } 99 | 100 | /** 101 | * Return the related buka. 102 | * 103 | * @return \Illuminate\Database\Eloquent\Relations\HasOne 104 | */ 105 | public function buka() 106 | { 107 | return $this->belongsTo(Buka::class, 'buka_id'); 108 | } 109 | 110 | /** 111 | * User relationship. 112 | * 113 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo 114 | */ 115 | public function user() 116 | { 117 | return $this->belongsTo(User::class, 'user_id'); 118 | } 119 | 120 | /** 121 | * Orders relationship. 122 | * 123 | * @return \Illuminate\Database\Eloquent\Relations\HasMany 124 | */ 125 | public function orders() 126 | { 127 | return $this->hasMany(Order::class, 'lunchbox_id'); 128 | } 129 | 130 | /** 131 | * Orders relationship. 132 | * 133 | * @return \Illuminate\Support\Collection 134 | */ 135 | public function ordersGrouped() 136 | { 137 | return $this->orders() 138 | ->selectRaw('*,count(*) as servings') 139 | ->groupBy('lunch_id') 140 | ->get(); 141 | } 142 | 143 | /** 144 | * Get orders between a certain time period. 145 | * 146 | * @param $query 147 | * @param string|Int|Carbon $startDate 148 | * @param string|Int|Carbon $endDate 149 | * @return mixed 150 | */ 151 | public function scopeOrdersBetween($query, $startDate, $endDate) 152 | { 153 | $endDate = $this->carbonInstanceFromDate($endDate, Carbon::now()); 154 | $startDate = $this->carbonInstanceFromDate($startDate, Carbon::now()->startOfMonth()); 155 | 156 | return $query->where('created_at', '>=', $startDate)->where('created_at', '<=', $endDate); 157 | } 158 | 159 | /** 160 | * Get orders since a certain date. 161 | * 162 | * @param $query 163 | * @param $since 164 | * @return mixed 165 | */ 166 | public function scopeOrdersSince($query, $since) 167 | { 168 | return $query->ordersBetween($since, Carbon::now()); 169 | } 170 | 171 | /** 172 | * Get carbon instance from date. 173 | * 174 | * @param $date 175 | * @param Carbon $default 176 | * @return array 177 | */ 178 | protected function carbonInstanceFromDate($date, Carbon $default) 179 | { 180 | if ( ! $date instanceof Carbon) { 181 | $timestamp = strtotime($date); 182 | 183 | if ( ! $timestamp OR ! $date = Carbon::createFromTimestamp($timestamp)) { 184 | $date = $default; 185 | } 186 | } 187 | 188 | return $date; 189 | } 190 | } -------------------------------------------------------------------------------- /app/Http/Controllers/Auth/AuthController.php: -------------------------------------------------------------------------------- 1 | middleware('guest')->except('logout'); 20 | 21 | parent::__construct(); 22 | } 23 | 24 | /** 25 | * Redirect the user to the Slack authentication page. 26 | * 27 | * @return Response 28 | */ 29 | public function redirectToProvider() 30 | { 31 | return Socialite::driver('slack')->redirect(); 32 | } 33 | 34 | /** 35 | * Obtain the user information from Slack. 36 | * 37 | * @return Response 38 | */ 39 | public function handleProviderCallback() 40 | { 41 | try { 42 | $user = Socialite::driver('slack')->user(); 43 | 44 | if (array_get($user->user, 'team.domain') !== option('slack_credentials.domain')) { 45 | throw new Exception("Invalid slack team."); 46 | } 47 | } catch (Exception $e) { 48 | return redirect()->home(); 49 | } 50 | 51 | $authUser = $this->findOrCreateUser($user); 52 | 53 | auth()->login($authUser, true); 54 | 55 | if (strpos(auth()->user()->slack_scopes, 'users:read') === false) { 56 | $authUrl = 'https://slack.com/oauth/authorize?scope=users:read&'. 57 | 'client_id='.option('SLACK_CREDENTIALS.client_id').'&'. 58 | 'state='.$authUser->id.'&'. 59 | 'redirect_uri='.urlencode(route('auth.slack.callback.user')); 60 | 61 | header('Location: '.$authUrl); 62 | return; 63 | } 64 | 65 | return redirect()->home(); 66 | } 67 | 68 | /** 69 | * Handle the callback when the users:* scope is being requested. 70 | * 71 | * @return Response 72 | */ 73 | public function handleProviderCallbackUser() 74 | { 75 | // Required Validators! 76 | ($code = request()->get('code')) OR abort(403); 77 | ($state = request()->get('state')) OR abort(403); 78 | ($user = User::find($state)) OR abort(403); 79 | 80 | // Get the access token... 81 | $response = (new Client)->request('GET', 'https://slack.com/api/oauth.access', [ 82 | 'query' => [ 83 | 'code' => $code, 84 | 'client_id' => option('SLACK_CREDENTIALS.client_id'), 85 | 'client_secret' => option('SLACK_CREDENTIALS.client_secret'), 86 | 'redirect_uri' => route('auth.slack.callback.user') 87 | ] 88 | ])->getBody()->getContents(); 89 | 90 | $response = json_decode($response); 91 | 92 | if ($response->ok == true) { 93 | $userInfo = $this->getUserInfoFromSlack($response->user_id, $response->access_token); 94 | 95 | // Update the user object based on these details... 96 | $user->slack_scopes = $response->scope; 97 | $user->name = $userInfo->user->profile->real_name_normalized; 98 | $user->username = $userInfo->user->name; 99 | $user->save(); 100 | 101 | auth()->login($user, true); 102 | } 103 | 104 | // Something probably went wrong somewhere... 105 | return redirect()->home(); 106 | } 107 | 108 | /** 109 | * Log user Out. 110 | * 111 | * @return \Illuminate\Http\RedirectResponse 112 | */ 113 | public function logout() 114 | { 115 | auth()->logout(); 116 | 117 | session()->forget('administrator'); 118 | 119 | return redirect()->route('guest.home'); 120 | } 121 | 122 | /** 123 | * Return user if exists; create and return if doesn't 124 | * 125 | * @param $user 126 | * @return User 127 | */ 128 | private function findOrCreateUser($user) 129 | { 130 | if ($authUser = User::where('slack_id', $user->id)->first()) { 131 | // Update the user stuff from slack... 132 | $authUser->name = $user->name; 133 | $authUser->avatar = $user->avatar; 134 | $authUser->save(); 135 | 136 | return $authUser; 137 | } 138 | 139 | $createdUser = User::create([ 140 | 'slack_id' => $user->id, 141 | 'name' => $user->name, 142 | 'email' => $user->email, 143 | 'avatar' => $user->avatar, 144 | ]); 145 | 146 | event(new UserWasCreated($createdUser)); 147 | 148 | return $createdUser; 149 | } 150 | 151 | /** 152 | * @param $slackUserId 153 | * @param $accessToken 154 | * @return mixed 155 | */ 156 | protected function getUserInfoFromSlack($slackUserId, $accessToken) 157 | { 158 | // Get user details from the request... 159 | $userInfo = (new Client)->request('GET', 'https://slack.com/api/users.info', [ 160 | 'query' => [ 161 | 'user' => $slackUserId, 162 | 'token' => $accessToken, 163 | ] 164 | ])->getBody()->getContents(); 165 | 166 | return json_decode($userInfo); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /config/session.php: -------------------------------------------------------------------------------- 1 | env('SESSION_DRIVER', 'file'), 20 | 21 | /* 22 | |-------------------------------------------------------------------------- 23 | | Session Lifetime 24 | |-------------------------------------------------------------------------- 25 | | 26 | | Here you may specify the number of minutes that you wish the session 27 | | to be allowed to remain idle before it expires. If you want them 28 | | to immediately expire on the browser closing, set that option. 29 | | 30 | */ 31 | 32 | 'lifetime' => 120, 33 | 34 | 'expire_on_close' => false, 35 | 36 | /* 37 | |-------------------------------------------------------------------------- 38 | | Session Encryption 39 | |-------------------------------------------------------------------------- 40 | | 41 | | This option allows you to easily specify that all of your session data 42 | | should be encrypted before it is stored. All encryption will be run 43 | | automatically by Laravel and you can use the Session like normal. 44 | | 45 | */ 46 | 47 | 'encrypt' => false, 48 | 49 | /* 50 | |-------------------------------------------------------------------------- 51 | | Session File Location 52 | |-------------------------------------------------------------------------- 53 | | 54 | | When using the native session driver, we need a location where session 55 | | files may be stored. A default has been set for you but a different 56 | | location may be specified. This is only needed for file sessions. 57 | | 58 | */ 59 | 60 | 'files' => storage_path('framework/sessions'), 61 | 62 | /* 63 | |-------------------------------------------------------------------------- 64 | | Session Database Connection 65 | |-------------------------------------------------------------------------- 66 | | 67 | | When using the "database" or "redis" session drivers, you may specify a 68 | | connection that should be used to manage these sessions. This should 69 | | correspond to a connection in your database configuration options. 70 | | 71 | */ 72 | 73 | 'connection' => null, 74 | 75 | /* 76 | |-------------------------------------------------------------------------- 77 | | Session Database Table 78 | |-------------------------------------------------------------------------- 79 | | 80 | | When using the "database" session driver, you may specify the table we 81 | | should use to manage the sessions. Of course, a sensible default is 82 | | provided for you; however, you are free to change this as needed. 83 | | 84 | */ 85 | 86 | 'table' => 'sessions', 87 | 88 | /* 89 | |-------------------------------------------------------------------------- 90 | | Session Sweeping Lottery 91 | |-------------------------------------------------------------------------- 92 | | 93 | | Some session drivers must manually sweep their storage location to get 94 | | rid of old sessions from storage. Here are the chances that it will 95 | | happen on a given request. By default, the odds are 2 out of 100. 96 | | 97 | */ 98 | 99 | 'lottery' => [2, 100], 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Session Cookie Name 104 | |-------------------------------------------------------------------------- 105 | | 106 | | Here you may change the name of the cookie used to identify a session 107 | | instance by ID. The name specified here will get used every time a 108 | | new session cookie is created by the framework for every driver. 109 | | 110 | */ 111 | 112 | 'cookie' => 'laravel_session', 113 | 114 | /* 115 | |-------------------------------------------------------------------------- 116 | | Session Cookie Path 117 | |-------------------------------------------------------------------------- 118 | | 119 | | The session cookie path determines the path for which the cookie will 120 | | be regarded as available. Typically, this will be the root path of 121 | | your application but you are free to change this when necessary. 122 | | 123 | */ 124 | 125 | 'path' => '/', 126 | 127 | /* 128 | |-------------------------------------------------------------------------- 129 | | Session Cookie Domain 130 | |-------------------------------------------------------------------------- 131 | | 132 | | Here you may change the domain of the cookie used to identify a session 133 | | in your application. This will determine which domains the cookie is 134 | | available to in your application. A sensible default has been set. 135 | | 136 | */ 137 | 138 | 'domain' => null, 139 | 140 | /* 141 | |-------------------------------------------------------------------------- 142 | | HTTPS Only Cookies 143 | |-------------------------------------------------------------------------- 144 | | 145 | | By setting this option to true, session cookies will only be sent back 146 | | to the server if the browser has a HTTPS connection. This will keep 147 | | the cookie from being sent to you if it can not be done securely. 148 | | 149 | */ 150 | 151 | 'secure' => false, 152 | 153 | /* 154 | |-------------------------------------------------------------------------- 155 | | HTTP Access Only 156 | |-------------------------------------------------------------------------- 157 | | 158 | | Setting this value to true will prevent JavaScript from accessing the 159 | | value of the cookie and the cookie will only be accessible through 160 | | the HTTP protocol. You are free to modify this option if needed. 161 | | 162 | */ 163 | 164 | 'http_only' => true, 165 | 166 | ]; 167 | -------------------------------------------------------------------------------- /resources/lang/en/validation.php: -------------------------------------------------------------------------------- 1 | 'The :attribute must be accepted.', 17 | 'active_url' => 'The :attribute is not a valid URL.', 18 | 'after' => 'The :attribute must be a date after :date.', 19 | 'alpha' => 'The :attribute may only contain letters.', 20 | 'alpha_dash' => 'The :attribute may only contain letters, numbers, and dashes.', 21 | 'alpha_num' => 'The :attribute may only contain letters and numbers.', 22 | 'array' => 'The :attribute must be an array.', 23 | 'before' => 'The :attribute must be a date before :date.', 24 | 'between' => [ 25 | 'numeric' => 'The :attribute must be between :min and :max.', 26 | 'file' => 'The :attribute must be between :min and :max kilobytes.', 27 | 'string' => 'The :attribute must be between :min and :max characters.', 28 | 'array' => 'The :attribute must have between :min and :max items.', 29 | ], 30 | 'boolean' => 'The :attribute field must be true or false.', 31 | 'confirmed' => 'The :attribute confirmation does not match.', 32 | 'date' => 'The :attribute is not a valid date.', 33 | 'date_format' => 'The :attribute does not match the format :format.', 34 | 'different' => 'The :attribute and :other must be different.', 35 | 'digits' => 'The :attribute must be :digits digits.', 36 | 'digits_between' => 'The :attribute must be between :min and :max digits.', 37 | 'dimensions' => 'The :attribute has invalid image dimensions.', 38 | 'distinct' => 'The :attribute field has a duplicate value.', 39 | 'email' => 'The :attribute must be a valid email address.', 40 | 'exists' => 'The selected :attribute is invalid.', 41 | 'filled' => 'The :attribute field is required.', 42 | 'image' => 'The :attribute must be an image.', 43 | 'in' => 'The selected :attribute is invalid.', 44 | 'in_array' => 'The :attribute field does not exist in :other.', 45 | 'integer' => 'The :attribute must be an integer.', 46 | 'ip' => 'The :attribute must be a valid IP address.', 47 | 'json' => 'The :attribute must be a valid JSON string.', 48 | 'max' => [ 49 | 'numeric' => 'The :attribute may not be greater than :max.', 50 | 'file' => 'The :attribute may not be greater than :max kilobytes.', 51 | 'string' => 'The :attribute may not be greater than :max characters.', 52 | 'array' => 'The :attribute may not have more than :max items.', 53 | ], 54 | 'mimes' => 'The :attribute must be a file of type: :values.', 55 | 'min' => [ 56 | 'numeric' => 'The :attribute must be at least :min.', 57 | 'file' => 'The :attribute must be at least :min kilobytes.', 58 | 'string' => 'The :attribute must be at least :min characters.', 59 | 'array' => 'The :attribute must have at least :min items.', 60 | ], 61 | 'not_in' => 'The selected :attribute is invalid.', 62 | 'numeric' => 'The :attribute must be a number.', 63 | 'present' => 'The :attribute field must be present.', 64 | 'regex' => 'The :attribute format is invalid.', 65 | 'required' => 'The :attribute field is required.', 66 | 'required_if' => 'The :attribute field is required when :other is :value.', 67 | 'required_unless' => 'The :attribute field is required unless :other is in :values.', 68 | 'required_with' => 'The :attribute field is required when :values is present.', 69 | 'required_with_all' => 'The :attribute field is required when :values is present.', 70 | 'required_without' => 'The :attribute field is required when :values is not present.', 71 | 'required_without_all' => 'The :attribute field is required when none of :values are present.', 72 | 'same' => 'The :attribute and :other must match.', 73 | 'size' => [ 74 | 'numeric' => 'The :attribute must be :size.', 75 | 'file' => 'The :attribute must be :size kilobytes.', 76 | 'string' => 'The :attribute must be :size characters.', 77 | 'array' => 'The :attribute must contain :size items.', 78 | ], 79 | 'string' => 'The :attribute must be a string.', 80 | 'timezone' => 'The :attribute must be a valid zone.', 81 | 'unique' => 'The :attribute has already been taken.', 82 | 'url' => 'The :attribute format is invalid.', 83 | 84 | /* 85 | |-------------------------------------------------------------------------- 86 | | Custom Validation Language Lines 87 | |-------------------------------------------------------------------------- 88 | | 89 | | Here you may specify custom validation messages for attributes using the 90 | | convention "attribute.rule" to name the lines. This makes it quick to 91 | | specify a specific custom language line for a given attribute rule. 92 | | 93 | */ 94 | 95 | 'custom' => [ 96 | 'attribute-name' => [ 97 | 'rule-name' => 'custom-message', 98 | ], 99 | ], 100 | 101 | /* 102 | |-------------------------------------------------------------------------- 103 | | Custom Validation Attributes 104 | |-------------------------------------------------------------------------- 105 | | 106 | | The following language lines are used to swap attribute place-holders 107 | | with something more reader friendly such as E-Mail Address instead 108 | | of "email". This simply helps us make messages a little cleaner. 109 | | 110 | */ 111 | 112 | 'attributes' => [], 113 | 114 | ]; 115 | --------------------------------------------------------------------------------