Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 65bcff5

Browse files
author
Aaron Kuzemchak
committed
Initial commit
0 parents  commit 65bcff5

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

config/users.php

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
return array(
4+
array(
5+
'id' => 1,
6+
'username' => 'admin',
7+
'password' => Hash::make('admin'),
8+
),
9+
array(
10+
'id' => 2,
11+
'username' => 'demo',
12+
'password' => Hash::make('demo'),
13+
),
14+
);

libraries/fileauth.php

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
class FileAuth extends Laravel\Auth\Drivers\Driver {
4+
5+
/**
6+
* Get the a given application user by ID
7+
*
8+
* @param int $id
9+
* @return mixed
10+
*/
11+
public function retrieve($id)
12+
{
13+
if(filter_var($id, FILTER_VALIDATE_INT) !== false)
14+
{
15+
$users = Config::get('fileauth::users');
16+
17+
// get the first matching user from the list
18+
$user = array_first($users, function($k, $v) use($id)
19+
{
20+
return $v['id'] == $id;
21+
});
22+
23+
if($user)
24+
{
25+
return (object) $user;
26+
}
27+
}
28+
}
29+
30+
/**
31+
* Attempt to log a user into the application
32+
*
33+
* @param array $arguments
34+
* @return bool
35+
*/
36+
public function attempt($arguments = array())
37+
{
38+
$users = Config::get("fileauth::users");
39+
$key = Config::get('auth.username');
40+
41+
// get the first matching user from the list
42+
$user = array_first($users, function($k, $v) use($arguments, $key)
43+
{
44+
if(array_key_exists($key, $v) && $arguments[$key] == $v[$key] && Hash::check($arguments['password'], $v['password']))
45+
{
46+
return true;
47+
}
48+
49+
return false;
50+
});
51+
52+
if($user)
53+
{
54+
// log the user in
55+
return $this->login($user['id'], array_get($arguments, 'remember'));
56+
}
57+
58+
return false;
59+
}
60+
61+
}

start.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
// map class name to file
4+
Autoloader::map(array(
5+
'FileAuth' => __DIR__.'/libraries/fileauth.php',
6+
));
7+
8+
// register the auth driver
9+
Auth::extend('file', function()
10+
{
11+
return new FileAuth();
12+
});

0 commit comments

Comments
 (0)