Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
t4rest committed Jul 10, 2017
1 parent 6c8ac9e commit 8ec8e76
Show file tree
Hide file tree
Showing 77 changed files with 990 additions and 62 deletions.
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: vendor/bin/heroku-php-nginx -C nginx.conf frontend/web
web: vendor/bin/heroku-php-nginx -C heroku/nginx.conf frontend/web
5 changes: 2 additions & 3 deletions backend/config/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [],
'defaultRoute' => 'main/default/index',
'modules' => require(__DIR__ . '/modules.php'), 'bootstrap' => ['log'],
'components' => [
'request' => [
'csrfParam' => '_csrf-backend',
Expand Down
7 changes: 7 additions & 0 deletions backend/config/modules.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

return [
'main' => [
'class' => 'backend\modules\main\Module',
],
];
34 changes: 34 additions & 0 deletions backend/controllers/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace backend\controllers;

use common\exceptions;
use yii\web\Controller;
use yii;

abstract class AuthController extends Controller
{
public function init()
{
parent::init();
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
}

/**
* @param yii\base\Action $action
* @return bool
* @throws exceptions\AuthorizationException
* @throws yii\web\BadRequestHttpException
*/
public function beforeAction($action)
{
$token = Yii::$app->request->getQueryParam('oauth_token');


if (!Yii::$app->user->loginByAccessToken($token)) {
throw exceptions\AuthorizationException::invalidToken();
}

return parent::beforeAction($action);
}
}
15 changes: 15 additions & 0 deletions backend/modules/main/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace backend\modules\main;

class Module extends \yii\base\Module
{
public $controllerNamespace = 'frontend\modules\main\controllers';

public function init()
{
parent::init();

// custom initialization code goes here
}
}
12 changes: 12 additions & 0 deletions backend/modules/main/controllers/SiteController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
namespace backend\modules\main\controllers;

use yii\web\Controller;

class SiteController extends Controller
{
public function actionIndex()
{
return $this->render('index');
}
}
60 changes: 60 additions & 0 deletions backend/modules/main/models/ContactForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace backend\models;

use Yii;
use yii\base\Model;

/**
* ContactForm is the model behind the contact form.
*/
class ContactForm extends Model
{
public $name;
public $email;
public $subject;
public $body;
public $verifyCode;


/**
* @inheritdoc
*/
public function rules()
{
return [
// name, email, subject and body are required
[['name', 'email', 'subject', 'body'], 'required'],
// email has to be a valid email address
['email', 'email'],
// verifyCode needs to be entered correctly
['verifyCode', 'captcha'],
];
}

/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}

/**
* Sends an email to the specified email address using the information collected by this model.
*
* @param string $email the target email address
* @return bool whether the email was sent
*/
public function sendEmail($email)
{
return Yii::$app->mailer->compose()
->setTo($email)
->setFrom([$this->email => $this->name])
->setSubject($this->subject)
->setTextBody($this->body)
->send();
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 16 additions & 0 deletions backend/modules/user/Module.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace backend\modules\user;

class Module extends \yii\base\Module
{
public $controllerNamespace = 'backend\modules\user\controllers';

public function init()
{
parent::init();

// custom initialization code goes here
}

}
23 changes: 23 additions & 0 deletions backend/modules/user/api/User.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace backend\modules\user\api;

use backend\modules\user\datatypes\UserStructure;
use yii;


class User
{

/**
* @return array
*/
public function info(): array
{
$user = new UserStructure(
Yii::$app->user->getIdentity()
);

return $user->serialize();
}
}
20 changes: 20 additions & 0 deletions backend/modules/user/controllers/UserController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace backend\modules\user\controllers;

use backend\controllers\AuthController;
use backend\modules\user\api\User as UserApi;


class UserController extends AuthController
{
public $api;

public function beforeAction($action)
{
if (parent::beforeAction($action)) {
$this->api = new UserApi();
}
return true;
}
}
47 changes: 47 additions & 0 deletions backend/modules/user/datatypes/UserStructure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace backend\modules\user\datatypes;

use common\datatypes\Structure;
use common\models\User;

class UserStructure implements Structure
{
/**
* @var User
*/
private $user;

public function __construct($user)
{
$this->user = $user;
}

public function serialize(): array
{
$user = [
'id' => $this->user->id,
'email' => $this->user->email,
'username' => $this->user->username,
'first_name' => $this->user->first_name,
'last_name' => $this->user->last_name,
'photo_url' => $this->user->photo_url,
'timezone' => $this->user->timezone,
'locale' => $this->user->locale,
'created_at' => $this->user->created_at,
'updated_at' => $this->user->updated_at,
];

// if($)

return $user;
}
}








17 changes: 0 additions & 17 deletions backend/views/site/index.php

This file was deleted.

22 changes: 22 additions & 0 deletions common/clients/AuthAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace common\clients;

use Yii;
use yii\authclient\AuthAction as MainAuth;

class AuthAction extends MainAuth
{
public function redirect($url, $enforceRedirect = true)
{
$viewFile = __DIR__ . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'redirect.php';
$viewData = [
'token' => Yii::$app->session->get('auth_token'),
'url' => $url,
'enforceRedirect' => $enforceRedirect,
];
$response = Yii::$app->getResponse();
$response->content = Yii::$app->getView()->renderFile($viewFile, $viewData);
return $response;
}
}
1 change: 1 addition & 0 deletions common/clients/StateStorage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace common\clients;

use Yii;
Expand Down
1 change: 1 addition & 0 deletions common/clients/TokenStorage.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace common\clients;

use yii\authclient\SessionStateStorage;
Expand Down
2 changes: 1 addition & 1 deletion common/clients/Twitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Twitter extends TwitterClient implements ClintInterface
/**
* @return int]
*/
public function getClientId():int
public function getClientId(): int
{
return self::ID;
}
Expand Down
33 changes: 33 additions & 0 deletions common/clients/views/redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
use yii\helpers\Json;

/* @var $this \yii\base\View */
/* @var $token string */
?>
<!DOCTYPE html>
<html>
<head>
<script>
function popupWindowRedirect(url, enforceRedirect, token)
{
if (window.opener && !window.opener.closed) {
window.opener.localStorage.setItem('token', token);
if (enforceRedirect === undefined || enforceRedirect) {
window.opener.location = url;
}
window.opener.focus();
window.close();
} else {
window.localStorage.setItem('token', token);
}
}
popupWindowRedirect(<?= Json::htmlEncode($url) ?>, <?= Json::htmlEncode($enforceRedirect) ?>, <?= Json::htmlEncode($token) ?>);
</script>
</head>
<body>

<div id="token" data-token="<?= Json::htmlEncode($token) ?>"></div>


</body>
</html>
13 changes: 6 additions & 7 deletions common/components/AuthHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ public function handle()

Yii::$app->user->login($user);

} else {

if ($authNetwork && $authNetwork->user_id != Yii::$app->user->id) {
throw new Exception(Yii::t('app', 'Unable to link {client} account. There is another user using it.', ['client' => $this->client->getTitle()]));
}
} else if ($authNetwork && $authNetwork->user_id != Yii::$app->user->id) {
throw new Exception(Yii::t('app', 'Unable to link {client} account. There is another user using it.', ['client' => $this->client->getTitle()]));
}

$this->saveAuthClient($authNetwork, $attributes);

return 123;
// return Yii::$app->user->getAuthKey();
Yii::$app->session->set(
'auth_token',
Yii::$app->user->getIdentity()->getAuthKey()
);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions common/datatypes/Structure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace common\datatypes;

interface Structure
{
public function serialize(): array;
}
Loading

0 comments on commit 8ec8e76

Please sign in to comment.