Skip to content

Commit e94e38a

Browse files
author
siddharajsinh.zala
committed
Laravel 5.2 Multi Auth - Beta
1 parent 8fc1e4f commit e94e38a

File tree

98 files changed

+6790
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+6790
-0
lines changed

.env.example

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
APP_ENV=local
2+
APP_DEBUG=true
3+
APP_KEY=SomeRandomString
4+
APP_URL=http://localhost
5+
6+
DB_CONNECTION=mysql
7+
DB_HOST=127.0.0.1
8+
DB_PORT=3306
9+
DB_DATABASE=homestead
10+
DB_USERNAME=homestead
11+
DB_PASSWORD=secret
12+
13+
CACHE_DRIVER=file
14+
SESSION_DRIVER=file
15+
QUEUE_DRIVER=sync
16+
17+
REDIS_HOST=127.0.0.1
18+
REDIS_PASSWORD=null
19+
REDIS_PORT=6379
20+
21+
MAIL_DRIVER=smtp
22+
MAIL_HOST=mailtrap.io
23+
MAIL_PORT=2525
24+
MAIL_USERNAME=null
25+
MAIL_PASSWORD=null
26+
MAIL_ENCRYPTION=null

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto
2+
*.css linguist-vendored
3+
*.scss linguist-vendored

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/vendor
2+
/node_modules
3+
/public/storage
4+
Homestead.yaml
5+
Homestead.json
6+
.env

.htaccess

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<IfModule mod_rewrite.c>
2+
<IfModule mod_negotiation.c>
3+
Options -MultiViews
4+
</IfModule>
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+
</IfModule>

app/Admin.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Foundation\Auth\User as Authenticatable;
6+
7+
class Admin extends Authenticatable
8+
{
9+
protected $table = 'admin';
10+
/**
11+
* The attributes that are mass assignable.
12+
*
13+
* @var array
14+
*/
15+
protected $fillable = [
16+
'name', 'email', 'password',
17+
];
18+
19+
/**
20+
* The attributes that should be hidden for arrays.
21+
*
22+
* @var array
23+
*/
24+
protected $hidden = [
25+
'password', 'remember_token',
26+
];
27+
}

app/Console/Commands/Inspire.php

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\Command;
6+
use Illuminate\Foundation\Inspiring;
7+
8+
class Inspire extends Command
9+
{
10+
/**
11+
* The name and signature of the console command.
12+
*
13+
* @var string
14+
*/
15+
protected $signature = 'inspire';
16+
17+
/**
18+
* The console command description.
19+
*
20+
* @var string
21+
*/
22+
protected $description = 'Display an inspiring quote';
23+
24+
/**
25+
* Execute the console command.
26+
*
27+
* @return mixed
28+
*/
29+
public function handle()
30+
{
31+
$this->comment(PHP_EOL.Inspiring::quote().PHP_EOL);
32+
}
33+
}

app/Console/Kernel.php

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace App\Console;
4+
5+
use Illuminate\Console\Scheduling\Schedule;
6+
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
7+
8+
class Kernel extends ConsoleKernel
9+
{
10+
/**
11+
* The Artisan commands provided by your application.
12+
*
13+
* @var array
14+
*/
15+
protected $commands = [
16+
// Commands\Inspire::class,
17+
];
18+
19+
/**
20+
* Define the application's command schedule.
21+
*
22+
* @param \Illuminate\Console\Scheduling\Schedule $schedule
23+
* @return void
24+
*/
25+
protected function schedule(Schedule $schedule)
26+
{
27+
// $schedule->command('inspire')
28+
// ->hourly();
29+
}
30+
}

app/Events/Event.php

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace App\Events;
4+
5+
abstract class Event
6+
{
7+
//
8+
}

app/Exceptions/Handler.php

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace App\Exceptions;
4+
5+
use Exception;
6+
use Illuminate\Validation\ValidationException;
7+
use Illuminate\Auth\Access\AuthorizationException;
8+
use Illuminate\Database\Eloquent\ModelNotFoundException;
9+
use Symfony\Component\HttpKernel\Exception\HttpException;
10+
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
11+
12+
class Handler extends ExceptionHandler
13+
{
14+
/**
15+
* A list of the exception types that should not be reported.
16+
*
17+
* @var array
18+
*/
19+
protected $dontReport = [
20+
AuthorizationException::class,
21+
HttpException::class,
22+
ModelNotFoundException::class,
23+
ValidationException::class,
24+
];
25+
26+
/**
27+
* Report or log an exception.
28+
*
29+
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
30+
*
31+
* @param \Exception $e
32+
* @return void
33+
*/
34+
public function report(Exception $e)
35+
{
36+
parent::report($e);
37+
}
38+
39+
/**
40+
* Render an exception into an HTTP response.
41+
*
42+
* @param \Illuminate\Http\Request $request
43+
* @param \Exception $e
44+
* @return \Illuminate\Http\Response
45+
*/
46+
public function render($request, Exception $e)
47+
{
48+
return parent::render($request, $e);
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\AdminAuth;
4+
5+
use App\User;
6+
use Validator;
7+
use App\Http\Controllers\Controller;
8+
use Illuminate\Foundation\Auth\ThrottlesLogins;
9+
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
10+
use Illuminate\Http\Request;
11+
use Illuminate\Support\Facades\Auth;
12+
use App\Admin;
13+
class AuthController extends Controller
14+
{
15+
/*
16+
|--------------------------------------------------------------------------
17+
| Registration & Login Controller
18+
|--------------------------------------------------------------------------
19+
|
20+
| This controller handles the registration of new users, as well as the
21+
| authentication of existing users. By default, this controller uses
22+
| a simple trait to add these behaviors. Why don't you explore it?
23+
|
24+
*/
25+
26+
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
27+
28+
/**
29+
* Where to redirect users after login / registration.
30+
*
31+
* @var string
32+
*/
33+
protected $redirectTo = '/admin';
34+
protected $guard = 'admin';
35+
36+
public function showLoginForm()
37+
{
38+
if(view()->exists('auth.authenticate')) {
39+
return view('auth.authenticate');
40+
}
41+
return view('admin.auth.login');
42+
}
43+
public function showRegistrationForm()
44+
{
45+
return view('admin.auth.register');
46+
}
47+
/**
48+
* Create a new authentication controller instance.
49+
*
50+
* @return void
51+
*/
52+
public function __construct()
53+
{
54+
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
55+
}
56+
57+
/**
58+
* Get a validator for an incoming registration request.
59+
*
60+
* @param array $data
61+
* @return \Illuminate\Contracts\Validation\Validator
62+
*/
63+
protected function validator(array $data)
64+
{
65+
return Validator::make($data, [
66+
'name' => 'required|max:255',
67+
'email' => 'required|email|max:255|unique:users',
68+
'password' => 'required|min:6|confirmed',
69+
]);
70+
}
71+
72+
/**
73+
* Create a new user instance after a valid registration.
74+
*
75+
* @param array $data
76+
* @return User
77+
*/
78+
protected function create(array $data)
79+
{
80+
return Admin::create([
81+
'name' => $data['name'],
82+
'email' => $data['email'],
83+
'password' => bcrypt($data['password']),
84+
]);
85+
}
86+
87+
/**
88+
* Handle a registration request for the application.
89+
*
90+
* @param \Illuminate\Http\Request $request
91+
* @return \Illuminate\Http\Response
92+
*/
93+
public function postRegister(Request $request)
94+
{
95+
return $this->register($request);
96+
}
97+
98+
/**
99+
* Handle a registration request for the application.
100+
*
101+
* @param \Illuminate\Http\Request $request
102+
* @return \Illuminate\Http\Response
103+
*/
104+
public function register(Request $request)
105+
{
106+
$validator = $this->validator($request->all());
107+
108+
if ($validator->fails()) {
109+
$this->throwValidationException(
110+
$request, $validator
111+
);
112+
}
113+
114+
Auth::guard($this->getGuard())->login($this->create($request->all()));
115+
116+
return redirect($this->redirectPath());
117+
}
118+
119+
/**
120+
* Get the guard to be used during registration.
121+
*
122+
* @return string|null
123+
*/
124+
protected function getGuard()
125+
{
126+
return property_exists($this, 'guard') ? $this->guard : null;
127+
}
128+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\AdminAuth;
4+
5+
use App\Http\Controllers\Controller;
6+
use Illuminate\Foundation\Auth\ResetsPasswords;
7+
8+
class PasswordController extends Controller
9+
{
10+
/*
11+
|--------------------------------------------------------------------------
12+
| Password Reset Controller
13+
|--------------------------------------------------------------------------
14+
|
15+
| This controller is responsible for handling password reset requests
16+
| and uses a simple trait to include this behavior. You're free to
17+
| explore this trait and override any methods you wish to tweak.
18+
|
19+
*/
20+
21+
use ResetsPasswords;
22+
23+
/**
24+
* Create a new password controller instance.
25+
*
26+
* @return void
27+
*/
28+
public function __construct()
29+
{
30+
$this->middleware('guest');
31+
}
32+
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use App\Http\Requests;
8+
use App\Http\Controllers\Controller;
9+
use Illuminate\Support\Facades\Auth;
10+
11+
class AdminController extends Controller
12+
{
13+
public function __construct(){
14+
$this->middleware('admin');
15+
}
16+
public function index(){
17+
return view('admin.dashboard');
18+
}
19+
}

0 commit comments

Comments
 (0)