diff --git a/src/Provider/Tpedu.php b/src/Provider/Tpedu.php new file mode 100644 index 000000000..e33b96463 --- /dev/null +++ b/src/Provider/Tpedu.php @@ -0,0 +1,105 @@ +isRefreshTokenAvailable()) { + $this->tokenRefreshParameters += [ + 'client_id' => $this->clientId, + 'client_secret' => $this->clientSecret + ]; + } + } + + /** + * {@inheritdoc} + */ + public function getUserProfile() + { + $response = $this->apiRequest('profile'); + + $data = new Data\Collection($response); + + if (!$data->exists('role')) { + throw new UnexpectedApiResponseException('Provider API returned an unexpected response.'); + } elseif ($data->get('role') == '家長') { + throw new UnexpectedApiResponseException('Parents can not login!'); + } + + $userProfile = new User\Profile(); + + if ($data->get('role') == '學生') { + $userProfile->identifier = $data->get('studentId'); + $userProfile->data['groups'] = ['學生', $data->get('class')]; + } else { + $userProfile->identifier = $data->get('teacherId'); + $userProfile->data['groups'] = $data->get('unit'); + $userProfile->data['groups'][] = '教師'; + } + $userProfile->displayName = $data->get('name'); + $userProfile->gender = $data->get('gender'); + $userProfile->language = 'zh_TW'; + $userProfile->phone = $data->get('mobile'); + $userProfile->email = $data->get('email'); + $userProfile->emailVerified = $data->get('email_verified') ? $userProfile->email : ''; + + return $userProfile; + } + +}