コード例 #1
0
    /**
     * Creates a new User model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
    public function actionCreate()
    {
        if (!\Yii::$app->user->isGuest) {
            return $this->goHome();
        }
        $model = new User();
        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            $email = new Email();
            $email->to_name = $model->name;
            $email->to_email = $model->email;
            $email->subject = "Your Tixty Purchase";
            $message = <<<EOT
Hi {$model->name}!!

You just registered as a user. Use {$model->email} to login with the password you chose and start buying tickets at <a href="https://tixty.co.uk/">tixty.co.uk</a>

Thanks,

Tixty
EOT;
            $email->body = nl2br($message);
            $email->save();
            $email->send();
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', ['model' => $model]);
        }
    }
コード例 #2
0
 public function save($request)
 {
     $email = new Email();
     $email->template_name = $request->input('template_name');
     $email->subject = $request->input('subject');
     $email->template = $request->input('template');
     $email->status = $request->input('status');
     if ($email->save()) {
         return $email->id;
     } else {
         return false;
     }
 }
コード例 #3
0
    /**
     * Displays a single Organisation model.
     * @param string $id
     * @return mixed
     */
    public function actionConnect($code, $state)
    {
        $sql = "SELECT * FROM organisation WHERE SHA1(CONCAT(`id`, :salt, `name`)) = :state";
        $organisation = Organisation::findBySql($sql, [':salt' => 'jiejieugs9837', ':state' => $state])->one();
        if (\Yii::$app->user->isGuest) {
            return $this->redirect('/site/denied/');
        }
        $user = \Yii::$app->user->identity;
        if (!$user->admin && count($user->organisations) == 0) {
            return $this->redirect('/site/denied/');
        } else {
            if (!$user->admin) {
                $organisations = $user->organisations;
                foreach ($organisations as $org) {
                    if ($organisation->id == $org->id) {
                        break 2;
                    }
                }
                return $this->redirect('/site/denied');
            }
        }
        if (!empty($code)) {
            $token_request_body = array('grant_type' => 'authorization_code', 'client_id' => Yii::$app->params['stripeClientID'], 'code' => $code, 'client_secret' => Yii::$app->params['stripeSecretKey']);
            $req = curl_init('https://connect.stripe.com/oauth/token');
            curl_setopt($req, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($req, CURLOPT_POST, true);
            curl_setopt($req, CURLOPT_POSTFIELDS, http_build_query($token_request_body));
            curl_setopt($req, CURLOPT_SSL_VERIFYPEER, true);
            //curl_setopt($req, CURLOPT_CAINFO, '/home/web/tickets/cacert.pem');
            $respCode = curl_getinfo($req, CURLINFO_HTTP_CODE);
            $resp = json_decode(curl_exec($req), true);
            curl_close($req);
            $organisation = $this->findModel($organisation->id);
            $organisation->stripe_access_token = $resp['access_token'];
            $organisation->stripe_public_key = $resp['stripe_publishable_key'];
            $organisation->stripe_user_id = $resp['stripe_user_id'];
            $organisation->stripe_refresh_token = $resp['refresh_token'];
            $organisation->save();
            $organisation_test = Organisation::findOne($organisation->id);
            $result = $organisation_test->stripe_user_id ? "successful" : "unsuccessful";
            $founder = User::findOne(OrganisationMembers::findOne(['organisation_id' => $organisation->id, 'founder' => 1])->user_id);
            $email = new Email();
            $email->to_name = $founder->name;
            $email->to_email = $founder->email;
            $email->subject = "Authorisation Attempt";
            $email->body = <<<EOT
You tried to connect {$organisation->name} to Tixty. That was {$result}.

Tixty
EOT;
            $email->save();
            $email->send();
            $response = print_r($resp, true);
            $email = new Email();
            $email->to_name = $email->sender_name;
            $email->to_email = $email->sender_email;
            $email->subject = "Authorisation Attempt for {$organisation->name} {$result}";
            $email->body = <<<EOT
<pre>{$response}</pre>
EOT;
            $email->save();
            $email->send();
        }
        return $this->redirect('/organisation/view', ['id' => $organisation->id]);
    }
コード例 #4
0
ファイル: Mailgun.php プロジェクト: CatoTH/Stadtratsantraege
 /**
  * @param string $toEmail
  * @param string $subject
  * @param string $textPlain
  * @param string $textHtml
  *
  * @throws \Exception
  */
 public static function sendWithLog($toEmail, $subject, $textPlain, $textHtml = '')
 {
     $mailer = new static(\Yii::$app->params);
     $messageId = explode('@', \Yii::$app->params['mailFromEmail']);
     $messageId = uniqid() . '@' . $messageId[1];
     $exception = null;
     try {
         $message = $mailer->createMessage($subject, $textPlain, $textHtml, $messageId);
         $status = $mailer->send($message, $toEmail);
     } catch (\Exception $e) {
         $status = Email::STATUS_DELIVERY_ERROR;
         $exception = $e;
     }
     $obj = new Email();
     $obj->toEmail = $toEmail;
     $obj->subject = $subject;
     $obj->text = $textPlain;
     $obj->dateSent = date('Y-m-d H:i:s');
     $obj->status = $status;
     $obj->messageId = $messageId;
     $obj->save();
     if ($exception) {
         /** @var \Exception $exception */
         throw new \Exception($exception->getMessage());
     }
     if (YII_ENV == 'test') {
         \Yii::$app->session->setFlash('email', 'E-Mail sent to: ' . $toEmail);
     }
 }
コード例 #5
0
    public function actionSave()
    {
        $session = new Session();
        $user = Yii::$app->user->identity;
        $cart = Cart::getCurrentCart();
        $cart->processCart();
        if ($cart->total > 0) {
            return $this->actionCharge();
        }
        $cart->status = Cart::CART_SOLD;
        $cart->save();
        $session->addSuccess(Yii::t('app', 'Congratulations, you\'ve completed your order!'));
        $cart_lines = [];
        foreach ($cart->items as $item) {
            $cart_lines[] = $item->ticket->group->event->name . ': ' . $item->ticket->name . ' x' . $item->quantity . ' @ ' . $item->ticket->ticket_price . ' each';
        }
        $cart_details = implode("\n", $cart_lines);
        $email = new Email();
        $email->to_name = $user->name;
        $email->to_email = $user->email;
        $email->subject = "Your Tixty Purchase";
        $message = <<<EOT
Hi {$user->name}!!

You just bought {$cart->quantity} tickets for a total of {$cart->total} - details below.

Thanks,

Tixty

---
{$cart_details}
EOT;
        $email->body = nl2br($message);
        $email->save();
        $email->send();
        $email = new Email();
        $email->to_name = "Tixty";
        $email->to_email = \Yii::$app->params['adminEmail'];
        $email->subject = "Tixty Purchase #{$cart->id}";
        $message = <<<EOT
{$user->name} just bought {$cart->quantity} tickets for a total of {$cart->total} - details below.

Tixty

---
{$cart_details}
EOT;
        $email->body = nl2br($message);
        $email->save();
        $email->send();
        return $this->redirect('index');
    }
コード例 #6
0
 /**
  * Creates a new Email model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Email();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         //return $this->redirect(['view', 'id' => $model->id]);
         return $this->goHome();
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }