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 |
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 |
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 |
--------------------------------------------------------------------------------