/** * 明示的に接続を破棄. */ public static function disconnect() { if (self::$mc) { self::$mc->close(); self::$mc = null; } }
public function executeCreate_token() { $token_expire = '+1 hours'; $expire_time = strtotime($token_expire); $mc_expire = $expire_time - time(); $tokendata = array('mail' => $this->login_user->getMail(), 'package_id' => $this->package->getId(), 'expire' => date('Y-m-d H:i:s', $expire_time)); $token = Random::string(32); mfwMemcache::set(self::INSTALL_TOKEN_PREFIX . $token, json_encode($tokendata), $mc_expire); apache_log('token', $token); apache_log('token_data', $tokendata); $params = array('token' => $token, 'expire' => $tokendata['expire'], 'token_url' => mfwRequest::makeURL("/package/install?token={$token}")); return $this->build($params); }
/** * @param[in] string $sender 送信アドレス */ public function sendResetMail() { $data = array('mail' => $this->row['mail'], 'microtime' => microtime()); $key = sha1(json_encode($data)); mfwMemcache::set($key, $data, self::RESET_MAIL_EXPIRE); $url = mfwRequest::makeUrl("/login/password_reset?key={$key}"); $subject = 'Reset password'; $to = $data['mail']; $from = 'From: ' . Config::get('mail_sender'); $body = "EMLauncher password reset URL:\n{$url}\n"; if (!mb_send_mail($to, $subject, $body, $from)) { throw new RuntimeException("mb_send_mail faild (key:{$key} to:{$to})"); } }
public function executePassword_commit() { $key = mfwRequest::param('key'); $pass = mfwRequest::param('password'); $data = mfwMemcache::get($key); $user_pass = null; if (isset($data['mail'])) { $user_pass = UserPassDb::selectByEmail($data['mail']); } if (!$user_pass) { return $this->buildErrorPage('invalid key'); } $user_pass->updatePasshash($pass); mfwMemcache::delete($key); return $this->build(); }
public function executeCreate_token() { try { $api_key = mfwRequest::param('api_key'); $pkg_id = mfwRequest::param('id'); $mail = mfwRequest::param('mail'); $expire_hour = mfwRequest::param('expire_hour'); // api_key check $app = ApplicationDb::selectByApiKey($api_key); if (!$app) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid api_key')); } // id check $pkg = PackageDb::retrieveByPK($pkg_id); if (!$pkg || $app->getId() !== $pkg->getAppId()) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid package id')); } // mail check $owner_mails = $app->getOwners()->getMailArray(); if (!in_array($mail, $owner_mails)) { return $this->jsonResponse(self::HTTP_400_BADREQUEST, array('error' => 'Invalid mail address')); } // create install token $expire_hour = empty($expire_hour) ? 1 : $expire_hour; $token_expire = sprintf('+%s hours', $expire_hour); $expire_time = strtotime($token_expire); $mc_expire = $expire_time - time(); $tokendata = array('mail' => $mail, 'package_id' => $pkg_id, 'expire' => date('Y-m-d H:i:s', $expire_time)); $token = Random::string(32); mfwMemcache::set(self::INSTALL_TOKEN_PREFIX . $token, json_encode($tokendata), $mc_expire); apache_log('token', $token); apache_log('token_data', $tokendata); $ret = $this->makePackageArray($pkg); $ret['install_url'] = mfwRequest::makeURL("/package/install?token={$token}"); } catch (Exception $e) { error_log(__METHOD__ . '(' . __LINE__ . '): ' . get_class($e) . ":{$e->getMessage()}"); return $this->jsonResponse(self::HTTP_500_INTERNALSERVERERROR, array('error' => $e->getMessage(), 'exception' => get_class($e))); } apache_log('app_id', $app->getId()); return $this->jsonResponse(self::HTTP_200_OK, $ret); }
/** * link_idから戻り先URLを取り出す. * @param[in] $link_id 省略時はクエリパラメータのlink_idが対象 * @return URL */ public static function getReturnUrl($link_id = null) { if (!$link_id) { $link_id = static::linkId(); } static $returnurls = array(); if (!array_key_exists($link_id, $returnurls)) { $returnurls[$link_id] = mfwMemcache::fetchURL($link_id); } return $returnurls[$link_id]; }
protected function checkToken($token) { $pkg_id = mfwMemcache::get(self::TOKEN_KEY_PREFIX . $token); return $pkg_id == $this->package->getId(); }