From af7abda07af4e9fed4b6081a72bbef5efefda63b Mon Sep 17 00:00:00 2001 From: Jane Adelmann Date: Fri, 26 Apr 2019 15:14:20 +0300 Subject: [PATCH] Fix saving agreement for group user. --- classes/plagiarism_pchkorg_api_provider.php | 11 +++++++++-- lib.php | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/classes/plagiarism_pchkorg_api_provider.php b/classes/plagiarism_pchkorg_api_provider.php index c4522b5..c302271 100644 --- a/classes/plagiarism_pchkorg_api_provider.php +++ b/classes/plagiarism_pchkorg_api_provider.php @@ -224,8 +224,15 @@ class plagiarism_pchkorg_api_provider { * Method send information to service thar agreement had been accepted. * Method will be called only for personal account type. * + * @param string $email User email + * @return void */ - public function save_accepted_agreement() { + public function save_accepted_agreement($email) { + $token = $this->token; + if ($this->is_group_token()) { + $token = $this->token . '::' . hash('sha256', $this->token . $email); + } + $curl = new curl(); $curl->post( $this->endpoint . '/api/v1/agreement/create/moodle-plugin/2019-04-11/', @@ -237,7 +244,7 @@ class plagiarism_pchkorg_api_provider { 'CURLOPT_SSL_VERIFYPEER' => false, 'CURLOPT_POST' => true, 'CURLOPT_HTTPHEADER' => array( - 'X-API-TOKEN: ' . $this->generate_api_token(), + 'X-API-TOKEN: ' . $token, ), ) ); diff --git a/lib.php b/lib.php index 1687b75..e1f7fff 100644 --- a/lib.php +++ b/lib.php @@ -594,7 +594,7 @@ display: inline-block;" ); $agreementaccepted = $DB->get_records('plagiarism_pchkorg_config', $agreementwhere); if (empty($agreementaccepted)) { - $apiprovider->save_accepted_agreement(); + $apiprovider->save_accepted_agreement($user->email); $DB->insert_record('plagiarism_pchkorg_config', $agreementwhere); }