class UserController extends ActiveController
{
const TOKEN = 'secret';
public $modelClass = 'backend\models\User';
public function behaviors()
{
$behaviors = parent::behaviors();
$behaviors['authenticator']['class'] = QueryParamAuth::className();
$behaviors['authenticator']['tokenParam'] = 'token';
return ArrayHelper::merge(parent::behaviors(), [
'access' => [
'class' => AccessControl::className(),
'user' => false,
'rules' => [
[
'allow' => true,
'matchCallback' => function ($rule, $action) {
$data = \Yii::$app->request->get('token');
return $data === self::TOKEN;
},
],
],
'denyCallback' => function ($rule, $action) {
throw new \yii\web\ForbiddenHttpException('Доступ запрещен');
}
],
]
);
}
}
window.location.href = "http://site.com/"
window.onload = function(){
function timer(){
let minute = document.getElementById('minute').innerHTML;
let second = document.getElementById('second').innerHTML;
let end = false;
if( second > 0 ) {
second--;
if( second < 10) {
second = '0'+second
};
} else{
second = 60;
if( minute > 0 ) {
minute--;
if(minute < 10){
minute = '0'+minute
}
} else{
end = true;
}
}
if(end){
clearInterval(intervalID);
alert("Время истекло!");
}else{document.getElementById('minute').innerHTML = minute;
document.getElementById('second').innerHTML = second;
}
}
window.intervalID = setInterval(timer, 1000);
}
router.get('/locations', (res, req, err) => {
if(err) return err;
ctrlLocations.locationsListByDistance
});
router.get('/order/:id', async(ctx) => {
await Order.findOne({orderId: ctx.params.id}).exec((err, id) => {
if (err) return err;
ctx.body = id;
});
})
router
.get('/user', async(ctx) => {
auth(ctx);
try {
let orders = await Order.find((err, doc) => {
return doc;
});
return ctx.render('user', {
title: 'Главнвя страница',
username: ctx.state.user,
order: orders
});
} catch(err){
await console.log(err);
}
});
router.post('/', async (ctx) => {
await passport.authenticate('local', async(err, user) => {
if(user === false){
await ctx.render('login', {title: 'Авторизация', message: 'Неверный логин или пароль'});
} else {
ctx.login(user, async (err) => {
await err ? ctx.body = err : ctx.redirect('/user');
});
}
})(ctx)
});
router.post('/', async (ctx) => {
await passport.authenticate('local', async(err, user) => {
if(user === false){
await ctx.render('login', {title: 'Авторизация', message: 'Неверный логин или пароль'});
} else {
console.log(user);
const payload = {
id: user.id,
username: user.username,
};
const token = jwt.sign(payload, jwtsecret); //здесь создается JWT
ctx.body = {user: user.username, token: 'JWT ' + token};
console.log(ctx.body);
ctx.redirect('/user');
}
}) (ctx)
});
Order.find().lean().then ...
[['phone'], 'string'],
['phone', 'match', 'pattern' => '/^(8)[(](\d{3})[)](\d{3})[-](\d{2})[-](\d{2})/', 'message' => 'Телефона, должно быть в формате 8(XXX)XXX-XX-XX'],
if ($model->load(Yii::$app->request->post()) && $client->load(Yii::$app->request->post())) {
$arr = ArrayHelper::map($model->tags, 'id', 'id');
foreach (Yii::$app->request->post('Zakaz')['tags_array'] as $one){
if (!in_array($one, $arr)){
$tag = new ZakazTag();
$tag->zakaz_id = $id;
$tag->tag_id = $one;
$tag->save();
}
if (isset($arr[$one])){
unset($arr[$one]);
}
}
ZakazTag::deleteAll(['tag_id' => $arr]);
}