public static function charge($token, $email, $amount) { $key = Config::get('stripeKey'); Stripe\Stripe::setApiKey($key); $customer = Stripe\Customer::create(array('email' => $email, 'card' => $token)); $charge = Stripe\Charge::create(array('customer' => $customer->id, 'amount' => $amount, 'currency' => 'USD')); return $charge; }
public static function bootDb() { // Init Eloquent ORM Connection $capsule = new Capsule(); $capsule->addConnection(Config::getDbConfig()); $capsule->bootEloquent(); }
public function testHandleRegister() { $code = $this->addCode(); // test wrong code $this->post('/auth/register', []); $this->assertEquals('200', $this->response->getStatusCode()); $this->checkErrorCode(AuthController::WrongCode); // test illegal email $this->post('/auth/register', ["code" => $code]); $this->assertEquals('200', $this->response->getStatusCode()); $this->checkErrorCode(AuthController::IllegalEmail); // test password to short $shortPwd = '123'; $this->post('/auth/register', ["code" => $code, "email" => $this->email, "passwd" => $shortPwd]); $this->assertEquals('200', $this->response->getStatusCode()); $this->checkErrorCode(AuthController::PasswordTooShort); // test password not equal $this->post('/auth/register', ["code" => $code, "email" => $this->email, "passwd" => $this->password, "repasswd" => $shortPwd]); $this->assertEquals('200', $this->response->getStatusCode()); $this->checkErrorCode(AuthController::PasswordNotEqual); // test email used $this->post('/auth/register', ["code" => $code, "email" => $this->getExistEmail(), "passwd" => $this->password, "repasswd" => $this->password]); $this->assertEquals('200', $this->response->getStatusCode()); $this->checkErrorCode(AuthController::EmailUsed); // illegal register Config::set('emailVerifyEnabled', false); $this->post('/auth/register', ["code" => $code, "email" => $this->email, "passwd" => $this->password, "repasswd" => $this->password, "name" => "name"]); $this->assertEquals('200', $this->response->getStatusCode()); }
/** * Get a collection of programmes listed by letter, using a cached record if it exists * @param string $letter The letter for which to query the programmes * @return \Illuminate\Support\Collection */ public function getProgrammes($letter) { $page = Request::get('page', 1); return $this->cache->remember("bbc.programmes.{$letter}.page.{$page}", \Config::get('cache.remember_time'), function () use($letter) { return $this->bbc_api_client->getProgrammes($letter); }); }
public function debug($request, $response, $args) { $server = ["headers" => $request->getHeaders(), "content_type" => $request->getContentType()]; $res = ["server_info" => $server, "ip" => Http::getClientIP(), "version" => Config::get('version'), "reg_count" => Check::getIpRegCount(Http::getClientIP())]; Logger::debug(json_encode($res)); return $this->echoJson($response, $res); }
public function __construct() { $this->config = Config::get("mail")["mailgun"]; $this->mg = new MailgunService($this->config["key"]); $this->domain = $this->config["domain"]; $this->sender = $this->config["sender"]; }
public static function checkPassword($hashedPassword, $password) { $method = Config::get('pwdMethod'); if ($hashedPassword == self::passwordHash($password)) { return true; } return false; }
public function testDebug() { $this->get('/debug'); $this->assertEquals('200', $this->response->getStatusCode()); $ary = json_decode($this->response->getBody(), true); // test version $this->assertEquals(Config::get('version'), $ary['version']); }
/** * Deliver the email confirmation. * * @param User $user * @return void */ public function sendEmailConfirmationTo(User $user) { $this->to = $user->email; $this->view = 'emails.confirm'; $this->from = \Config::get('mail.from.address'); $this->name = \Config::get('mail.from.name'); $this->data = compact('user'); $this->deliver('🚗 애.카.프. 딜러회원 가입을 완료해주세요.'); }
public function isAbleToCheckin() { $last = $this->attributes['last_check_in_time']; $hour = Config::get('checkinTime'); if ($last + $hour * 3600 < time()) { return true; } return false; }
public function testHash() { Config::set('pwdMethod', 'md5'); $this->hashTest(); Config::set('pwdMethod', 'sha256'); $this->hashTest(); Config::set('pwdMethod', 'default'); $this->hashTest(); }
public static function createTokenStorage() { switch (Config::get('tokenDriver')) { case 'db': return new DB(); case 'dynamodb': return new Dynamodb(); default: return new DB(); } }
/** * @return Cache */ public static function newSessionCache() { switch (Config::get('session')) { case 'redis': return self::newRedisCache(); case 'file': return self::newFileCache(Config::getStoragePath('/framework/sessions')); default: return self::newFileCache(); } }
/** * @param string $message * @param string $type * @param array $attachment */ public function post($message, $type, $attachment = []) { $type = \Config::get('slack.types.' . strtolower($type), \Config::get('slack.default', [])); $webHookUrl = \Config::get('slack.webHookUrl'); $client = new Client($webHookUrl, ['username' => array_get($type, 'username', 'FamarryBot'), 'channel' => array_get($type, 'channel', '#random'), 'link_names' => true, 'icon' => array_get($type, 'icon', ':smile:')]); $messageObj = $client->createMessage(); if (!empty($attachment)) { $attachment = new Attachment(['fallback' => array_get($attachment, 'fallback', ''), 'text' => array_get($attachment, 'text', ''), 'pretext' => array_get($attachment, 'pretext', ''), 'color' => array_get($attachment, 'color', 'good'), 'fields' => array_get($attachment, 'fields', [])]); $messageObj->attach($attachment); } $messageObj->setText($message)->send(); }
public function registerJob($jobId, $jobInfo) { $queueData = ['key' => \Config::get('async.key'), 'jobs' => [['id' => $jobId, 'data' => $jobInfo]]]; if (\Config::get('async.enable', false) == true) { $auth = ["key" => \Config::get('aws.accounts.key'), "secret" => \Config::get('aws.accounts.secret'), "region" => \Config::get('aws.accounts.region')]; $sqs = new SqsClient($auth); $sqs->{$sqs}->sendMessage(['QueueUrl' => \Config::get('async.worker.queue'), 'MessageBody' => json_encode($queueData)]); // Log::info('Add Queue:' . json_encode($queueData)); } else { $this->executeJob($queueData); } }
public static function createAuth() { $method = Config::get('authDriver'); switch ($method) { case 'cookie': return new Cookie(); case 'redis': return new Redis(); case 'jwt': return new JwtToken(); } return new Redis(); }
public static function getDriver() { $method = Config::get('authDriver'); switch ($method) { case 'cookie': return new Cookie(); break; case 'redis': return new Redis(); break; } return new Redis(); }
private function setStatusName($todos) { foreach ($todos as $todo) { if ($todo->deleted_at) { $todo->status_name = 'DELETED'; } elseif ($todo->status == \Config::get('app.status.todo.incomplete')) { $todo->status_name = 'INCOMPLETE'; } elseif ($todo->status == \Config::get('app.status.todo.completed')) { $todo->status_name = 'COMPLETED'; } } return $todos; }
public static function sendDailyMail() { $users = User::all(); foreach ($users as $user) { echo "Send daily mail to user: "******"-每日流量报告"; $to = $user->email; try { Mail::send($to, $subject, 'news/daily-traffic-report.tpl', ["user" => $user], []); } catch (Exception $e) { echo $e->getMessage(); } } }
/** * @param $template * @param $ary * @return mixed */ public static function genHtml($template, $ary) { $smarty = new smarty(); $smarty->settemplatedir(BASE_PATH . '/resources/email/'); $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); // add config $smarty->assign('config', Config::getPublicConfig()); $smarty->assign('analyticsCode', DbConfig::get('analytics-code')); foreach ($ary as $key => $value) { $smarty->assign($key, $value); } return $smarty->fetch($template); }
public static function send($to, $subject, $text) { $driver = Config::get("maildriver"); switch ($driver) { case "mailgun": $mail = new Mailgun(); $mail->send($to, $subject, $text); case "smtp": // @TODO smtp // @TODO smtp default: // @TODO default action } }
public static function getSmarty() { $smarty = new smarty(); //实例化smarty $smarty->settemplatedir(BASE_PATH . '/resources/views/' . Config::get('theme') . '/'); //设置模板文件存放目录 $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); //设置生成文件存放目录 $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); //设置缓存文件存放目录 // add config $smarty->assign('config', Config::getPublicConfig()); $smarty->assign('user', Auth::getUser()); return $smarty; }
public static function send($to, $subject, $text) { $driver = Config::get("mailDriver"); switch ($driver) { case "mailgun": $mail = new Mailgun(); return $mail->send($to, $subject, $text); case "smtp": $mail = new Smtp(); return $mail->send($to, $subject, $text); default: // @TODO default action } return true; }
public function doCheckin($request, $response, $args) { $user = Auth::getUser(); //权限检查 if (!$user->isAbleToCheckin()) { $tranferToAdd = 0; $res['msg'] = "签到过了哦"; return $response->getBody()->write(json_encode($res)); } $tranferToAdd = rand(Config::get('checkinMin'), Config::get('checkinMax')); // Add transfer $user->addTraffic($tranferToAdd); $res['msg'] = "获得了" . $tranferToAdd . "MB流量"; return $response->getBody()->write(json_encode($res)); }
public function smarty() { //global $config; $smarty = new smarty(); //实例化smarty $smarty->settemplatedir(BASE_PATH . '/views/' . Config::get('theme') . '/'); //设置模板文件存放目录 $smarty->setcompiledir(BASE_PATH . '/storage/framework/smarty/compile/'); //设置生成文件存放目录 $smarty->setcachedir(BASE_PATH . '/storage/framework/smarty/cache/'); //设置缓存文件存放目录 // add config $smarty->assign('config', $_ENV); $smarty->assign('user', Auth::getUser()); $this->smarty = $smarty; return $smarty; }
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next) { $key = Helper::getMuKeyFromReq($request); if ($key == null) { $res['ret'] = 0; $res['msg'] = "key is null"; $newResponse = $response->withStatus(401); $newResponse->getBody()->write(json_encode($res)); return $newResponse; } if ($key != Config::get('muKey')) { $res['ret'] = 0; $res['msg'] = "token is invalid"; $newResponse = $response->withStatus(401); $newResponse->getBody()->write(json_encode($res)); return $newResponse; } $response = $next($request, $response); return $response; }
/** * @param $email string * @return bool */ public static function sendResetEmail($email) { $pwdRst = new PasswordReset(); $pwdRst->email = $email; $pwdRst->init_time = time(); $pwdRst->expire_time = time() + 3600 * 24; // @todo $pwdRst->token = Tools::genRandomChar(64); if (!$pwdRst->save()) { return false; } $subject = Config::get('appName') . "重置密码"; $resetUrl = Config::get('baseUrl') . "/password/token/" . $pwdRst->token; try { Mail::send($email, $subject, 'password/reset.tpl', ["resetUrl" => $resetUrl], []); } catch (Exception $e) { return false; } return true; }
public function TestingCache($cache) { fwrite(STDERR, "test {$cache} cache "); Config::set('cache', $cache); $client = Factory::newCache(); $key = 'key'; $value = 'value'; $ttl = 3600; $client->set($key, $value, $ttl); $this->assertEquals($value, $client->get($key)); $client->del($key); $this->assertEquals(null, $client->get($key)); // test expired $ttl = 1; $client->set($key, $value, $ttl); sleep(2); $this->assertEquals(null, $client->get($key)); // test wrong key $this->assertEquals(null, $client->get(time())); }
public function addTraffic($request, $response, $args) { // $data = json_decode($request->getParsedBody(),true); $id = $args['id']; $u = $request->getParam('u'); $d = $request->getParam('d'); $nodeId = $request->getParam('node_id'); $node = Node::find($nodeId); $rate = $node->traffic_rate; $user = User::find($id); $user->t = time(); $user->u = $user->u + $u * $rate; $user->d = $user->d + $d * $rate; if (!$user->save()) { $res = ["msg" => "update failed"]; return $this->echoJson($response, $res, 400); } // log $totalTraffic = Tools::flowAutoShow(($u + $d) * $rate); $traffic = new TrafficLog(); $traffic->user_id = $id; $traffic->u = $u; $traffic->d = $d; $traffic->node_id = $nodeId; $traffic->rate = $rate; $traffic->traffic = $totalTraffic; $traffic->log_time = time(); $traffic->save(); $res = ["ret" => 1, "msg" => "ok"]; if (Config::get('log_traffic_dynamodb')) { try { $client = new DynamoTrafficLog(); $id = $client->store($u, $d, $nodeId, $id, $totalTraffic, $rate); $res["id"] = $id; } catch (\Exception $e) { $res["msg"] = $e->getMessage(); Logger::error($e->getMessage()); } } return $this->echoJson($response, $res); }
public function createAdmin() { echo "add admin/ 创建管理员帐号....."; // ask for input fwrite(STDOUT, "Enter your email/输入管理员邮箱: "); // get input $email = trim(fgets(STDIN)); // write input back fwrite(STDOUT, "Enter password for: {$email} / 为 {$email} 添加密码 "); $passwd = trim(fgets(STDIN)); echo "Email: {$email}, Password: {$passwd}! "; fwrite(STDOUT, "Press [Y] to create admin..... 按下[Y]确认来确认创建管理员账户..... "); $y = trim(fgets(STDIN)); if (strtolower($y) == "y") { echo "start create admin account"; // create admin user // do reg user $user = new User(); $user->user_name = "admin"; $user->email = $email; $user->pass = Hash::passwordHash($passwd); $user->passwd = Tools::genRandomChar(6); $user->port = Tools::getLastPort() + 1; $user->t = 0; $user->u = 0; $user->d = 0; $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic')); $user->invite_num = Config::get('inviteNum'); $user->ref_by = 0; $user->is_admin = 1; if ($user->save()) { echo "Successful/添加成功!"; return true; } echo "添加失败"; return false; } echo "cancel"; return false; }