<commit_before><?php

namespace app\controllers;

use \DateTime;
use Yii;
use app\models\User;
use app\models\TempUser;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\HttpException;
use yii\helpers\Url;
use SendGrid;

/**
 * UserController implements the CRUD actions for User model.
 */
class UserController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Lists all User models.
     * @return mixed
     */
    public function actionIndex($token)
    {
        //Viewer is the user who is currently logged in and viewing.
        $viewer = Yii::$app->user->identity;

        //Viewee is the user being queried and viewed.
        $viewee = User::findOne(['userName'=>$token]);

        //See if the object user exist
        if(!$viewee)
            $viewee = User::findOne(['userId'=>$token]);
        if(!$viewee)
            throw new HttpException(400,'User does not exist');

        $counters = $viewer->userId == $viewee->userId ? $viewee->counters : $viewee->getCounters()->where(['public'=>true])->all();
        $data = $this->makeCalendarData($counters, $viewer, $viewee);<commit_msg>When ui and database are in incosistent state, logout user and go to homepage.<commit_after><?php

namespace app\controllers;

use \DateTime;
use Yii;
use app\models\User;
use app\models\TempUser;
use yii\data\ActiveDataProvider;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\HttpException;
use yii\helpers\Url;
use SendGrid;

/**
 * UserController implements the CRUD actions for User model.
 */
class UserController extends Controller
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['post'],
                ],
            ],
        ];
    }

    /**
     * Lists all User models.
     * @return mixed
     */
    public function actionIndex($token)
    {
        //Viewer is the user who is currently logged in and viewing.
        if(!$viewer = Yii::$app->user->identity) {
            Yii::$app->user->logout();
            $this->goHome();
        }


        //Viewee is the user being queried and viewed.
        $viewee = User::findOne(['userName'=>$token]);

        //See if the object user exist
        if(!$viewee)
            $viewee = User::findOne(['userId'=>$token]);
        if(!$viewee)
            throw new HttpException(400,'User does not exist');

        $counters = $viewer->userId == $viewee->userId ?
            $viewee->getCounters()->orderBy('dispOrder')->all() :
            $viewee->getCounters()->where(['public'=>true])->orderBy('dispOrder')->all();

        $data = $this->makeCalendarData($counters, $viewer, $viewee);
{'fraction_non_alphanumeric': 0.14447683835438938, 'fraction_numerical': 0.001943634596695821, 'mean_word_length': 2.309753483386924, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2621271', 'n_tokens_mistral': 946, 'n_tokens_neox': 924, 'n_words': 222}