diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 0310f78c5c..e82e3a6089 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -81,7 +81,33 @@ class gitlab extends control { if($_POST) { + if($this->post->zentaoUsers) + { + $data = array(); + $number = 0; + foreach($this->post->zentaoUsers as $gitlabId => $account) + { + if($account) + { + $data[$number]['openID'] = $gitlabId; + $data[$number]['account'] = $account; + $data[$number]['providerType'] = 'gitlab'; + $data[$number]['providerID'] = $id; + $number++; + } + } + } + foreach($data as $bindUser) + { + if(!$this->gitlab->checkAccountId($bindUser['openID'],$bindUser['providerID'])) + { + $this->dao->insert(TABLE_OAUTH)->data($bindUser)->exec(); + }else + { + $this->dao->update(TABLE_OAUTH)->data($bindUser)->where('openID')->eq($bindUser['openID'])->andWhere('providerID')->eq($bindUser['providerID'])->exec(); + } + } } $gitlab = $this->gitlab->getByID($id); diff --git a/module/gitlab/model.php b/module/gitlab/model.php index 0e22c70fef..72d4cfcbae 100644 --- a/module/gitlab/model.php +++ b/module/gitlab/model.php @@ -97,7 +97,7 @@ class gitlabModel extends model { $api = rtrim($gitlab->url, '/') . '/api/v4/users?private_token=' . $gitlab->token; $response = json_decode(commonModel::http($api)); - + if (!$response) return array(); $users = array(); @@ -194,6 +194,19 @@ class gitlabModel extends model return $gitlab_url; } + + /** + * check if gitlab id exists + * + * @param string + * @access public + * @return array + */ + public function checkAccountId($openID,$providerID) + { + return $this->dao->select('openID')->from(TABLE_OAUTH)->where('openID')->eq($openID)->andWhere('providerID')->eq($providerID)->fetch('openID'); + } + /** * Get hooks. * diff --git a/module/gitlab/view/binduser.html.php b/module/gitlab/view/binduser.html.php index 9eb34410a2..380a0550c6 100644 --- a/module/gitlab/view/binduser.html.php +++ b/module/gitlab/view/binduser.html.php @@ -15,7 +15,7 @@