Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle user as staff #3

Merged
merged 2 commits into from
Mar 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,18 @@ Fungsi `getUser()` akan mengembalikan sebuah object `stdClass` PHP yang memiliki
$user = SSO\SSO::getUser();
echo $user->username; // prints user's username
echo $user->name; // prints user's name
echo $user->npm; // prints user's npm
echo $user->role; // prints user's role

/* jika role sebagai mahasiswa */
echo $user->npm; // prints user's npm
echo $user->org_code; // prints user's organization code
echo $user->faculty; // prints user's faculty
echo $user->study_program; // prints user's study program
echo $user->educational_program; // prints user's educational program

/* jika role sebagai staff */
echo $user->nip; // prints user's nip

### 3. Memeriksa otentikasi

SSO\SSO::check();
Expand Down
18 changes: 12 additions & 6 deletions SSO/SSO.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,20 @@ public static function getUser() {
$user = new \stdClass();
$user->username = phpCAS::getUser();
$user->name = $details['nama'];
$user->npm = $details['npm'];
$user->role = $details['peran_user'];
$user->org_code = $details['kd_org'];

$data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code];
$user->faculty = $data['faculty'];
$user->study_program = $data['study_program'];
$user->educational_program = $data['educational_program'];
if ($user->role === 'mahasiswa') {
$user->npm = $details['npm'];
$user->org_code = $details['kd_org'];

$data = json_decode(file_get_contents( __DIR__ . '/additional-info.json'), true)[$user->org_code];
$user->faculty = $data['faculty'];
$user->study_program = $data['study_program'];
$user->educational_program = $data['educational_program'];
}
else if ($user->role === 'staff') {
$user->nip = $details['nip'];
}

return $user;
}
Expand Down
6 changes: 5 additions & 1 deletion example-manual.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
// At this point, the authentication has succeeded.
// This shows how to get the user details.
$user = SSO\SSO::getUser();
echo $user->name . ' ' . $user->npm . ' ' . $user->role . ' ' . $user->faculty . ' ' . $user->study_program . ' ' . $user->educational_program;

if ($user->role === 'mahasiswa')
echo $user->username . ' ' . $user->name . ' ' . $user->npm . ' ' . $user->role . ' ' . $user->faculty . ' ' . $user->study_program . ' ' . $user->educational_program;
else if ($user->role === 'staff')
echo $user->username . ' ' . $user->name . ' ' . $user->nip . ' ' . $user->role;
6 changes: 5 additions & 1 deletion example.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@
// At this point, the authentication has succeeded.
// This shows how to get the user details.
$user = SSO\SSO::getUser();
echo $user->name . ' ' . $user->npm . ' ' . $user->role . ' ' . $user->org_code . ' ' . $user->faculty . ' ' . $user->study_program . ' ' . $user->educational_program;

if ($user->role === 'mahasiswa')
echo $user->username . ' ' . $user->name . ' ' . $user->npm . ' ' . $user->role . ' ' . $user->faculty . ' ' . $user->study_program . ' ' . $user->educational_program;
else if ($user->role === 'staff')
echo $user->username . ' ' . $user->name . ' ' . $user->nip . ' ' . $user->role;