Exemplo n.º 1
0
 public function keyApplyAction(Request $request)
 {
     $applier = new KeyApplier();
     $keys = $applier->applyKey($this->getCurrentUser());
     if (empty($keys['accessKey']) || empty($keys['secretKey'])) {
         return $this->createJsonResponse(array('error' => 'Key生成失败,请检查服务器网络后,重试!'));
     }
     $settings = $this->getSettingService()->get('storage', array());
     $settings['cloud_access_key'] = $keys['accessKey'];
     $settings['cloud_secret_key'] = $keys['secretKey'];
     $settings['cloud_key_applied'] = 1;
     $this->getSettingService()->set('storage', $settings);
     return $this->createJsonResponse(array('status' => 'ok'));
 }
Exemplo n.º 2
0
 public function initKey()
 {
     $settings = $this->getSettingService()->get('storage', array());
     if (!empty($settings['cloud_key_applied'])) {
         return array('accessKey' => '您的Key已生成,请直接进入系统', 'secretKey' => '---');
     }
     $applier = new KeyApplier();
     $users = $this->getUserService()->searchUsers(array('roles' => 'ROLE_SUPER_ADMIN'), array('createdTime', 'DESC'), 0, 1);
     if (empty($users) or empty($users[0])) {
         return array('error' => '管理员账号不存在,创建Key失败');
     }
     $keys = $applier->applyKey($users[0], 'opensource', 'install');
     if (empty($keys['accessKey']) or empty($keys['secretKey'])) {
         return array('error' => 'Key生成失败,请检查服务器网络后,重试!');
     }
     $settings['cloud_access_key'] = $keys['accessKey'];
     $settings['cloud_secret_key'] = $keys['secretKey'];
     $settings['cloud_key_applied'] = 1;
     $this->getSettingService()->set('storage', $settings);
     return $keys;
 }