Exemple #1
0
 public function getServiceConfig()
 {
     return array('factories' => array('Account\\Model\\Account' => function ($sm) {
         $account = new Account();
         $account->setServiceLocator($sm);
         return $account;
     }));
 }
 public function addAction()
 {
     $form = new AccountForm();
     $form->get('submit')->setValue('Add');
     $element = new Element\Text('my-text');
     $element->setLabel('Please note your account #')->setLabelAttributes(array('class' => 'note-label'));
     $request = $this->getRequest();
     if ($request->isPost()) {
         $account = new Account();
         $form->setInputFilter($account->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $account->exchangeArray($form->getData());
             $account->movie_id_1 = '';
             $account->movie_id_2 = '';
             $account->movie_id_3 = '';
             $this->getAccountTable()->saveAccount($account);
             // Redirect to list of Accounts
             return $this->redirect()->toRoute('movie', array('id' => $account->id));
         }
     }
     return array('form' => $form, 'element' => $element);
 }
 public function setRolesAction()
 {
     if (!PermissionChecker::check(Role::CO)) {
         return $this->redirect()->toRoute('account', ['action' => 'noright']);
     }
     $form = new SearchUserForm();
     $request = $this->getRequest();
     $paginator = $this->getAccountTable()->getUsersAndAbove(true);
     $page = (int) $this->params()->fromQuery('page', 1);
     $name = $this->params()->fromQuery('name', '');
     $role = $this->params()->fromQuery('role', '');
     $account = new Account();
     $form->setInputFilter($account->getUserSearchInputFilter());
     $form->setData(['name' => $name, 'role' => $role]);
     if ($form->isValid()) {
         $account->exchangeArray($form->getData());
         $paginator = $this->getAccountTable()->getUsersAndAbove(true, $name, $role);
     }
     $role_strings = Role::getAllRoles();
     $paginator->setCurrentPageNumber($page);
     $paginator->setItemCountPerPage(25);
     return ['form' => $form, 'users' => $paginator, 'role_strings' => $role_strings];
 }
 /**
  * Creates a user session in the user namespace.
  * id, role, name, avatar and registered are accessable afterwards.
  * @param \Account\Model\Account $account
  */
 public static function createUserSession(Account $account)
 {
     $session = new Container('user');
     $session->id = $account->getId();
     $session->role = $account->getRole();
     $session->name = $account->getName();
     $session->avatar = $account->getAvatar();
     $session->registered = $account->getDateRegistered();
 }
 /**
  * Saves an account to the db. If the id exists the given dataset will be updated
  * @param \Account\Model\Account $account
  *
  * @throws \Exception
  */
 public function saveAccount(Account $account)
 {
     $data = ['name' => $account->getName(), 'password' => $account->getPassword(), 'userhash' => $account->getUserHash(), 'email' => $account->getEmail(), 'role' => $account->getRole(), 'avatar' => $account->getAvatar(), 'date_registered' => $account->getDateRegistered(), 'mini' => $account->getMini()];
     if (!$account->getId()) {
         $data['password'] = hash('sha256', $account->getPassword()) . Constants::SALT;
         $this->tableGateway->insert($data);
     } else {
         if ($this->getAccount($account->getId())) {
             $this->tableGateway->update($data, ['id' => $account->getId()]);
         } else {
             throw new \Exception('Account id does not exist');
         }
     }
 }
 private function sendAssignmentMail(Account $account, array $assignments, string $strategy)
 {
     $target_main = implode(',', array_keys($assignments, strtolower($account->getName())));
     $target_mini = implode(',', array_keys($assignments, strtolower($account->getMini())));
     $text = 'Hello ' . $account->getName() . ". Your targets are:\n";
     if ($target_main) {
         $text .= $account->getName() . ': ' . $target_main . "\n";
     }
     if ($target_mini) {
         $text .= $account->getMini() . ': ' . $target_mini . "\n";
     }
     $text .= 'War Strategy: ' . $strategy . "\n\n";
     $text .= 'Good Luck. Further information can be found under ' . $_SERVER['SERVER_NAME'] . '/warclaim/';
     $this->appMailService->sendMail($account->getEmail(), 'A new war has started!', $text);
 }
 /**
  * QQ/wx帐户取消扣减操作
  * @param data  通过HTTP RAW POST方式提交数据,数据字段定义如下:
  *      platform        Integer   (required)腾讯平台定义。定义如下:1.微信,2.QQ,3.WT。4.QQ大厅。5.游客模式
  *      os              Integer   (required)客户端操作系统定义。0: iOS, 1: Android
  *      open_id         String    (required)用户openID
  *      access_token    String    (required)用户访问接口的access_token
  *      pf              String    (required)腾讯pf定义
  *      pf_key          String    (required)腾讯pf_key定义
  *      zoneid          Integer   (required)腾讯zoneid定义
  *      pay_token       String    (required)腾讯pay_token定义
  *      amt             Integer   (required)取消扣减金额(可能为浮点型,根据实际情况定)
  *      billno          String    (required)此次交易号
  * @return array 返回一个JSON数组,结构如下:
  *      ret             Integer   成功or失败。0失败,1成功
  *      msg             String    返回消息
  *      data            Mixed     返回数据,如果成功,返回格式如下:
  *          ret             Integer 腾讯的返回代码
  *          time            Integer 当前时间戳
  *          flag            String  该数据包的签名
  */
 public function cancelPayAction()
 {
     $logger = $this->getServiceLocator()->get('Zend\\Log');
     $config = $this->getServiceLocator()->get('config');
     $user = $this->getServiceLocator()->get('Account\\Model\\Account');
     $data = json_decode($this->request->getContent(), true);
     $logger->info('Data from client(post):');
     $logger->debug($data);
     if (($ret = $user->store($data)) === true) {
         $result = $user->cancelPay($data);
         if ($result['ret'] === Account::CX_CODE_SUCCESS) {
             $r_data = $result['data'];
             if ($r_data['ret'] === Account::TX_CODE_SUCCESS) {
                 $rdata = $user->signCxResponse(array('ret' => $r_data['ret']));
                 $response = Account::formatResponse(Account::CX_CODE_SUCCESS, 'success', $rdata);
                 //send GM command to GS
                 //根据area_id/plat_id/partition查找数据库连接
                 $adapter_name = "gateway";
                 $adapter = $this->getServiceLocator()->get($adapter_name);
                 $sql = "SELECT ip, port, db_host, db_port, db_name, db_user, db_pass, status FROM servers WHERE area_id = {$data['platform']} AND plat_id = {$data['os']} AND partition = {$data['zoneid']}";
                 $logger->info("execute sql: {$sql}");
                 $result = $adapter->query($sql, Adapter::QUERY_MODE_EXECUTE);
                 $logger->debug('find db info on gateway');
                 //$logger->debug(print_r($result, true));
                 if (!empty($result)) {
                     $gs_config = array();
                     foreach ($result as $row) {
                         $gs_config['status'] = $row['status'];
                         $gs_config['host'] = $row['db_host'];
                         $gs_config['port'] = $row['db_port'];
                         $gs_config['name'] = $row['db_name'];
                         $gs_config['user'] = $row['db_user'];
                         $gs_config['pass'] = $row['db_pass'];
                         $gs_config['gs_ip'] = $row['ip'];
                         $gs_config['gs_port'] = $row['port'];
                     }
                     $gm_result = Account::sendGMCmd($response, $gs_config['gs_ip'], $gs_config['gs_port'], false);
                     $logger->debug($gm_result);
                 }
             } else {
                 //MSDK Return result error
                 $response = Account::formatResponse(Account::CX_CODE_FAILED, 'MSDK return error!', $r_data);
             }
         } else {
             //MSDK Http response error
             $response = Account::formatResponse($result);
         }
     } else {
         //Data validation failed
         $response = Account::formatResponse(Account::CX_CODE_FAILED, 'Data posted from client is invalid!', $ret);
     }
     //output
     //return new JsonModel($response);
     echo json_encode($response);
     exit;
 }
 /**
  * Sends out a confirmation mail to the registered account
  *
  * @param Account $account
  */
 private function sendConfirmationMail(Account $account)
 {
     $mailText = "Congratulations " . $account->getName() . ", you registered at Eternal Deztiny. To complete your registration, ";
     $server = 'ed.com';
     if (array_key_exists('SERVER_NAME', $_SERVER)) {
         $server = $_SERVER['SERVER_NAME'];
     }
     $mailText .= "follow the link:\n" . $server . "/account/activate/" . $account->getUserHash();
     $this->appMailService->sendMail($account->getEmail(), 'Your registration at Eternal Deztiny', $mailText);
 }
 /**
  * Sends out a lost password mail to the given account
  * @param Account $account
  */
 private function sendLostPasswordMail(Account $account)
 {
     $mailText = 'Hello ' . $account->getName() . ', a password reset for your account was requested. ' . 'If you didn\'t request a password reset, you don\'t need to do anything. If you really want to ' . 'reset your password, please follow the given link: ' . $_SERVER['SERVER_NAME'] . '/account/resetpassword/' . $account->getUserHash();
     $this->appMailService->sendMail($account->getEmail(), 'Password Reset', $mailText);
 }