Example #1
0
 public function upgradeRoleUser($userId, $roleKey, $days)
 {
     $roleModel = Api::_()->getModel('User\\Model\\Role');
     $role = $roleModel->getRole($roleKey);
     if (!isset($role['id'])) {
         return array();
     }
     $roleUser = $this->getRoleUser($userId, $role['id']);
     $now = \Eva\Date\Date::getNow();
     if (!isset($roleUser['user_id'])) {
         $data['user_id'] = $userId;
         $data['role_id'] = $role['id'];
         $data['status'] = 'active';
         $data['activeTime'] = $now;
         $data['expiredTime'] = \Eva\Date\Date::getFuture(3600 * 24 * $days, $now, 'Y-m-d H:i:s');
         $this->setItem($data)->createRoleUser();
     } else {
         $roleUser['status'] = 'active';
         if ($roleUser['expiredTime'] > $now) {
             $roleUser['expiredTime'] = \Eva\Date\Date::getFuture(3600 * 24 * $days, $roleUser['expiredTime'], 'Y-m-d H:i:s');
         } else {
             $roleUser['expiredTime'] = \Eva\Date\Date::getFuture(3600 * 24 * $days, $now, 'Y-m-d H:i:s');
             $roleUser['activeTime'] = $now;
         }
         $roleUser->saveRoleUser();
     }
 }
Example #2
0
 public function resetProcess($code, $newPassword)
 {
     $this->trigger('resetprocess.pre');
     if (!$this->verifyRequestCode($code)) {
         throw new \Exception('Password reset code verify failed');
     }
     $codeItem = $this->getItem('User\\Item\\Code');
     $userId = $codeItem->user_id;
     $this->setItem(array('id' => $userId));
     $item = $this->getItem();
     $item->self(array('*'));
     $salt = $item->salt;
     $oldPassword = $item->password;
     $bcrypt = new \Zend\Crypt\Password\Bcrypt();
     $bcrypt->setSalt($salt);
     $item->password = $bcrypt->create($newPassword);
     $item->oldPassword = $oldPassword;
     $item->lastPasswordChangeTime = \Eva\Date\Date::getNow();
     $this->trigger('resetprocess');
     $item->save();
     $codeItem->clear();
     $codeItem->getDataClass()->where(array('code' => $code))->save(array('codeStatus' => 'used', 'used_by_id' => $userId, 'usedTime' => \Eva\Date\Date::getNow()));
     //One code used will expire all other active codes
     $codeItem->getDataClass()->where(array('codeType' => 'resetPassword', 'codeStatus' => 'active', 'user_id' => $userId))->save(array('codeStatus' => 'expired', 'expiredTime' => \Eva\Date\Date::getNow()));
     $this->trigger('resetprocess.post');
 }
Example #3
0
 public function loginRefresh()
 {
     $userId = $this->getUserId();
     if (!$userId) {
         throw new \Core\Exception\InvalidArgumentException(sprintf('No user id found when refresh login'));
     }
     $user = $this->getItem()->getDataClass()->where(array('id' => $userId))->save(array('onlineStatus' => 'online', 'lastLoginTime' => \Eva\Date\Date::getNow(), 'lastFreshTime' => \Eva\Date\Date::getNow(), 'lastLoginIp' => $_SERVER["REMOTE_ADDR"]));
 }
Example #4
0
 public function getCreateTime()
 {
     if (!$this->createTime) {
         return $this->createTime = \Eva\Date\Date::getNow();
     } else {
         return $this->createTime;
     }
 }
Example #5
0
 public function getEndDatetimeUtc()
 {
     $datetime = $this->endDay . ' ' . $this->endTime;
     if ($this->timezone && $this->endTime && $this->endDay) {
         return $this->endDatetimeUtc = \Eva\Date\Date::getBefore($this->timezone * 3600, $datetime, 'Y-m-d H:i:s');
     }
     return $this->endDatetimeUtc = $datetime;
 }
Example #6
0
 protected function onCreateActivity($event)
 {
     $itemModel = Api::_()->getModel('Activity\\Model\\Activity');
     $item = $itemModel->getItem();
     $eventActivityItem = $itemModel->getItem('Activity\\Item\\EventActivity');
     $eventActivityItem->event_id = $this->eventId;
     $eventActivityItem->message_id = $item->message_id;
     $eventActivityItem->messageTime = \Eva\Date\Date::getNow();
     $eventActivityItem->create();
 }
 public function expireAction()
 {
     $this->changeViewModel('json');
     $itemModel = Api::_()->getModel('Oauth\\Model\\Accesstoken');
     $dataClass = $itemModel->getItem()->getDataClass();
     $dataClass->where(function ($where) {
         $where->equalTo('tokenStatus', 'active');
         $where->equalTo('version', 'Oauth2');
         $where->lessThan('expireTime', \Eva\Date\Date::getNow());
         return $where;
     })->save(array('tokenStatus' => 'expried'));
     return new JsonModel();
 }
 public function offlineAction()
 {
     $this->changeViewModel('json');
     $itemModel = Api::_()->getModel('User\\Model\\User');
     $config = Api::_()->getConfig();
     $onlineToOfflineTime = $config['user']['online_to_offline_time'];
     $onlineToOfflineTime = \Eva\Date\Date::getBefore($onlineToOfflineTime, null, 'Y-m-d H:i:s');
     $dataClass = $itemModel->getItem()->getDataClass();
     $dataClass->where(function ($where) use($onlineToOfflineTime) {
         $where->lessThan('lastFreshTime', $onlineToOfflineTime);
         return $where;
     })->save(array('onlineStatus' => 'offline'));
     return new JsonModel();
 }
 public function prepareData($data)
 {
     $data['password'] = $data['inputPassword'];
     $data['oldPassword'] = $data['verifyPassword'];
     unset($data['verifyPassword'], $data['inputPassword'], $data['repeatPassword']);
     $userModel = \Eva\Api::_()->getModel('User\\Model\\User');
     $user = $userModel->getUser($data['id']);
     $salt = $user->salt;
     $bcrypt = new \Zend\Crypt\Password\Bcrypt();
     $bcrypt->setSalt($salt);
     $data['password'] = $bcrypt->create($data['password']);
     $data['oldPassword'] = $user->password;
     $data['lastPasswordChangeTime'] = \Eva\Date\Date::getNow();
     return $data;
 }
Example #10
0
 public function getRemovedTime()
 {
     return $this->removedTime = \Eva\Date\Date::getNow();
 }
Example #11
0
 public function getResponseTime()
 {
     $this->responseTime = \Eva\Date\Date::getNow();
 }
Example #12
0
 public function getRegisterTime()
 {
     if (!$this->registerTime) {
         return $this->registerTime = \Eva\Date\Date::getNow();
     }
 }
Example #13
0
 public function getProduct($pid, $nick = null)
 {
     $options = $this->getOptions();
     $nick = $nick ? $nick : $options['nick'];
     $url = 'http://gw.api.taobao.com/router/rest';
     $query = array('app_key' => $options['consumerKey'], 'format' => 'json', 'fields' => 'num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume', 'method' => 'taobao.taobaoke.items.detail.get', 'sign_method' => 'md5', 'timestamp' => \Eva\Date\Date::getNow(), 'v' => '2.0', 'num_iids' => $pid, 'nick' => $nick);
     $query['sign'] = $this->getSignature($query);
     $client = $this->getClient($url, $query);
     $response = $client->send();
     $responseText = $response->getBody();
     if ($this->isResponseFailed($responseText) === true) {
         $responseErrorMessage = $this->responseErrorMessage;
         $responseErrorMessage = $responseErrorMessage ? $responseErrorMessage : 'response error';
     } else {
         $product = $this->parseResponse($responseText);
         $product = $product['taobaoke_items_detail_get_response']['taobaoke_item_details']['taobaoke_item_detail'][0]['item'];
         $title = $product['title'];
         $query = array('app_key' => $options['consumerKey'], 'format' => 'json', 'fields' => 'num_iid,title,nick,pic_url,price,click_url,commission,commission_rate,commission_num,commission_volume,shop_click_url,seller_credit_score,item_location,volume', 'method' => 'taobao.taobaoke.items.get', 'sign_method' => 'md5', 'timestamp' => \Eva\Date\Date::getNow(), 'v' => '2.0', 'keyword' => $title);
         $query['sign'] = $this->getSignature($query);
         $client = $this->getClient($url, $query);
         $response = $client->send();
         $responseText = $response->getBody();
         if ($this->isResponseFailed($responseText) === true) {
             $responseErrorMessage = $this->responseErrorMessage;
             $responseErrorMessage = $responseErrorMessage ? $responseErrorMessage : 'response error';
         } else {
             $products = $this->parseResponse($responseText);
             $productsCount = $products['taobaoke_items_get_response']['total_results'];
             $products = $products['taobaoke_items_get_response']['taobaoke_items']['taobaoke_item'];
             $res = array();
             foreach ($products as $commissionProduct) {
                 if ($product['num_iid'] == $commissionProduct['num_iid']) {
                     $res = $commissionProduct;
                 }
             }
             return $res;
         }
     }
     return array();
 }
Example #14
0
 public function activeAccount()
 {
     $codeItem = $this->getItem();
     $userId = $codeItem->user_id;
     $userItem = $this->getItem('User\\Item\\User');
     $codeItem->codeStatus = 'used';
     $codeItem->used_by_id = $userId;
     $codeItem->usedTime = \Eva\Date\Date::getNow();
     $codeItem->save();
     $userItem->clear();
     $userItem->getDataClass()->where(array('id' => $userId))->save(array('status' => 'active'));
     //One code used will expire all other active codes
     $codeItem->getDataClass()->where(array('codeType' => 'activeAccount', 'codeStatus' => 'active', 'user_id' => $userId))->save(array('codeStatus' => 'expired', 'expiredTime' => \Eva\Date\Date::getNow()));
 }
Example #15
0
 public function getUpdateTime()
 {
     $this->updateTime = \Eva\Date\Date::getNow();
 }
Example #16
0
 public function getExpiredTime()
 {
     return $this->expiredTime = \Eva\Date\Date::getFuture(3600 * 24 * 60, $this->refreshTime, 'Y-m-d H:i:s');
 }
Example #17
0
 public function getFollowTime()
 {
     if (!$this->followTime) {
         return $this->followTime = \Eva\Date\Date::getNow();
     }
 }
Example #18
0
 public function getExpiredTime()
 {
     //expired is 10 days
     return $this->expiredTime = \Eva\Date\Date::getFuture(3600 * 24 * 10, $this->createTime, 'Y-m-d H:i:s');
 }
Example #19
0
 public function getApprovalTime()
 {
     if (!$this->approvalTime) {
         return $this->approvalTime = \Eva\Date\Date::getNow();
     }
 }