Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Mar 24, 2017
1 parent 613a1b1 commit 90c5089
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 12 deletions.
3 changes: 3 additions & 0 deletions assets/CodeMirrorButtonsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use yii\web\AssetBundle;

/**
* CodeMirrorButtonsAsset is for buttons plugin for CodeMirror
*/
class CodeMirrorButtonsAsset extends AssetBundle
{
public $sourcePath = '@bower/codemirror-buttons';
Expand Down
2 changes: 1 addition & 1 deletion commands/RbacController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RbacController extends Controller
{
public function actionInit()
{
if (!$this->confirm("Are you sure? It will re-create permissions tree.")) {
if (!$this->confirm('Are you sure? It will re-create permissions tree.')) {
return self::EXIT_CODE_NORMAL;
}

Expand Down
22 changes: 21 additions & 1 deletion components/UserPermissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@


use app\models\News;
use app\models\Project;
use app\models\User;

/**
* UserPermissions contains various methods to check what user can do
*/
class UserPermissions
{
const ADMIN_NEWS = 'adminNews';
const ADMIN_USERS = 'adminUsers';

/**
* Checks if user can admin news
* @return bool
*/
public static function canAdminNews()
{
if (\Yii::$app->user->isGuest) {
Expand All @@ -26,6 +32,11 @@ public static function canAdminNews()
return false;
}

/**
* Checks if user can edit particular news
* @param News $news
* @return bool
*/
public static function canEditNews(News $news)
{
if (\Yii::$app->user->isGuest) {
Expand All @@ -44,6 +55,10 @@ public static function canEditNews(News $news)
return false;
}

/**
* Checks if user can admin other users
* @return bool
*/
public static function canAdminUsers()
{
if (\Yii::$app->user->isGuest) {
Expand All @@ -57,6 +72,11 @@ public static function canAdminUsers()
return false;
}

/**
* Checks if user can edit profile
* @param User $user
* @return bool
*/
public static function canEditUser(User $user)
{
if (\Yii::$app->user->isGuest) {
Expand Down
10 changes: 10 additions & 0 deletions controllers/CommentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use yii\web\Controller;
use yii\web\NotFoundHttpException;

/**
* CommentController
*/
class CommentController extends Controller
{
/**
Expand All @@ -30,6 +33,9 @@ public function behaviors()
];
}

/**
* @return string
*/
public function actionIndex()
{
$query = Comment::find()->orderBy('id DESC');
Expand All @@ -43,6 +49,10 @@ public function actionIndex()
]);
}

/**
* @param int $id
* @return \yii\web\Response
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
Expand Down
38 changes: 38 additions & 0 deletions controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;

/**
* NewsController
*/
class NewsController extends Controller
{
/**
* @inheritdoc
*/
public function behaviors()
{
return [
Expand Down Expand Up @@ -51,6 +57,9 @@ public function behaviors()
];
}

/**
* @return string
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
Expand All @@ -63,6 +72,9 @@ public function actionIndex()
]);
}

/**
* @return string
*/
public function actionSuggest()
{
$model = new News([
Expand Down Expand Up @@ -115,6 +127,10 @@ public function actionRss()
$feed->render();
}

/**
* @param int $status
* @return string
*/
public function actionAdmin($status)
{
$query = News::find()->orderBy('created_at DESC');
Expand All @@ -131,6 +147,11 @@ public function actionAdmin($status)
]);
}

/**
* @param int $id
* @return string|\yii\web\Response
* @throws ForbiddenHttpException
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
Expand All @@ -152,6 +173,10 @@ public function actionUpdate($id)
]);
}

/**
* @param int $id
* @return \yii\web\Response
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
Expand All @@ -160,6 +185,10 @@ public function actionDelete($id)
}


/**
* @param int $id
* @return string|\yii\web\Response
*/
public function actionView($id)
{
$news = $this->findModel($id);
Expand All @@ -177,6 +206,10 @@ public function actionView($id)
]);
}

/**
* @param News $news
* @param Comment $comment
*/
private function notifyAboutComment(News $news, Comment $comment)
{
$users = [];
Expand All @@ -199,6 +232,11 @@ private function notifyAboutComment(News $news, Comment $comment)
}
}

/**
* @param int $id
* @return null|News
* @throws NotFoundHttpException
*/
protected function findModel($id)
{
if (($model = News::findOne($id)) !== null) {
Expand Down
38 changes: 28 additions & 10 deletions controllers/SiteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace app\controllers;

use app\components\AuthHandler;
use app\models\Auth;
use app\models\PasswordResetRequestForm;
use app\models\ResetPasswordForm;
use app\models\SignupForm;
use app\models\User;
use Yii;
use yii\authclient\ClientInterface;
use yii\base\InvalidParamException;
use yii\filters\AccessControl;
use yii\helpers\ArrayHelper;
use yii\web\BadRequestHttpException;
use yii\web\Controller;
use yii\filters\VerbFilter;
use app\models\LoginForm;

/**
* SiteController
*/
class SiteController extends Controller
{
/**
Expand Down Expand Up @@ -79,6 +79,9 @@ public function onAuthSuccess($client)
(new AuthHandler($client))->handle();
}

/**
* @return string
*/
public function actionLogin()
{
if (!\Yii::$app->user->isGuest) {
Expand All @@ -88,31 +91,39 @@ public function actionLogin()
$model = new LoginForm();
if ($model->load(Yii::$app->request->post()) && $model->login()) {
return $this->goBack();
} else {
return $this->render('login', [
'model' => $model,
]);
}
return $this->render('login', [
'model' => $model,
]);
}

/**
* @return \yii\web\Response
*/
public function actionLogout()
{
Yii::$app->user->logout();

return $this->goHome();
}

/**
* @return string
*/
public function actionAbout()
{
return $this->render('about');
}

/**
* @return string|\yii\web\Response
*/
public function actionSignup()
{
$model = new SignupForm();
if ($model->load(Yii::$app->request->post())) {
if ($user = $model->signup()) {
if (Yii::$app->getUser()->login($user, 3600 * 24 * 30)) {
if (Yii::$app->getUser()->login($user, Yii::$app->params['user.rememberMeDuration'])) {
return $this->goHome();
}
}
Expand All @@ -123,6 +134,9 @@ public function actionSignup()
]);
}

/**
* @return string|\yii\web\Response
*/
public function actionRequestPasswordReset()
{
$model = new PasswordResetRequestForm();
Expand All @@ -131,16 +145,20 @@ public function actionRequestPasswordReset()
Yii::$app->getSession()->setFlash('success', 'Check your email for further instructions.');

return $this->goHome();
} else {
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
}
Yii::$app->getSession()->setFlash('error', 'Sorry, we are unable to reset password for email provided.');
}

return $this->render('requestPasswordResetToken', [
'model' => $model,
]);
}

/**
* @param string $token
* @return string|\yii\web\Response
* @throws BadRequestHttpException
*/
public function actionResetPassword($token)
{
try {
Expand Down

0 comments on commit 90c5089

Please sign in to comment.