Closed lalyn closed 8 years ago
Hi @lalyn, there's a couple issues with the code you've posted.
First of all, delete your LdapAttributeHandler
. It's not needed here (nor is it used anywhere).
Next, in your config/adldap_auth.php
file, inside the sync_attributes
array, use the following array:
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
'employeeid' => 'samaccountname',
],
Now, upon logging in, you should now be able to access your users synchronized samaccountname
attribute:
// resources/views/welcome.blade.php
{{ Auth::user()->employeeid }}
Hi thanks alot for the reply. It was quite helpful. But the error I'm getting now is, the Employee id column in Users table is fetching 'username' not the 'employeeid' itself. Just curious to ask, do I need to create any new migration to fetch this employeeid from AD. Here I have the screenshot for u.
And Im sorry to ask can u kindly teach me where do I insert this code : // resources/views/welcome.blade.php
{{ Auth::user()->employeeid }}
My main idea is to tie employee id from adldap2 with the fingerprint database's employee id so that employees will be able to view their own attendance based on employee id (unique key)
Oh, if you want the employee ID from Active Directory, just use the configuration:
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
'employeeid' => 'employeeid',
],
Wow, it works now! Thank you so much, I was struggling with this for almost two days. Thank you really appreciate your help!
Hi if you dont mind could u please guide me on the query to tie employee id from adldap2 with my fingerprint system's database employee id. Here is my code :
class AttendanceController extends Controller
{
/**
* Show a list of all of the articles in the database.
* @return Response
*/
public function index()
{
return view('backend.attendance.index');
}
public function viewOwnAttendance()
{
if (access()->hasPermission('view-own-attendance'))
{
return view('backend.attendance.viewownattendance');
}
}
public function getOwn(Request $request)
{
if (access()->hasPermission('view-own-attendance'))
{
$attendance = DB::connection('mysql2')
->table('user_info')
->leftjoin('attendance','user_info.userid','=','attendance.userid')
->select(DB::raw("user_info.userid,user_info.username, attendance.date, attendance.att_in, attendance.att_out"))
->where('attendance.date', '>=', DB::raw("(DATE_FORMAT(user_info.lastupdate,'%Y-%m-%d'))"))
->where('user_info.username', '=', Auth::user()->name);
return Datatables::of($attendance)
->filter(function ($query) use ($request) {
if($request->has('start_date')) {
$query->where('attendance.date', '>=', "{$request->get('start_date')}");
}
if($request->has('end_date')) {
$query->where('attendance.date', '<=', "{$request->get('end_date')}");
}
})
->make(true);
}
}
Hi @lalyn, just curious, why aren't you using laravel models for retreiving user info? You're already using one for authentication.
But to answer your question, the employeeid
is synchronized on your users
database table, so you could retrieve the current users employeeid
using:
Auth::user()->employeeid
Hi there, could anyone assist me on how to sync employee id attribute in adldap2. I have followed the documentation but my phpmyadmin is not fetching the employee id from AD. I have made changes in ldap_auth.php , ldapattributehandler.php and create_users_table.php migration file. The code is as below :
3.Adldap_auth.php
Can anyone help me please since im very new to laravel. I am developing an attendance system for my company.