Initial commit
This commit is contained in:
4
frontend/Dockerfile
Normal file
4
frontend/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
||||
FROM yiisoftware/yii2-php:8.3-apache
|
||||
|
||||
# Change document root for Apache
|
||||
RUN sed -i -e 's|/app/web|/app/frontend/web|g' /etc/apache2/sites-available/000-default.conf
|
||||
25
frontend/assets/AppAsset.php
Normal file
25
frontend/assets/AppAsset.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\assets;
|
||||
|
||||
use yii\web\AssetBundle;
|
||||
|
||||
/**
|
||||
* Main frontend application asset bundle.
|
||||
*/
|
||||
class AppAsset extends AssetBundle
|
||||
{
|
||||
public $basePath = '@webroot';
|
||||
public $baseUrl = '@web';
|
||||
public $css = [
|
||||
'css/site.css',
|
||||
'css/select2.css',
|
||||
];
|
||||
public $js = [
|
||||
'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js',
|
||||
];
|
||||
public $depends = [
|
||||
'yii\web\YiiAsset',
|
||||
'yii\bootstrap5\BootstrapAsset',
|
||||
];
|
||||
}
|
||||
22
frontend/assets/ConfettiAsset.php
Normal file
22
frontend/assets/ConfettiAsset.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\assets;
|
||||
|
||||
use yii\web\AssetBundle;
|
||||
|
||||
/**
|
||||
* Confetti assett.
|
||||
*/
|
||||
class ConfettiAsset extends AssetBundle
|
||||
{
|
||||
|
||||
public $basePath = '@webroot';
|
||||
public $baseUrl = '@web';
|
||||
public $css = [
|
||||
];
|
||||
public $js = [
|
||||
'//cdn.jsdelivr.net/npm/canvas-confetti@1.5.1/dist/confetti.browser.min.js',
|
||||
];
|
||||
public $depends = [
|
||||
];
|
||||
}
|
||||
15
frontend/codeception.yml
Normal file
15
frontend/codeception.yml
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace: frontend\tests
|
||||
actor_suffix: Tester
|
||||
paths:
|
||||
tests: tests
|
||||
output: tests/_output
|
||||
data: tests/_data
|
||||
support: tests/_support
|
||||
bootstrap: _bootstrap.php
|
||||
settings:
|
||||
colors: true
|
||||
memory_limit: 1024M
|
||||
modules:
|
||||
config:
|
||||
Yii2:
|
||||
configFile: 'config/codeception-local.php'
|
||||
4
frontend/config/.gitignore
vendored
Normal file
4
frontend/config/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
codeception-local.php
|
||||
main-local.php
|
||||
params-local.php
|
||||
test-local.php
|
||||
1
frontend/config/bootstrap.php
Normal file
1
frontend/config/bootstrap.php
Normal file
@@ -0,0 +1 @@
|
||||
<?php
|
||||
76
frontend/config/main.php
Normal file
76
frontend/config/main.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
use yii\i18n\PhpMessageSource;
|
||||
|
||||
use function Sentry\init;
|
||||
|
||||
$params = array_merge(
|
||||
require __DIR__ . '/../../common/config/params.php',
|
||||
require __DIR__ . '/../../common/config/params-local.php',
|
||||
require __DIR__ . '/params.php',
|
||||
require __DIR__ . '/params-local.php'
|
||||
);
|
||||
|
||||
// adding sentry to main on common and frontend
|
||||
init([
|
||||
'dsn' => $params['sentry.dsn'],
|
||||
// Specify a fixed sample rate
|
||||
'traces_sample_rate' => 1.0,
|
||||
// Set a sampling rate for profiling - this is relative to traces_sample_rate
|
||||
'profiles_sample_rate' => 1.0,
|
||||
]);
|
||||
|
||||
return [
|
||||
'id' => 'app-frontend',
|
||||
'basePath' => dirname(__DIR__),
|
||||
'bootstrap' => ['log'],
|
||||
'controllerNamespace' => 'frontend\controllers',
|
||||
'modules' => [
|
||||
'gridview' => [
|
||||
'class' => '\kartik\grid\Module',
|
||||
'bsVersion' => '5.x',
|
||||
]
|
||||
],
|
||||
'components' => [
|
||||
'i18n' => [
|
||||
'translations' => [
|
||||
'*' => [
|
||||
'class' => PhpMessageSource::class,
|
||||
'fileMap' => [],
|
||||
],
|
||||
],
|
||||
],
|
||||
'request' => [
|
||||
'parsers' => [
|
||||
'application/json' => 'yii\web\JsonParser',
|
||||
],
|
||||
'csrfParam' => '_csrf-frontend',
|
||||
],
|
||||
'session' => [
|
||||
// this is the name of the session cookie used for login on the frontend
|
||||
'name' => 'calorie-frontend',
|
||||
],
|
||||
'log' => [
|
||||
'traceLevel' => YII_DEBUG ? 3 : 0,
|
||||
'targets' => [
|
||||
[
|
||||
'class' => \yii\log\FileTarget::class,
|
||||
'levels' => ['error', 'warning'],
|
||||
],
|
||||
'utility' => [
|
||||
'class' => \yii\log\SyslogTarget::class,
|
||||
'enabled' => false,
|
||||
],
|
||||
],
|
||||
],
|
||||
'errorHandler' => [
|
||||
'errorAction' => 'site/error',
|
||||
],
|
||||
'user' => [
|
||||
'identityClass' => 'common\models\User',
|
||||
'enableAutoLogin' => true,
|
||||
'identityCookie' => ['name' => '_identity-frontend', 'httpOnly' => true],
|
||||
],
|
||||
],
|
||||
'params' => $params,
|
||||
];
|
||||
5
frontend/config/params.php
Normal file
5
frontend/config/params.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
return [
|
||||
'bsVersion' => '5.x',
|
||||
'adminEmail' => 'admin@example.com',
|
||||
];
|
||||
18
frontend/config/test.php
Normal file
18
frontend/config/test.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
return [
|
||||
'id' => 'app-frontend-tests',
|
||||
'components' => [
|
||||
'assetManager' => [
|
||||
'basePath' => __DIR__ . '/../web/assets',
|
||||
],
|
||||
'urlManager' => [
|
||||
'showScriptName' => true,
|
||||
],
|
||||
'request' => [
|
||||
'cookieValidationKey' => 'test',
|
||||
],
|
||||
'mailer' => [
|
||||
'messageClass' => \yii\symfonymailer\Message::class
|
||||
]
|
||||
],
|
||||
];
|
||||
144
frontend/controllers/MealController.php
Normal file
144
frontend/controllers/MealController.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use common\models\Meal;
|
||||
use yii\data\ActiveDataProvider;
|
||||
use yii\web\Controller;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\filters\VerbFilter;
|
||||
|
||||
/**
|
||||
* MealController implements the CRUD actions for Meal model.
|
||||
*/
|
||||
class MealController extends Controller
|
||||
{
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return array_merge(
|
||||
parent::behaviors(),
|
||||
[
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::className(),
|
||||
'actions' => [
|
||||
'delete' => ['POST'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lists all Meal models.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
$dataProvider = new ActiveDataProvider([
|
||||
'query' => Meal::find(),
|
||||
/*
|
||||
'pagination' => [
|
||||
'pageSize' => 50
|
||||
],
|
||||
'sort' => [
|
||||
'defaultOrder' => [
|
||||
'id' => SORT_DESC,
|
||||
]
|
||||
],
|
||||
*/
|
||||
]);
|
||||
|
||||
return $this->render('index', [
|
||||
'dataProvider' => $dataProvider,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a single Meal model.
|
||||
* @param int $id ID
|
||||
* @return string
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionView($id)
|
||||
{
|
||||
return $this->render('view', [
|
||||
'model' => $this->findModel($id),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new Meal model.
|
||||
* If creation is successful, the browser will be redirected to the 'view' page.
|
||||
* @return string|\yii\web\Response
|
||||
*/
|
||||
public function actionCreate()
|
||||
{
|
||||
$model = new Meal();
|
||||
|
||||
if ($this->request->isPost) {
|
||||
if ($model->load($this->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
} else {
|
||||
$model->loadDefaultValues();
|
||||
}
|
||||
|
||||
return $this->render('create', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates an existing Meal model.
|
||||
* If update is successful, the browser will be redirected to the 'view' page.
|
||||
* @param int $id ID
|
||||
* @return string|\yii\web\Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionUpdate($id)
|
||||
{
|
||||
$model = $this->findModel($id);
|
||||
|
||||
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) {
|
||||
return $this->redirect(['view', 'id' => $model->id]);
|
||||
}
|
||||
|
||||
return $this->render('update', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes an existing Meal model.
|
||||
* If deletion is successful, the browser will be redirected to the 'index' page.
|
||||
* @param int $id ID
|
||||
* @return \yii\web\Response
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
public function actionDelete($id)
|
||||
{
|
||||
$this->findModel($id)->delete();
|
||||
|
||||
return $this->redirect(['index']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the Meal model based on its primary key value.
|
||||
* If the model is not found, a 404 HTTP exception will be thrown.
|
||||
* @param int $id ID
|
||||
* @return Meal the loaded model
|
||||
* @throws NotFoundHttpException if the model cannot be found
|
||||
*/
|
||||
protected function findModel($id)
|
||||
{
|
||||
if (($model = Meal::findOne(['id' => $id])) !== null) {
|
||||
return $model;
|
||||
}
|
||||
|
||||
throw new NotFoundHttpException('The requested page does not exist.');
|
||||
}
|
||||
}
|
||||
281
frontend/controllers/SiteController.php
Normal file
281
frontend/controllers/SiteController.php
Normal file
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\controllers;
|
||||
|
||||
use common\components\SonarApiComponent;
|
||||
use common\jobs\EmailJob;
|
||||
use frontend\models\ResendVerificationEmailForm;
|
||||
use frontend\models\VerifyEmailForm;
|
||||
use Yii;
|
||||
use yii\base\InvalidArgumentException;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\filters\AccessControl;
|
||||
use common\models\LoginForm;
|
||||
use frontend\models\PasswordResetRequestForm;
|
||||
use frontend\models\ResetPasswordForm;
|
||||
use frontend\models\SignupForm;
|
||||
use yii\web\Response;
|
||||
|
||||
use const donatj\UserAgent\BROWSER;
|
||||
use const donatj\UserAgent\PLATFORM;
|
||||
|
||||
/**
|
||||
* Site controller
|
||||
*/
|
||||
class SiteController extends Controller
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function behaviors()
|
||||
{
|
||||
return [
|
||||
'access' => [
|
||||
'class' => AccessControl::class,
|
||||
'only' => ['logout', 'signup', 'webhook'],
|
||||
'rules' => [
|
||||
[
|
||||
'actions' => ['signup'],
|
||||
'allow' => true,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
[
|
||||
'actions' => ['webhook'],
|
||||
'allow' => true,
|
||||
'roles' => ['?'],
|
||||
],
|
||||
[
|
||||
'actions' => ['logout'],
|
||||
'allow' => true,
|
||||
'roles' => ['@'],
|
||||
],
|
||||
],
|
||||
],
|
||||
'verbs' => [
|
||||
'class' => VerbFilter::class,
|
||||
'actions' => [
|
||||
'logout' => ['post'],
|
||||
'webhook' => ['post','head'],
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function beforeAction($action)
|
||||
{
|
||||
if ($action->id == 'webhook') {
|
||||
$this->enableCsrfValidation = false;
|
||||
}
|
||||
|
||||
return parent::beforeAction($action);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function actions()
|
||||
{
|
||||
return [
|
||||
'error' => [
|
||||
'class' => \yii\web\ErrorAction::class,
|
||||
],
|
||||
'captcha' => [
|
||||
'class' => \yii\captcha\CaptchaAction::class,
|
||||
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays homepage.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionIndex()
|
||||
{
|
||||
return $this->render('index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs in a user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogin()
|
||||
{
|
||||
if (!Yii::$app->user->isGuest) {
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
$model = new LoginForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->login()) {
|
||||
return $this->goBack();
|
||||
}
|
||||
|
||||
$model->password = '';
|
||||
|
||||
return $this->render('login', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out the current user.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionLogout()
|
||||
{
|
||||
Yii::$app->user->logout();
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs user up.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionSignup()
|
||||
{
|
||||
$model = new SignupForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->signup()) {
|
||||
Yii::$app->session->setFlash('success', 'Thank you for registration! Snap your first meal.');
|
||||
return $this->response->redirect(['meal/create']);
|
||||
}
|
||||
|
||||
return $this->render('signup', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
public function actionWebhook()
|
||||
{
|
||||
Yii::$app->response->format = Response::FORMAT_JSON;
|
||||
|
||||
if (Yii::$app->request->isHead) {
|
||||
Yii::$app->response->statusCode = 200;
|
||||
return Yii::$app->response->send();
|
||||
}
|
||||
|
||||
/** @var SonarApiComponent $api */
|
||||
$api = Yii::$app->sonar;
|
||||
$object = json_decode(Yii::$app->request->getRawBody());
|
||||
|
||||
return $api->storeInvoice($api->getInvoice($object->object_id));
|
||||
}
|
||||
|
||||
|
||||
// @todo
|
||||
// fix deployment script
|
||||
// save local .env variables for deployment
|
||||
// verify email is working
|
||||
// fix user sales agent issue
|
||||
/**
|
||||
* Requests password reset.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionRequestPasswordReset()
|
||||
{
|
||||
$model = new PasswordResetRequestForm();
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
|
||||
if ($model->sendEmail()) {
|
||||
Yii::$app->session->setFlash('success', 'Please check your email for further instructions.');
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
// Keep the same message as to not leak any data with users
|
||||
Yii::$app->session->setFlash('success', 'Please check your email for further instructions.');
|
||||
}
|
||||
|
||||
return $this->render('requestPasswordResetToken', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets password.
|
||||
*
|
||||
* @param string $token
|
||||
* @return mixed
|
||||
* @throws BadRequestHttpException
|
||||
*/
|
||||
public function actionResetPassword($token)
|
||||
{
|
||||
try {
|
||||
$model = new ResetPasswordForm($token);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
|
||||
if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->resetPassword()) {
|
||||
|
||||
$uaInfo = \donatj\UserAgent\parse_user_agent();
|
||||
|
||||
Yii::$app->queue->push(new EmailJob([
|
||||
'templateAlias' => EmailJob::PASSWORD_HAS_BEEN_RESET,
|
||||
'email' => $model->email,
|
||||
'templateModel' => [
|
||||
'name' => $model->first_name,
|
||||
"operating_system" => $uaInfo[PLATFORM],
|
||||
"browser_name" => $uaInfo[BROWSER],
|
||||
]
|
||||
]));
|
||||
Yii::$app->session->setFlash('success', 'New password saved.');
|
||||
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
return $this->render('resetPassword', [
|
||||
'model' => $model,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify email address
|
||||
*
|
||||
* @param string $token
|
||||
* @throws BadRequestHttpException
|
||||
* @return yii\web\Response
|
||||
*/
|
||||
public function actionVerifyEmail($token)
|
||||
{
|
||||
try {
|
||||
$model = new VerifyEmailForm($token);
|
||||
} catch (InvalidArgumentException $e) {
|
||||
throw new BadRequestHttpException($e->getMessage());
|
||||
}
|
||||
if ($model->verifyEmail()) {
|
||||
Yii::$app->session->setFlash('success', 'Your email has been confirmed! Upon our approval you will receive a welcome email.');
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
Yii::$app->session->setFlash('error', 'Sorry, we are unable to verify your account with provided token.');
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resend verification email
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function actionResendVerificationEmail()
|
||||
{
|
||||
$model = new ResendVerificationEmailForm();
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
$model->sendEmail();
|
||||
Yii::$app->session->setFlash('success', 'Check your email for further instructions.');
|
||||
return $this->goHome();
|
||||
}
|
||||
|
||||
return $this->render('resendVerificationEmail', [
|
||||
'model' => $model
|
||||
]);
|
||||
}
|
||||
}
|
||||
61
frontend/models/ContactForm.php
Normal file
61
frontend/models/ContactForm.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\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([Yii::$app->params['senderEmail'] => Yii::$app->params['senderName']])
|
||||
->setReplyTo([$this->email => $this->name])
|
||||
->setSubject($this->subject)
|
||||
->setTextBody($this->body)
|
||||
->send();
|
||||
}
|
||||
}
|
||||
82
frontend/models/PasswordResetRequestForm.php
Normal file
82
frontend/models/PasswordResetRequestForm.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use common\jobs\EmailJob;
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\User;
|
||||
|
||||
use const donatj\UserAgent\BROWSER;
|
||||
use const donatj\UserAgent\PLATFORM;
|
||||
|
||||
/**
|
||||
* Password reset request form
|
||||
*/
|
||||
class PasswordResetRequestForm extends Model
|
||||
{
|
||||
public $email;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['email', 'trim'],
|
||||
['email', 'required'],
|
||||
['email', 'email'],
|
||||
['email', 'exist',
|
||||
'targetClass' => '\common\models\User',
|
||||
'filter' => ['status' => User::STATUS_ACTIVE],
|
||||
'message' => 'There is no user with this email address.'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends an email with a link, for resetting the password.
|
||||
*
|
||||
* @return bool whether the email was send
|
||||
*/
|
||||
public function sendEmail()
|
||||
{
|
||||
/* @var $user User */
|
||||
$user = User::findOne([
|
||||
'status' => User::STATUS_ACTIVE,
|
||||
'email' => $this->email,
|
||||
]);
|
||||
|
||||
if (!$user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!User::isPasswordResetTokenValid($user->password_reset_token)) {
|
||||
$user->generatePasswordResetToken();
|
||||
if (!$user->save()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$uaInfo = \donatj\UserAgent\parse_user_agent();
|
||||
} catch (\Exception $e) {
|
||||
$uaInfo[PLATFORM] = 'unknown';
|
||||
$uaInfo[BROWSER] = 'unknown';
|
||||
}
|
||||
|
||||
Yii::$app->queue->push(new EmailJob([
|
||||
'templateAlias' => EmailJob::PASSWORD_RESET,
|
||||
'email' => $this->email,
|
||||
'templateModel' => [
|
||||
'name' => $user->first_name,
|
||||
"operating_system" => $uaInfo[PLATFORM],
|
||||
"action_url" => Yii::$app->urlManager->createAbsoluteUrl(['site/reset-password', 'token' => $user->password_reset_token]),
|
||||
"browser_name" => $uaInfo[BROWSER],
|
||||
]
|
||||
]));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
63
frontend/models/ResendVerificationEmailForm.php
Normal file
63
frontend/models/ResendVerificationEmailForm.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use common\jobs\EmailJob;
|
||||
use Yii;
|
||||
use common\models\User;
|
||||
use yii\base\Model;
|
||||
|
||||
class ResendVerificationEmailForm extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $email;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['email', 'trim'],
|
||||
['email', 'required'],
|
||||
['email', 'email'],
|
||||
['email', 'exist',
|
||||
'targetClass' => '\common\models\User',
|
||||
'filter' => ['status' => User::STATUS_UNVERIFIED],
|
||||
'message' => 'There is no user with this email address.'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends confirmation email to user
|
||||
*
|
||||
* @return bool whether the email was sent
|
||||
*/
|
||||
public function sendEmail()
|
||||
{
|
||||
$user = User::findOne([
|
||||
'email' => $this->email,
|
||||
'status' => User::STATUS_UNVERIFIED
|
||||
]);
|
||||
|
||||
if ($user === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Yii::$app->queue->push(new EmailJob([
|
||||
'templateAlias' => EmailJob::VERIFY_EMAIL,
|
||||
'email' => $user->email,
|
||||
'templateModel' => [
|
||||
'name' => $user->first_name,
|
||||
"action_url" => Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]),
|
||||
]
|
||||
]));
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
73
frontend/models/ResetPasswordForm.php
Normal file
73
frontend/models/ResetPasswordForm.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use yii\base\InvalidArgumentException;
|
||||
use yii\base\Model;
|
||||
use Yii;
|
||||
use common\models\User;
|
||||
|
||||
/**
|
||||
* Password reset form
|
||||
*/
|
||||
class ResetPasswordForm extends Model
|
||||
{
|
||||
public $password;
|
||||
|
||||
/**
|
||||
* @var \common\models\User
|
||||
*/
|
||||
private $_user;
|
||||
public $email;
|
||||
public $first_name;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a form model given a token.
|
||||
*
|
||||
* @param string $token
|
||||
* @param array $config name-value pairs that will be used to initialize the object properties
|
||||
* @throws InvalidArgumentException if token is empty or not valid
|
||||
*/
|
||||
public function __construct($token, $config = [])
|
||||
{
|
||||
if (empty($token) || !is_string($token)) {
|
||||
throw new InvalidArgumentException('Password reset token cannot be blank.');
|
||||
}
|
||||
$this->_user = User::findByPasswordResetToken($token);
|
||||
if (!$this->_user) {
|
||||
throw new InvalidArgumentException('Wrong password reset token.');
|
||||
}
|
||||
|
||||
$this->email = $this->_user->email;
|
||||
$this->first_name = $this->_user->first_name;
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
['password', 'required'],
|
||||
['password', 'string', 'min' => Yii::$app->params['user.passwordMinLength']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets password.
|
||||
*
|
||||
* @return bool if password was reset.
|
||||
*/
|
||||
public function resetPassword()
|
||||
{
|
||||
$user = $this->_user;
|
||||
$user->setPassword($this->password);
|
||||
$user->removePasswordResetToken();
|
||||
$user->generateAuthKey();
|
||||
|
||||
return $user->save(false);
|
||||
}
|
||||
}
|
||||
82
frontend/models/SignupForm.php
Normal file
82
frontend/models/SignupForm.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Model;
|
||||
use common\models\User;
|
||||
use common\jobs\EmailJob;
|
||||
|
||||
|
||||
/**
|
||||
* Signup form
|
||||
*/
|
||||
class SignupForm extends Model
|
||||
{
|
||||
public $first_name;
|
||||
public $email;
|
||||
public $password;
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['email','first_name'], 'trim'],
|
||||
[['email','first_name'], 'required'],
|
||||
['email', 'email'],
|
||||
['email', 'string', 'max' => 255],
|
||||
['email', 'unique', 'targetClass' => User::class, 'message' => 'This email address has already been taken.'],
|
||||
['password', 'required'],
|
||||
['password', 'string', 'min' => Yii::$app->params['user.passwordMinLength']],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Signs user up.
|
||||
*
|
||||
* @return bool whether the creating new account was successful and email was sent
|
||||
*/
|
||||
public function signup()
|
||||
{
|
||||
if (!$this->validate()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user = new User();
|
||||
$user->email = $this->email;
|
||||
$user->first_name = $this->first_name;
|
||||
$user->setPassword($this->password);
|
||||
$user->generateAuthKey();
|
||||
$user->generateEmailVerificationToken();
|
||||
$user->save(false);
|
||||
|
||||
// the following three lines were added:
|
||||
$auth = \Yii::$app->authManager;
|
||||
$salesAgentRole = $auth->getRole('user');
|
||||
$auth->assign($salesAgentRole, $user->getId());
|
||||
|
||||
return $this->sendEmail($user);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends confirmation email to user
|
||||
* @param User $user user model to with email should be send
|
||||
* @return bool whether the email was sent
|
||||
*/
|
||||
protected function sendEmail($user)
|
||||
{
|
||||
Yii::$app->queue->push(new EmailJob([
|
||||
'templateAlias' => EmailJob::VERIFY_EMAIL,
|
||||
'email' => $user->email,
|
||||
'templateModel' => [
|
||||
"name" => $user->first_name,
|
||||
"action_url" => Yii::$app->urlManager->createAbsoluteUrl(['site/verify-email', 'token' => $user->verification_token]),
|
||||
]
|
||||
]));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
65
frontend/models/VerifyEmailForm.php
Normal file
65
frontend/models/VerifyEmailForm.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\models;
|
||||
|
||||
use common\jobs\EmailJob;
|
||||
use common\models\User;
|
||||
use Yii;
|
||||
use yii\base\InvalidArgumentException;
|
||||
use yii\base\Model;
|
||||
|
||||
class VerifyEmailForm extends Model
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* @var User
|
||||
*/
|
||||
private $_user;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a form model with given token.
|
||||
*
|
||||
* @param string $token
|
||||
* @param array $config name-value pairs that will be used to initialize the object properties
|
||||
* @throws InvalidArgumentException if token is empty or not valid
|
||||
*/
|
||||
public function __construct($token, array $config = [])
|
||||
{
|
||||
if (empty($token) || !is_string($token)) {
|
||||
throw new InvalidArgumentException('Verify email token cannot be blank.');
|
||||
}
|
||||
$this->_user = User::findByVerificationToken($token);
|
||||
if (!$this->_user) {
|
||||
throw new InvalidArgumentException('Wrong verify email token.');
|
||||
}
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify email
|
||||
*
|
||||
* @return User|null the saved model or null if saving fails
|
||||
*/
|
||||
public function verifyEmail()
|
||||
{
|
||||
$user = $this->_user;
|
||||
$user->status = User::STATUS_VERIFIED;
|
||||
|
||||
Yii::$app->queue->push(new EmailJob([
|
||||
'templateAlias' => EmailJob::ADMIN_NOTIFY,
|
||||
"email" => Yii::$app->params['adminEmail'],
|
||||
'templateModel' => [
|
||||
"user_name" => $user->email,
|
||||
"action_url" => Yii::$app->urlManager->createAbsoluteUrl(['user/update', 'id' => $user->id, 'approve' => 1]),
|
||||
"action_edit_url" => Yii::$app->urlManager->createAbsoluteUrl(['user/update', 'id' => $user->id]),
|
||||
]
|
||||
]));
|
||||
|
||||
return $user->save(false) ? $user : null;
|
||||
}
|
||||
}
|
||||
2
frontend/runtime/.gitignore
vendored
Normal file
2
frontend/runtime/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
10
frontend/tests/_bootstrap.php
Normal file
10
frontend/tests/_bootstrap.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
defined('YII_DEBUG') or define('YII_DEBUG', true);
|
||||
defined('YII_ENV') or define('YII_ENV', 'test');
|
||||
defined('YII_APP_BASE_PATH') or define('YII_APP_BASE_PATH', __DIR__.'/../../');
|
||||
|
||||
require_once YII_APP_BASE_PATH . '/vendor/autoload.php';
|
||||
require_once YII_APP_BASE_PATH . '/vendor/yiisoft/yii2/Yii.php';
|
||||
require_once YII_APP_BASE_PATH . '/common/config/bootstrap.php';
|
||||
require_once __DIR__ . '/../config/bootstrap.php';
|
||||
26
frontend/tests/_data/login_data.php
Normal file
26
frontend/tests/_data/login_data.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'auth_key' => 'tUu1qHcde0diwUol3xeI-18MuHkkprQI',
|
||||
// password_0
|
||||
'password_hash' => '$2y$13$nJ1WDlBaGcbCdbNC5.5l4.sgy.OMEKCqtDQOdQ2OWpgiKRWYyzzne',
|
||||
'password_reset_token' => 'RkD_Jw0_8HEedzLk7MM-ZKEFfYR7VbMr_1392559490',
|
||||
'created_at' => '1392559490',
|
||||
'status' => '1',
|
||||
'updated_at' => '1392559490',
|
||||
'email' => 'sfriesen@jenkins.info',
|
||||
'first_name' => 'sfriesen',
|
||||
],
|
||||
[
|
||||
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
// Test1234
|
||||
'password_hash' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
'email' => 'test@mail.com',
|
||||
'first_name' => 'test',
|
||||
'status' => '9',
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
|
||||
],
|
||||
];
|
||||
46
frontend/tests/_data/user.php
Normal file
46
frontend/tests/_data/user.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
[
|
||||
'auth_key' => 'iwTNae9t34OmnK6l4vT4IeaTk-YWI2Rv',
|
||||
'password_hash' => '$2y$13$CXT0Rkle1EMJ/c1l5bylL.EylfmQ39O5JlHJVFpNn618OUS1HwaIi',
|
||||
'password_reset_token' => 't5GU9NwpuGYSfb7FEZMAxqtuz2PkEvv_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'first_name' => 'mister dude',
|
||||
'email' => 'brady.renner@rutherford.com',
|
||||
'status' => 1,
|
||||
],
|
||||
[
|
||||
'auth_key' => 'EdKfXrx88weFMV0vIxuTMWKgfK2tS3Lp',
|
||||
'password_hash' => '$2y$13$g5nv41Px7VBqhS3hVsVN2.MKfgT3jFdkXEsMC4rQJLfaMa7VaJqL2',
|
||||
'password_reset_token' => '4BSNyiZNAuxjs5Mty990c47sVrgllIi_' . time(),
|
||||
'created_at' => '1391885313',
|
||||
'updated_at' => '1391885313',
|
||||
'first_name' => 'already taken',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'status' => '0',
|
||||
],
|
||||
[
|
||||
'auth_key' => 'O87GkY3_UfmMHYkyezZ7QLfmkKNsllzT',
|
||||
//Test1234
|
||||
'first_name' => 'test.test',
|
||||
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
|
||||
'email' => 'test@mail.com',
|
||||
'status' => 10,
|
||||
'sales_agent_id' => 0,
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330',
|
||||
],
|
||||
[
|
||||
'auth_key' => '4XXdVqi3rDpa_a6JH6zqVreFxUPcUPvJ',
|
||||
//Test1234
|
||||
'password_hash' => '$2y$13$d17z0w/wKC4LFwtzBcmx6up4jErQuandJqhzKGKczfWuiEhLBtQBK',
|
||||
'email' => 'test2@mail.com',
|
||||
'status' => '10',
|
||||
'created_at' => '1548675330',
|
||||
'updated_at' => '1548675330',
|
||||
'verification_token' => 'already_used_token_1548675330',
|
||||
],
|
||||
];
|
||||
2
frontend/tests/_output/.gitignore
vendored
Normal file
2
frontend/tests/_output/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
1
frontend/tests/_support/.gitignore
vendored
Normal file
1
frontend/tests/_support/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
_generated
|
||||
34
frontend/tests/_support/FunctionalTester.php
Normal file
34
frontend/tests/_support/FunctionalTester.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void verify($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class FunctionalTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\FunctionalTesterActions;
|
||||
|
||||
|
||||
public function seeValidationError($message)
|
||||
{
|
||||
$this->see($message, '.invalid-feedback');
|
||||
}
|
||||
|
||||
public function dontSeeValidationError($message)
|
||||
{
|
||||
$this->dontSee($message, '.invalid-feedback');
|
||||
}
|
||||
}
|
||||
26
frontend/tests/_support/UnitTester.php
Normal file
26
frontend/tests/_support/UnitTester.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests;
|
||||
|
||||
/**
|
||||
* Inherited Methods
|
||||
* @method void wantToTest($text)
|
||||
* @method void wantTo($text)
|
||||
* @method void execute($callable)
|
||||
* @method void expectTo($prediction)
|
||||
* @method void verify($prediction)
|
||||
* @method void amGoingTo($argumentation)
|
||||
* @method void am($role)
|
||||
* @method void lookForwardTo($achieveValue)
|
||||
* @method void comment($description)
|
||||
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
|
||||
*
|
||||
* @SuppressWarnings(PHPMD)
|
||||
*/
|
||||
class UnitTester extends \Codeception\Actor
|
||||
{
|
||||
use _generated\UnitTesterActions;
|
||||
/**
|
||||
* Define custom actions here
|
||||
*/
|
||||
}
|
||||
9
frontend/tests/acceptance.suite.yml.example
Normal file
9
frontend/tests/acceptance.suite.yml.example
Normal file
@@ -0,0 +1,9 @@
|
||||
suite_namespace: frontend\tests\acceptance
|
||||
actor: AcceptanceTester
|
||||
modules:
|
||||
enabled:
|
||||
- WebDriver:
|
||||
url: http://localhost:8080
|
||||
browser: firefox
|
||||
- Yii2:
|
||||
part: init
|
||||
21
frontend/tests/acceptance/HomeCest.php
Normal file
21
frontend/tests/acceptance/HomeCest.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\acceptance;
|
||||
|
||||
use frontend\tests\AcceptanceTester;
|
||||
use yii\helpers\Url;
|
||||
|
||||
class HomeCest
|
||||
{
|
||||
public function checkHome(AcceptanceTester $I)
|
||||
{
|
||||
$I->amOnRoute(Url::toRoute('/site/index'));
|
||||
$I->see('My Application');
|
||||
|
||||
$I->seeLink('About');
|
||||
$I->click('About');
|
||||
$I->wait(2); // wait for page to be opened
|
||||
|
||||
$I->see('This is the About page.');
|
||||
}
|
||||
}
|
||||
16
frontend/tests/acceptance/_bootstrap.php
Normal file
16
frontend/tests/acceptance/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Cepts.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Cept
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
7
frontend/tests/functional.suite.yml
Normal file
7
frontend/tests/functional.suite.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
suite_namespace: frontend\tests\functional
|
||||
actor: FunctionalTester
|
||||
modules:
|
||||
enabled:
|
||||
- Filesystem
|
||||
- Yii2
|
||||
- Asserts
|
||||
67
frontend/tests/functional/LoginCest.php
Normal file
67
frontend/tests/functional/LoginCest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
class LoginCest
|
||||
{
|
||||
protected $formId = '#login-form';
|
||||
/**
|
||||
* Load fixtures before db transaction begin
|
||||
* Called in _before()
|
||||
* @see \Codeception\Module\Yii2::_before()
|
||||
* @see \Codeception\Module\Yii2::loadFixtures()
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'login_data.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/login');
|
||||
}
|
||||
|
||||
protected function formParams($login, $password)
|
||||
{
|
||||
return [
|
||||
'LoginForm[email]' => $login,
|
||||
'LoginForm[password]' => $password,
|
||||
];
|
||||
}
|
||||
|
||||
public function checkEmpty(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('', ''));
|
||||
$I->seeValidationError('Email cannot be blank.');
|
||||
$I->seeValidationError('Password cannot be blank.');
|
||||
}
|
||||
|
||||
public function checkWrongPassword(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm('#login-form', $this->formParams('admin', 'wrong'));
|
||||
$I->seeValidationError('Incorrect email or password.');
|
||||
}
|
||||
|
||||
public function checkInactiveAccount(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('test@mail.com', 'Test1234'));
|
||||
$I->seeValidationError('Incorrect email or password');
|
||||
}
|
||||
|
||||
public function checkValidLogin(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('sfriesen@jenkins.info', 'password_0'));
|
||||
$I->see('Logout (sfriesen@jenkins.info)', 'form button[type=submit]');
|
||||
$I->dontSeeLink('Login');
|
||||
$I->dontSeeLink('Signup');
|
||||
}
|
||||
}
|
||||
53
frontend/tests/functional/ResendVerificationEmailCest.php
Normal file
53
frontend/tests/functional/ResendVerificationEmailCest.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
use common\fixtures\UserFixture;
|
||||
|
||||
class ResendVerificationEmailCest
|
||||
{
|
||||
protected $formId = '#resend-verification-email-form';
|
||||
|
||||
|
||||
/**
|
||||
* Load fixtures before db transaction begin
|
||||
* Called in _before()
|
||||
* @see \Codeception\Module\Yii2::_before()
|
||||
* @see \Codeception\Module\Yii2::loadFixtures()
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/resend-verification-email');
|
||||
}
|
||||
|
||||
protected function formParams($email)
|
||||
{
|
||||
return [
|
||||
'ResendVerificationEmailForm[email]' => $email
|
||||
];
|
||||
}
|
||||
|
||||
public function checkPage(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Resend verification email', 'h1');
|
||||
$I->see('Please fill out your email. A verification email will be sent there.');
|
||||
}
|
||||
|
||||
public function checkSendSuccessfully(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, $this->formParams('test@mail.com'));
|
||||
$I->see('Check your email for further instructions.');
|
||||
}
|
||||
}
|
||||
57
frontend/tests/functional/SignupCest.php
Normal file
57
frontend/tests/functional/SignupCest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class SignupCest
|
||||
{
|
||||
protected $formId = '#form-signup';
|
||||
|
||||
|
||||
public function _before(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/signup');
|
||||
}
|
||||
|
||||
public function signupWithEmptyFields(FunctionalTester $I)
|
||||
{
|
||||
$I->see('Signup', 'h1');
|
||||
$I->see('Please fill out the following fields to signup:');
|
||||
$I->submitForm($this->formId, []);
|
||||
$I->seeValidationError('First Name cannot be blank.');
|
||||
$I->seeValidationError('Email cannot be blank.');
|
||||
$I->seeValidationError('Password cannot be blank.');
|
||||
}
|
||||
|
||||
public function signupWithWrongEmail(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm(
|
||||
$this->formId, [
|
||||
'SignupForm[first_name]' => 'tester',
|
||||
'SignupForm[email]' => 'ttttt',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]
|
||||
);
|
||||
$I->dontSee('First Name cannot be blank.', '.invalid-feedback');
|
||||
$I->dontSee('Password cannot be blank.', '.invalid-feedback');
|
||||
$I->see('Email is not a valid email address.', '.invalid-feedback');
|
||||
}
|
||||
|
||||
public function signupSuccessfully(FunctionalTester $I)
|
||||
{
|
||||
$I->submitForm($this->formId, [
|
||||
'SignupForm[first_name]' => 'tester',
|
||||
'SignupForm[email]' => 'tester.email@example.com',
|
||||
'SignupForm[password]' => 'tester_password',
|
||||
]);
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'first_name' => 'tester',
|
||||
'email' => 'tester.email@example.com',
|
||||
'status' => \common\models\User::STATUS_UNVERIFIED
|
||||
]);
|
||||
|
||||
$I->see('Thank you for registration. Please check your email for further instructions');
|
||||
}
|
||||
}
|
||||
59
frontend/tests/functional/VerifyEmailCest.php
Normal file
59
frontend/tests/functional/VerifyEmailCest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\functional;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\tests\FunctionalTester;
|
||||
|
||||
class VerifyEmailCest
|
||||
{
|
||||
/**
|
||||
* Load fixtures before db transaction begin
|
||||
* Called in _before()
|
||||
* @see \Codeception\Module\Yii2::_before()
|
||||
* @see \Codeception\Module\Yii2::loadFixtures()
|
||||
* @return array
|
||||
*/
|
||||
public function _fixtures()
|
||||
{
|
||||
return [
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function checkEmptyToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => '']);
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Verify email token cannot be blank.');
|
||||
}
|
||||
|
||||
public function checkInvalidToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => 'wrong_token']);
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Wrong verify email token.');
|
||||
}
|
||||
|
||||
public function checkNoToken(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email');
|
||||
$I->canSee('Bad Request', 'h1');
|
||||
$I->canSee('Missing required parameters: token');
|
||||
}
|
||||
|
||||
public function checkSuccessVerification(FunctionalTester $I)
|
||||
{
|
||||
$I->amOnRoute('site/verify-email', ['token' => '4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330']);
|
||||
$I->canSee('Your email has been confirmed! Upon our approval you will receive a welcome email.');
|
||||
$I->canSee('Sales Agent Portal', 'h1');
|
||||
|
||||
$I->seeRecord('common\models\User', [
|
||||
'email' => 'test@mail.com',
|
||||
'status' => \common\models\User::STATUS_VERIFIED
|
||||
]);
|
||||
}
|
||||
}
|
||||
16
frontend/tests/functional/_bootstrap.php
Normal file
16
frontend/tests/functional/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Cests.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Cests
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
7
frontend/tests/unit.suite.yml
Normal file
7
frontend/tests/unit.suite.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
suite_namespace: frontend\tests\unit
|
||||
actor: UnitTester
|
||||
modules:
|
||||
enabled:
|
||||
- Yii2:
|
||||
part: [orm, email, fixtures]
|
||||
- Asserts
|
||||
16
frontend/tests/unit/_bootstrap.php
Normal file
16
frontend/tests/unit/_bootstrap.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
/**
|
||||
* Here you can initialize variables via \Codeception\Util\Fixtures class
|
||||
* to store data in global array and use it in Tests.
|
||||
*
|
||||
* ```php
|
||||
* // Here _bootstrap.php
|
||||
* \Codeception\Util\Fixtures::add('user1', ['name' => 'davert']);
|
||||
* ```
|
||||
*
|
||||
* In Tests
|
||||
*
|
||||
* ```php
|
||||
* \Codeception\Util\Fixtures::get('user1');
|
||||
* ```
|
||||
*/
|
||||
55
frontend/tests/unit/models/PasswordResetRequestFormTest.php
Normal file
55
frontend/tests/unit/models/PasswordResetRequestFormTest.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use Yii;
|
||||
use frontend\models\PasswordResetRequestForm;
|
||||
use common\fixtures\UserFixture as UserFixture;
|
||||
use common\models\User;
|
||||
|
||||
class PasswordResetRequestFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testSendMessageWithWrongEmailAddress()
|
||||
{
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = 'not-existing-email@example.com';
|
||||
verify($model->sendEmail())->true();
|
||||
}
|
||||
|
||||
public function testNotSendEmailsToInactiveUser()
|
||||
{
|
||||
$user = $this->tester->grabFixture('user', 1);
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $user['email'];
|
||||
// this is true because we do not want to display messages such as "email does not exist"
|
||||
verify($model->sendEmail())->true();
|
||||
}
|
||||
|
||||
public function testSendEmailSuccessfully()
|
||||
{
|
||||
$userFixture = $this->tester->grabFixture('user', 0);
|
||||
|
||||
$model = new PasswordResetRequestForm();
|
||||
$model->email = $userFixture['email'];
|
||||
$user = User::findOne(['password_reset_token' => $userFixture['password_reset_token']]);
|
||||
|
||||
verify($model->sendEmail())->notEmpty();
|
||||
verify($user->password_reset_token)->notEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
|
||||
use Codeception\Test\Unit;
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\models\ResendVerificationEmailForm;
|
||||
|
||||
class ResendVerificationEmailFormTest extends Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testWrongEmailAddress()
|
||||
{
|
||||
$model = new ResendVerificationEmailForm();
|
||||
$model->attributes = [
|
||||
'email' => 'aaa@bbb.cc'
|
||||
];
|
||||
|
||||
verify($model->validate())->false();
|
||||
verify($model->hasErrors())->true();
|
||||
verify($model->getFirstError('email'))->equals('There is no user with this email address.');
|
||||
}
|
||||
|
||||
public function testEmptyEmailAddress()
|
||||
{
|
||||
$model = new ResendVerificationEmailForm();
|
||||
$model->attributes = [
|
||||
'email' => ''
|
||||
];
|
||||
|
||||
verify($model->validate())->false();
|
||||
verify($model->hasErrors())->true();
|
||||
verify($model->getFirstError('email'))->equals('Email cannot be blank.');
|
||||
}
|
||||
|
||||
public function testResendToActiveUser()
|
||||
{
|
||||
$model = new ResendVerificationEmailForm();
|
||||
$model->attributes = [
|
||||
'email' => 'test2@mail.com'
|
||||
];
|
||||
|
||||
verify($model->validate())->true();
|
||||
}
|
||||
|
||||
public function testSuccessfullyResend()
|
||||
{
|
||||
$model = new ResendVerificationEmailForm();
|
||||
$model->attributes = [
|
||||
'email' => 'test@mail.com'
|
||||
];
|
||||
|
||||
verify($model->validate())->true();
|
||||
verify($model->hasErrors())->false();
|
||||
|
||||
verify($model->sendEmail())->true();
|
||||
|
||||
}
|
||||
}
|
||||
45
frontend/tests/unit/models/ResetPasswordFormTest.php
Normal file
45
frontend/tests/unit/models/ResetPasswordFormTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\models\ResetPasswordForm;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class ResetPasswordFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function testResetWrongToken()
|
||||
{
|
||||
$this->tester->expectThrowable('yii\base\InvalidArgumentException', function() {
|
||||
new ResetPasswordForm('');
|
||||
});
|
||||
|
||||
$this->tester->expectThrowable('yii\base\InvalidArgumentException', function() {
|
||||
new ResetPasswordForm('notexistingtoken_1391882543');
|
||||
});
|
||||
}
|
||||
|
||||
public function testResetCorrectToken()
|
||||
{
|
||||
$user = $this->tester->grabFixture('user', 0);
|
||||
$form = new ResetPasswordForm($user['password_reset_token']);
|
||||
verify($form->resetPassword())->notEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
60
frontend/tests/unit/models/SignupFormTest.php
Normal file
60
frontend/tests/unit/models/SignupFormTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\models\SignupForm;
|
||||
|
||||
class SignupFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testCorrectSignup()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'first_name' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
$user = $model->signup();
|
||||
verify($user)->notEmpty();
|
||||
|
||||
/** @var \common\models\User $user */
|
||||
$user = $this->tester->grabRecord('common\models\User', [
|
||||
'first_name' => 'some_username',
|
||||
'email' => 'some_email@example.com',
|
||||
'status' => \common\models\User::STATUS_UNVERIFIED
|
||||
]);
|
||||
}
|
||||
|
||||
public function testEmailAlreadySignedUp()
|
||||
{
|
||||
$model = new SignupForm([
|
||||
'first_name' => 'troy.becker',
|
||||
'email' => 'nicolas.dianna@hotmail.com',
|
||||
'password' => 'some_password',
|
||||
]);
|
||||
|
||||
verify($model->signup())->empty();
|
||||
verify($model->getErrors('first_name'))->empty();
|
||||
verify($model->getErrors('email'))->notEmpty();
|
||||
|
||||
verify($model->getFirstError('email'))
|
||||
->equals('This email address has already been taken.');
|
||||
}
|
||||
}
|
||||
48
frontend/tests/unit/models/VerifyEmailFormTest.php
Normal file
48
frontend/tests/unit/models/VerifyEmailFormTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace frontend\tests\unit\models;
|
||||
|
||||
use common\fixtures\UserFixture;
|
||||
use frontend\models\VerifyEmailForm;
|
||||
|
||||
class VerifyEmailFormTest extends \Codeception\Test\Unit
|
||||
{
|
||||
/**
|
||||
* @var \frontend\tests\UnitTester
|
||||
*/
|
||||
protected $tester;
|
||||
|
||||
|
||||
public function _before()
|
||||
{
|
||||
$this->tester->haveFixtures([
|
||||
'user' => [
|
||||
'class' => UserFixture::class,
|
||||
'dataFile' => codecept_data_dir() . 'user.php'
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
public function testVerifyWrongToken()
|
||||
{
|
||||
$this->tester->expectThrowable('\yii\base\InvalidArgumentException', function() {
|
||||
new VerifyEmailForm('');
|
||||
});
|
||||
|
||||
$this->tester->expectThrowable('\yii\base\InvalidArgumentException', function() {
|
||||
new VerifyEmailForm('notexistingtoken_1391882543');
|
||||
});
|
||||
}
|
||||
|
||||
public function testVerifyCorrectToken()
|
||||
{
|
||||
$model = new VerifyEmailForm('4ch0qbfhvWwkcuWqjN8SWRq72SOw1KYT_1548675330');
|
||||
$user = $model->verifyEmail();
|
||||
verify($user)->instanceOf('common\models\User');
|
||||
|
||||
verify($user->first_name)->equals('test.test');
|
||||
verify($user->email)->equals('test@mail.com');
|
||||
verify($user->status)->equals(\common\models\User::STATUS_VERIFIED);
|
||||
verify($user->validatePassword('Test1234'))->true();
|
||||
}
|
||||
}
|
||||
111
frontend/views/layouts/main.php
Normal file
111
frontend/views/layouts/main.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/** @var \yii\web\View $this */
|
||||
|
||||
/** @var string $content */
|
||||
|
||||
use common\widgets\Alert;
|
||||
use frontend\assets\AppAsset;
|
||||
use yii\bootstrap5\Breadcrumbs;
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\Nav;
|
||||
use yii\bootstrap5\NavBar;
|
||||
use yii\helpers\Url;
|
||||
|
||||
AppAsset::register($this);
|
||||
?>
|
||||
<?php
|
||||
$this->beginPage() ?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= Yii::$app->language ?>" class="h-100">
|
||||
<head>
|
||||
<meta charset="<?= Yii::$app->charset ?>">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<?php
|
||||
$this->registerCsrfMetaTags() ?>
|
||||
<title><?= Html::encode($this->title) ?></title>
|
||||
<?php $this->head() ?>
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
|
||||
</head>
|
||||
<body class="d-flex flex-column h-100">
|
||||
<?php
|
||||
$this->beginBody() ?>
|
||||
|
||||
<header>
|
||||
<?php
|
||||
NavBar::begin([
|
||||
'brandLabel' => Yii::$app->name,
|
||||
'brandUrl' => Yii::$app->homeUrl,
|
||||
'options' => [
|
||||
'class' => 'navbar navbar-expand-xxl navbar-dark bg-dark fixed-top navbar-fixed-50',
|
||||
],
|
||||
]);
|
||||
$menuItems = [];
|
||||
|
||||
if (!Yii::$app->user->isGuest) {
|
||||
$menuItems[] = [
|
||||
'label' => 'Meals',
|
||||
'url' => [Url::to(['meal/index'])],
|
||||
];
|
||||
$menuItems[] = [
|
||||
'label' => 'Summary',
|
||||
'url' => [Url::to(['summary'])],
|
||||
];
|
||||
}
|
||||
|
||||
echo Nav::widget([
|
||||
'options' => ['class' => 'navbar-nav me-auto'],
|
||||
'items' => $menuItems,
|
||||
]);
|
||||
if (Yii::$app->user->isGuest) {
|
||||
echo
|
||||
Html::a(
|
||||
'Signup',
|
||||
['/site/signup'],
|
||||
[
|
||||
'class' => ['btn btn-link login text-decoration-none'],
|
||||
]
|
||||
);
|
||||
echo
|
||||
Html::a(
|
||||
'Login',
|
||||
['/site/login'],
|
||||
[
|
||||
'class' => ['btn btn-link login text-decoration-none'],
|
||||
]
|
||||
);
|
||||
} else {
|
||||
echo Html::beginForm(['/site/logout'], 'post', ['class' => 'd-flex'])
|
||||
. Html::submitButton(
|
||||
'Logout (' . Yii::$app->user->identity->email . ')',
|
||||
['class' => 'btn btn-link logout text-decoration-none']
|
||||
)
|
||||
. Html::endForm();
|
||||
}
|
||||
NavBar::end();
|
||||
?>
|
||||
</header>
|
||||
|
||||
<main role="main" class="flex-shrink-0">
|
||||
<div class="container">
|
||||
<?= Breadcrumbs::widget([
|
||||
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
|
||||
]) ?>
|
||||
<?= Alert::widget() ?>
|
||||
<?= $content ?>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<footer class="footer mt-auto py-3 text-muted">
|
||||
<div class="container">
|
||||
<p class="float-start">© <?= Html::encode(Yii::$app->name) ?> <?= date('Y') ?></p>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
<?php
|
||||
$this->endBody() ?>
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
$this->endPage();
|
||||
39
frontend/views/meal/_form.php
Normal file
39
frontend/views/meal/_form.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Meal $model */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="meal-form">
|
||||
|
||||
<?php $form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'file_name')->textInput(['maxlength' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'calories')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'protein')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'fat')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'carbohydrates')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'fiber')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'meal')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'created_at')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'updated_at')->textInput() ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
20
frontend/views/meal/create.php
Normal file
20
frontend/views/meal/create.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Meal $model */
|
||||
|
||||
$this->title = 'Create Meal';
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Meals', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="meal-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
49
frontend/views/meal/index.php
Normal file
49
frontend/views/meal/index.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
use common\models\Meal;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\grid\ActionColumn;
|
||||
use yii\grid\GridView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\data\ActiveDataProvider $dataProvider */
|
||||
|
||||
$this->title = 'Meals';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="meal-index">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Create Meal', ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'columns' => [
|
||||
['class' => 'yii\grid\SerialColumn'],
|
||||
|
||||
'id',
|
||||
'file_name',
|
||||
'calories',
|
||||
'protein',
|
||||
'fat',
|
||||
//'carbohydrates',
|
||||
//'fiber',
|
||||
//'meal',
|
||||
//'created_at',
|
||||
//'updated_at',
|
||||
[
|
||||
'class' => ActionColumn::className(),
|
||||
'urlCreator' => function ($action, Meal $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
}
|
||||
],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
|
||||
</div>
|
||||
21
frontend/views/meal/update.php
Normal file
21
frontend/views/meal/update.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Meal $model */
|
||||
|
||||
$this->title = 'Update Meal: ' . $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Meals', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]];
|
||||
$this->params['breadcrumbs'][] = 'Update';
|
||||
?>
|
||||
<div class="meal-update">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
45
frontend/views/meal/view.php
Normal file
45
frontend/views/meal/view.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\Meal $model */
|
||||
|
||||
$this->title = $model->id;
|
||||
$this->params['breadcrumbs'][] = ['label' => 'Meals', 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
<div class="meal-view">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => 'Are you sure you want to delete this item?',
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
</p>
|
||||
|
||||
<?= DetailView::widget([
|
||||
'model' => $model,
|
||||
'attributes' => [
|
||||
'id',
|
||||
'file_name',
|
||||
'calories',
|
||||
'protein',
|
||||
'fat',
|
||||
'carbohydrates',
|
||||
'fiber',
|
||||
'meal',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
],
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
27
frontend/views/site/error.php
Normal file
27
frontend/views/site/error.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var string $name */
|
||||
/** @var string $message */
|
||||
/** @var Exception $exception */
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
$this->title = $name;
|
||||
?>
|
||||
<div class="site-error">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<div class="alert alert-danger">
|
||||
<?= nl2br(Html::encode($message)) ?>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
The above error occurred while the Web server was processing your request.
|
||||
</p>
|
||||
<p>
|
||||
Please contact us if you think this is a server error. Thank you.
|
||||
</p>
|
||||
|
||||
</div>
|
||||
43
frontend/views/site/index.php
Normal file
43
frontend/views/site/index.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
|
||||
$this->title = 'Sales Agent';
|
||||
?>
|
||||
|
||||
<div class="alert alert-info" role="info">
|
||||
👋 <i>Please note: This app provides estimated nutritional values. It is not a substitute for professional dietary advice.</i>
|
||||
</div>
|
||||
<div class="site-index">
|
||||
<div class="p-5 mb-4 bg-transparent rounded-3">
|
||||
<div class="container-fluid py-5 text-center">
|
||||
<h1 class="display-4">Calorie Ease</h1>
|
||||
<p class="fs-5 fw-light">Track your food with a picture!</p>
|
||||
<p>
|
||||
<a class="btn btn-lg btn-success" href="<?= Yii::$app->getUrlManager()->createUrl(['meal/create']) ?>">Log a meal</a>
|
||||
<a class="btn btn-lg btn-primary" href="<?= Yii::$app->getUrlManager()->createUrl(['summary']) ?>">View Summary</a></p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="body-content">
|
||||
<div class="row">
|
||||
<div class="col-lg-4">
|
||||
<h2><i class="bi bi-camera-video"></i> Upload Food Photos</h2>
|
||||
|
||||
<p>Easily upload photos of your meals and snacks. Our AI analyzes the images to provide estimated nutrition data.</p>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<h2><i class="bi bi-bar-chart-line"></i> Daily Nutrition Summary</h2>
|
||||
|
||||
<p>View a concise summary of your daily calorie, protein, fat, carbohydrate, and fiber intake. This helps track your progress and goals.</p>
|
||||
</div>
|
||||
<div class="col-lg-4">
|
||||
<h2><i class="bi bi-calendar-event"></i> Meal Logging & Tracking</h2>
|
||||
|
||||
<p>Effortlessly log your meals and snacks throughout the day. The app will automatically calculate your daily totals.</p>
|
||||
</div>
|
||||
</div>
|
||||
<p></p>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
55
frontend/views/site/login.php
Normal file
55
frontend/views/site/login.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\bootstrap5\ActiveForm $form */
|
||||
/** @var \common\models\LoginForm $model */
|
||||
|
||||
use yii\bootstrap5\Alert;
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
|
||||
$this->title = 'Login';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="site-login">
|
||||
<?php
|
||||
if (YII_ENV_DEV) {
|
||||
echo Alert::widget([
|
||||
'options' => [
|
||||
'class' => 'alert-success',
|
||||
],
|
||||
'body' => '<img src="/images/navi.png"> Hey! Listen! You can login with <strong>admin@example.com</strong> or <strong>user@example.com</strong> - both passwords are <strong>password</strong>',
|
||||
'closeButton' => false,
|
||||
]); ?>
|
||||
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>Please fill out the following fields to login:</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-5">
|
||||
<?php $form = ActiveForm::begin(['id' => 'login-form']); ?>
|
||||
|
||||
<?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
|
||||
|
||||
<?= $form->field($model, 'password')->passwordInput() ?>
|
||||
|
||||
<?= $form->field($model, 'rememberMe')->checkbox() ?>
|
||||
|
||||
<div class="my-1 mx-0" style="color:#999;">
|
||||
If you forgot your password you can <?= Html::a('reset it', ['site/request-password-reset']) ?>.
|
||||
<br>
|
||||
Need new verification email? <?= Html::a('Resend', ['site/resend-verification-email']) ?>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
31
frontend/views/site/requestPasswordResetToken.php
Normal file
31
frontend/views/site/requestPasswordResetToken.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\bootstrap5\ActiveForm $form */
|
||||
/** @var \frontend\models\PasswordResetRequestForm $model */
|
||||
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
|
||||
$this->title = 'Request password reset';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="site-request-password-reset">
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>Please fill out your email. A link to reset password will be sent there.</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-5">
|
||||
<?php $form = ActiveForm::begin(['id' => 'request-password-reset-form']); ?>
|
||||
|
||||
<?= $form->field($model, 'email')->textInput(['autofocus' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
31
frontend/views/site/resendVerificationEmail.php
Normal file
31
frontend/views/site/resendVerificationEmail.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View$this */
|
||||
/** @var yii\bootstrap5\ActiveForm $form */
|
||||
/** @var \frontend\models\ResetPasswordForm $model */
|
||||
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
|
||||
$this->title = 'Resend verification email';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="site-resend-verification-email">
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>Please fill out your email. A verification email will be sent there.</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-5">
|
||||
<?php $form = ActiveForm::begin(['id' => 'resend-verification-email-form']); ?>
|
||||
|
||||
<?= $form->field($model, 'email')->textInput(['autofocus' => true, 'data-1p-ignore' => '']) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Send', ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
31
frontend/views/site/resetPassword.php
Normal file
31
frontend/views/site/resetPassword.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\bootstrap5\ActiveForm $form */
|
||||
/** @var \frontend\models\ResetPasswordForm $model */
|
||||
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
|
||||
$this->title = 'Reset password';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="site-reset-password">
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>Please choose your new password:</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-5">
|
||||
<?php $form = ActiveForm::begin(['id' => 'reset-password-form']); ?>
|
||||
|
||||
<?= $form->field($model, 'password')->passwordInput(['autofocus' => true]) ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Save', ['class' => 'btn btn-primary']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
35
frontend/views/site/signup.php
Normal file
35
frontend/views/site/signup.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\bootstrap5\ActiveForm $form */
|
||||
/** @var \frontend\models\SignupForm $model */
|
||||
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
|
||||
$this->title = 'Signup';
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="site-signup">
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>Please fill out the following fields to signup:</p>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-5">
|
||||
<?php $form = ActiveForm::begin(['id' => 'form-signup']); ?>
|
||||
|
||||
<?= $form->field($model, 'first_name') ?>
|
||||
|
||||
<?= $form->field($model, 'email') ?>
|
||||
|
||||
<?= $form->field($model, 'password')->passwordInput() ?>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton('Signup', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
|
||||
</div>
|
||||
|
||||
<?php ActiveForm::end(); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
41
frontend/views/user/_form.php
Normal file
41
frontend/views/user/_form.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Html;
|
||||
use yii\bootstrap5\ActiveForm;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $model */
|
||||
/** @var array $salesAgents */
|
||||
/** @var yii\widgets\ActiveForm $form */
|
||||
?>
|
||||
|
||||
<div class="user-form">
|
||||
|
||||
<?php
|
||||
$form = ActiveForm::begin(); ?>
|
||||
|
||||
<?= $form->field($model, 'email')->textInput() ?>
|
||||
|
||||
<?= $form->field($model, 'status')->dropDownList($model->getStatusName(true)) ?>
|
||||
|
||||
<?= $form->field($model, 'role')->dropDownList(
|
||||
ArrayHelper::map(Yii::$app->authManager->getRoles(), 'name', 'name'),
|
||||
['prompt' => '-- Select role --']
|
||||
) ?>
|
||||
|
||||
<?= $form->field($model, 'sales_agent_id')->label(Yii::t('app', 'Sales Agent'))->dropDownList(
|
||||
$salesAgents,
|
||||
['prompt' => '-- Select Sales Agent --']
|
||||
) ?>
|
||||
|
||||
<br/>
|
||||
|
||||
<div class="form-group">
|
||||
<?= Html::submitButton(Yii::t('app', 'Save'), ['class' => 'btn btn-success']) ?>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
ActiveForm::end(); ?>
|
||||
|
||||
</div>
|
||||
24
frontend/views/user/create.php
Normal file
24
frontend/views/user/create.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $model */
|
||||
/** @var array $salesAgents */
|
||||
|
||||
$this->title = Yii::t('app', 'Create User');
|
||||
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Users'), 'url' => ['index']];
|
||||
$this->params['breadcrumbs'][] = $this->title;
|
||||
?>
|
||||
<div class="user-create">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>A new password will be emailed to the user upon creation. The user will not need to validate their email address.</p>
|
||||
<p>If you want them to validate their email, have them sign up on the home page.</p>
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'salesAgents' => $salesAgents,
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
97
frontend/views/user/index.php
Normal file
97
frontend/views/user/index.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
use common\models\User;
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\grid\ActionColumn;
|
||||
use yii\grid\GridView;
|
||||
use common\models\SalesAgent;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var yii\data\ActiveDataProvider $dataProvider */
|
||||
/** @var common\models\search\User $searchModel */
|
||||
|
||||
$this->title = Yii::t('app', 'Users');
|
||||
?>
|
||||
<div class="user-index container1">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<p>
|
||||
<?= Html::a(Yii::t('app', 'Create User'), ['create'], ['class' => 'btn btn-success']) ?>
|
||||
</p>
|
||||
|
||||
|
||||
<?= GridView::widget([
|
||||
'dataProvider' => $dataProvider,
|
||||
'filterModel' => $searchModel,
|
||||
'layout' => "{items}\n{summary}{pager}",
|
||||
'tableOptions' => [
|
||||
'class' => 'custom-table',
|
||||
],
|
||||
'headerRowOptions' => [
|
||||
'class' => 'table-header',
|
||||
],
|
||||
'rowOptions' => [
|
||||
'class' => 'align-middle',
|
||||
],
|
||||
'columns' => [
|
||||
'email:email',
|
||||
[
|
||||
'attribute' => 'status',
|
||||
'label' => 'Status',
|
||||
'value' => function ($model) {
|
||||
return $model->getStatusName();
|
||||
},
|
||||
'filter' => [
|
||||
User::STATUS_ACTIVE => 'Active',
|
||||
User::STATUS_INACTIVE => 'Inactive',
|
||||
User::STATUS_UNVERIFIED => 'Unverified',
|
||||
User::STATUS_VERIFIED => 'Verified (not active)',
|
||||
],
|
||||
],
|
||||
[
|
||||
'attribute' => 'salesAgentName',
|
||||
'label' => Yii::t('app', 'Sales Agent'),
|
||||
'format' => 'raw',
|
||||
'value' => function ($model) {
|
||||
return $model->salesAgent
|
||||
? Html::a($model->salesAgent->name, Url::to(['sales-agent/view', 'id' => $model->salesAgent->id]))
|
||||
: Yii::t('app', 'None assigned');
|
||||
},
|
||||
'filter' => \yii\helpers\ArrayHelper::map(SalesAgent::find()->all(), 'name', 'name'),
|
||||
],
|
||||
[
|
||||
'attribute' => 'role',
|
||||
'label' => 'Role',
|
||||
'value' => function ($model) {
|
||||
$roles = Yii::$app->authManager->getRolesByUser($model->id);
|
||||
return !empty($roles) ? reset($roles)->name : null;
|
||||
},
|
||||
'filter' => \yii\helpers\ArrayHelper::map(
|
||||
Yii::$app->authManager->getRoles(),
|
||||
'name',
|
||||
'name'
|
||||
),
|
||||
],
|
||||
'created_at:datetime',
|
||||
'updated_at:datetime',
|
||||
[
|
||||
'class' => ActionColumn::class,
|
||||
'urlCreator' => function ($action, User $model, $key, $index, $column) {
|
||||
return Url::toRoute([$action, 'id' => $model->id]);
|
||||
},
|
||||
],
|
||||
],
|
||||
'pager' => [
|
||||
'class' => 'yii\widgets\LinkPager',
|
||||
'nextPageLabel' => '►',
|
||||
'prevPageLabel' => '◄',
|
||||
'firstPageLabel' => 'First',
|
||||
'lastPageLabel' => 'Last',
|
||||
'maxButtonCount' => 5,
|
||||
'options' => ['class' => 'pagination'],
|
||||
],
|
||||
]); ?>
|
||||
|
||||
</div>
|
||||
22
frontend/views/user/update.php
Normal file
22
frontend/views/user/update.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $model */
|
||||
/** @var array $salesAgents */
|
||||
|
||||
$this->title = Yii::t('app', 'Update User: {name}', [
|
||||
'name' => $model->email,
|
||||
]);
|
||||
?>
|
||||
<div class="user-update container1">
|
||||
|
||||
<h1><?= Html::encode($this->title) ?></h1>
|
||||
|
||||
<?= $this->render('_form', [
|
||||
'model' => $model,
|
||||
'salesAgents' => $salesAgents
|
||||
]) ?>
|
||||
|
||||
</div>
|
||||
51
frontend/views/user/view.php
Normal file
51
frontend/views/user/view.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use yii\helpers\Html;
|
||||
use yii\helpers\Url;
|
||||
use yii\widgets\DetailView;
|
||||
|
||||
/** @var yii\web\View $this */
|
||||
/** @var common\models\User $model */
|
||||
|
||||
$this->title = $model->email;
|
||||
\yii\web\YiiAsset::register($this);
|
||||
?>
|
||||
|
||||
<div class="user-view mt-3">
|
||||
<div class="card shadow-sm rounded-lg p-4">
|
||||
<h2 class="mb-3"><?= Html::encode($this->title) ?></h2>
|
||||
|
||||
<div class="d-flex gap-2 mb-4">
|
||||
<?php if (Yii::$app->user->can('updateDelete')): ?>
|
||||
<?= Html::a(Yii::t('app', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
|
||||
<?= Html::a(Yii::t('app', 'Delete'), ['delete', 'id' => $model->id], [
|
||||
'class' => 'btn btn-danger',
|
||||
'data' => [
|
||||
'confirm' => Yii::t('app', 'Are you sure you want to delete this user?'),
|
||||
'method' => 'post',
|
||||
],
|
||||
]) ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<p><strong>ID:</strong> <?= Html::encode($model->id) ?></p>
|
||||
<p><strong>Email:</strong> <?= Html::encode($model->email) ?></p>
|
||||
<p><strong>Status:</strong> <?= Html::encode($model->statusName) ?></p>
|
||||
<p><strong>Role:</strong> <?= Html::encode($model->role) ?></p>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<p><strong>Sales Agent:</strong>
|
||||
<?php if (!empty($model->salesAgent)): ?>
|
||||
<?= Html::a(Html::encode($model->salesAgent->name), Url::to(['sales-agent/view', 'id' => $model->salesAgent->id]), ['class' => 'text-decoration-none']) ?>
|
||||
<?php else: ?>
|
||||
<?= Yii::t('app', 'None assigned') ?>
|
||||
<?php endif; ?>
|
||||
</p>
|
||||
<p><strong>Created At:</strong> <?= Yii::$app->formatter->asDatetime($model->created_at) ?></p>
|
||||
<p><strong>Updated At:</strong> <?= Yii::$app->formatter->asDatetime($model->updated_at) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
7
frontend/web/.htaccess
Normal file
7
frontend/web/.htaccess
Normal file
@@ -0,0 +1,7 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteBase /
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteRule . /index.php [L]
|
||||
</IfModule>
|
||||
2
frontend/web/assets/.gitignore
vendored
Normal file
2
frontend/web/assets/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*
|
||||
!.gitignore
|
||||
185
frontend/web/css/select2.css
Normal file
185
frontend/web/css/select2.css
Normal file
@@ -0,0 +1,185 @@
|
||||
.select2-container--bootstrap .select2-selection--single {
|
||||
height: calc(1.5em + .75rem + 2px);
|
||||
font-size: 1rem;
|
||||
line-height: 2.4;
|
||||
color: #495057;
|
||||
background-color: #fff;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: .25rem;
|
||||
transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
|
||||
box-shadow: inset 0 0 0 transparent;
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
min-width: 150px;
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection__arrow {
|
||||
height: 100%;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
right: 10px;
|
||||
color: #495057;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection__rendered {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection--single:focus {
|
||||
border-color: #80bdff;
|
||||
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection--single:hover {
|
||||
border-color: #80bdff;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection__placeholder {
|
||||
color: #6c757d;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection--single .select2-selection__rendered {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-search--dropdown .select2-search__field {
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
padding: .375rem .75rem;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: .25rem;
|
||||
}
|
||||
|
||||
.select2-container {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.select2-hidden-accessible {
|
||||
border: 0;
|
||||
clip: rect(0 0 0 0);
|
||||
-webkit-clip-path: inset(50%);
|
||||
clip-path: inset(50%);
|
||||
height: 1px;
|
||||
overflow: hidden;
|
||||
padding: 0;
|
||||
position: absolute;
|
||||
width: 1px;
|
||||
white-space: nowrap
|
||||
}
|
||||
|
||||
.select2-dropdown {
|
||||
background-color: white;
|
||||
border: 1px solid #ced4da;
|
||||
border-radius: 4px;
|
||||
box-sizing: border-box;
|
||||
display: block;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
.select2-container--open .select2-dropdown {
|
||||
left: 0
|
||||
}
|
||||
|
||||
.select2-container--open .select2-dropdown--above {
|
||||
border-bottom: none;
|
||||
border-bottom-left-radius: 0;
|
||||
border-bottom-right-radius: 0
|
||||
}
|
||||
|
||||
.select2-container--open .select2-dropdown--below {
|
||||
border-top: none;
|
||||
border-top-left-radius: 0;
|
||||
border-top-right-radius: 0
|
||||
}
|
||||
|
||||
.select2-search--dropdown {
|
||||
display: block;
|
||||
padding: 4px
|
||||
}
|
||||
|
||||
.select2-search--dropdown .select2-search__field {
|
||||
padding: 4px;
|
||||
width: 100%;
|
||||
box-sizing: border-box
|
||||
}
|
||||
|
||||
.select2-search--dropdown .select2-search__field::-webkit-search-cancel-button {
|
||||
-webkit-appearance: none
|
||||
}
|
||||
|
||||
.select2-search--dropdown.select2-search--hide {
|
||||
display: none
|
||||
}
|
||||
|
||||
.select2-container--default .select2-search--dropdown .select2-search__field {
|
||||
border: 1px solid #aaa
|
||||
}
|
||||
|
||||
.select2-container--classic .select2-search--dropdown .select2-search__field {
|
||||
border: 1px solid #aaa;
|
||||
outline: 0
|
||||
}
|
||||
|
||||
.select2-container--classic .select2-dropdown {
|
||||
background-color: #fff;
|
||||
border: 1px solid transparent
|
||||
}
|
||||
|
||||
.select2-container--classic .select2-dropdown--above {
|
||||
border-bottom: none
|
||||
}
|
||||
|
||||
.select2-container--classic .select2-dropdown--below {
|
||||
border-top: none
|
||||
}
|
||||
|
||||
.select2-container--classic.select2-container--open .select2-dropdown {
|
||||
border-color: #5897fb
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-results__option:hover {
|
||||
background-color: #f1f1f1;
|
||||
color: #333;
|
||||
width: 100%;
|
||||
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection__clear {
|
||||
margin-right: 2px;
|
||||
color: #d9534f;
|
||||
font-size: 1.2rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-selection__clear:hover {
|
||||
color: #c9302c;
|
||||
}
|
||||
|
||||
.select2-container--bootstrap .select2-results__option {
|
||||
list-style: none;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
font-size: 1rem;
|
||||
color: #333;
|
||||
margin-bottom: 8px;
|
||||
box-sizing: border-box;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
|
||||
.select2-results__options {
|
||||
margin: 0;
|
||||
padding: 5px 0;
|
||||
}
|
||||
325
frontend/web/css/site.css
Normal file
325
frontend/web/css/site.css
Normal file
@@ -0,0 +1,325 @@
|
||||
/* Customize container or page background */
|
||||
body {
|
||||
background-color: #fff; /* Light pastel background color */
|
||||
}
|
||||
|
||||
main > .container, main > .container-fluid
|
||||
{
|
||||
padding: 70px 15px 20px;
|
||||
}
|
||||
|
||||
.date-date {
|
||||
width: 300px;
|
||||
}
|
||||
|
||||
.login {
|
||||
color: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
.login:hover {
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
.login:active {
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.footer {
|
||||
background-color: #f5f5f5;
|
||||
font-size: .9em;
|
||||
height: 60px;
|
||||
}
|
||||
|
||||
.footer > .container, .footer > .container-fluid {
|
||||
padding-right: 15px;
|
||||
padding-left: 15px;
|
||||
}
|
||||
|
||||
.not-set {
|
||||
color: #c55;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* add sorting icons to gridview sort links */
|
||||
a.asc:after, a.desc:after {
|
||||
content: '';
|
||||
left: 3px;
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
border: solid 5px transparent;
|
||||
margin: 4px 4px 2px 4px;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
a.asc:after {
|
||||
border-bottom: solid 7px #212529;
|
||||
border-top-width: 0;
|
||||
}
|
||||
|
||||
a.desc:after {
|
||||
border-top: solid 7px #212529;
|
||||
border-bottom-width: 0;
|
||||
}
|
||||
|
||||
.grid-view th,
|
||||
.grid-view td:last-child {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.grid-view .filters input,
|
||||
.grid-view .filters select {
|
||||
min-width: 50px;
|
||||
}
|
||||
|
||||
.hint-block {
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.error-summary {
|
||||
color: #a94442;
|
||||
background: #fdf7f7;
|
||||
border-left: 3px solid #eed3d7;
|
||||
padding: 10px 20px;
|
||||
margin: 0 0 15px 0;
|
||||
}
|
||||
|
||||
/* align the logout "link" (button in form) of the navbar */
|
||||
.navbar form > button.logout {
|
||||
padding-top: 7px;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
}
|
||||
|
||||
@media(max-width:767px) {
|
||||
.navbar form > button.logout {
|
||||
display:block;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
}
|
||||
}
|
||||
|
||||
.navbar form > button.logout:focus,
|
||||
.navbar form > button.logout:hover {
|
||||
text-decoration: none;
|
||||
color: rgba(255, 255, 255, 0.75);
|
||||
}
|
||||
|
||||
.navbar form > button.logout:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
/* style breadcrumb widget as in previous bootstrap versions */
|
||||
.breadcrumb {
|
||||
background-color: var(--bs-gray-200);
|
||||
border-radius: .25rem;
|
||||
padding: .75rem 1rem;
|
||||
}
|
||||
|
||||
.breadcrumb-item > a
|
||||
{
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.index{
|
||||
padding-top: 20px;
|
||||
}
|
||||
|
||||
/* Main table styling */
|
||||
.custom-table {
|
||||
margin: 0 auto;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
background-color: #fff;
|
||||
border-radius: 10px;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* Header styling */
|
||||
.custom-table th {
|
||||
background-color: #99c7e7;
|
||||
color: #fff;
|
||||
padding: 15px;
|
||||
text-align: center;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.custom-table th a {
|
||||
text-decoration: none;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
/* Row styling */
|
||||
.custom-table td {
|
||||
padding: 15px;
|
||||
text-align: center !important;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
|
||||
.custom-table tr:last-child td {
|
||||
border-bottom: none; /* Remove bottom border for the last row */
|
||||
}
|
||||
|
||||
/* Alternating row colors */
|
||||
.custom-table tr:nth-child(even) {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
|
||||
/* Action buttons */
|
||||
.blue-back {
|
||||
background-color: #333; /* Darker background for buttons */
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 12px;
|
||||
border-radius: 5px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Action buttons */
|
||||
.blue-back {
|
||||
background-color: #333; /* Darker background for buttons */
|
||||
}
|
||||
|
||||
/* Align filter input text vertically in the middle */
|
||||
.custom-table input[type="text"] {
|
||||
padding: 10px;
|
||||
font-size: 14px;
|
||||
color: #333; /* Regular text color */
|
||||
}
|
||||
|
||||
/* Style for placeholder text */
|
||||
.custom-table input::placeholder {
|
||||
color: #444;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
|
||||
/* Align text vertically in the middle */
|
||||
.align-middle {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* Lighter text color */
|
||||
.text-light-gray {
|
||||
color: #888888; /* Light grey text */
|
||||
}
|
||||
|
||||
/* Pagination container */
|
||||
.pagination {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
/* Pagination item styles */
|
||||
.pagination li {
|
||||
margin: 0 5px;
|
||||
}
|
||||
|
||||
/* Pagination link styles */
|
||||
.pagination li a, .pagination li span {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
line-height: normal;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
border: 2px solid black;
|
||||
color: black;
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
transition: background-color 0.3s, color 0.3s;
|
||||
}
|
||||
|
||||
.pagination li.active.disabled a,
|
||||
.pagination li.disabled.active a {
|
||||
background-color: black;
|
||||
color: white;
|
||||
border-color: black;
|
||||
cursor: default;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.pagination .active a {
|
||||
background-color: black;
|
||||
color: white;
|
||||
border-color: black;
|
||||
}
|
||||
|
||||
.pagination .first a:hover,
|
||||
.pagination .last a:hover {
|
||||
background: none !important;
|
||||
}
|
||||
|
||||
.pagination .first a,
|
||||
.pagination .last a,
|
||||
.pagination .last.disabled span,
|
||||
.pagination .first.disabled span {
|
||||
border: none;
|
||||
background: none;
|
||||
position: relative;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.pagination .last.disabled span,
|
||||
.pagination .first.disabled span {
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.pagination .first a, .pagination .last a {
|
||||
position: relative;
|
||||
transition: color 0.3s;
|
||||
}
|
||||
|
||||
.pagination li:not(.prev):not(.next):not(.disabled):not(.active) a:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.pagination .prev a, .pagination .next a {
|
||||
padding: 0;
|
||||
font-size: 18px;
|
||||
color: black;
|
||||
border: none;
|
||||
transition: color 0.3s ease;
|
||||
}
|
||||
|
||||
.pagination .prev a:hover, .pagination .next a:hover {
|
||||
color: #555555;
|
||||
}
|
||||
|
||||
.pagination .prev.disabled span,
|
||||
.pagination .next.disabled span {
|
||||
cursor: not-allowed;
|
||||
border: none;
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.pagination li a, .pagination li span {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.custom-table .filters input::placeholder {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.custom-table .filters input {
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.spacing1{
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
.container1{
|
||||
padding-top: 10px;
|
||||
}
|
||||
BIN
frontend/web/favicon.ico
Normal file
BIN
frontend/web/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 318 B |
BIN
frontend/web/images/navi.png
Normal file
BIN
frontend/web/images/navi.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Reference in New Issue
Block a user