Fix saving agreement for group user.

This commit is contained in:
Jane Adelmann 2019-04-26 15:14:20 +03:00
parent 7951fd129c
commit af7abda07a
No known key found for this signature in database
GPG Key ID: 4CCF39DF30B8AF72
2 changed files with 10 additions and 3 deletions

View File

@ -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,
),
)
);

View File

@ -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);
}