titles and admin page html

This commit is contained in:
Sergey Yarkov 2019-12-07 00:11:00 +03:00
parent 17b39b4a90
commit dcb3d7e0b6
15 changed files with 85 additions and 39 deletions

View File

@ -5,14 +5,14 @@ function initialize(passport, getUserByEmail, getUserById) {
const authenticateUser = async (email, password, done) => { const authenticateUser = async (email, password, done) => {
const user = getUserByEmail(email); const user = getUserByEmail(email);
if (user == null) { if (user == null) {
return done(null, false, { message: 'Пользователь с такой почтой не найден' }); return done(null, false, { message: 'Администратор с такой почтой не найден!' });
} }
try { try {
if (await bcrypt.compare(password, user.password)) { if (await bcrypt.compare(password, user.password)) {
return done(null, user); return done(null, user);
} else { } else {
return done(null, false, { message: 'Неверный пароль' }); return done(null, false, { message: 'Неверный пароль!' });
} }
} catch (error) { } catch (error) {
return done(error); return done(error);

View File

@ -11,8 +11,9 @@ function checkNotAuthenticated(req, res, next) {
} }
function loginRoute(req, res) { function loginRoute(req, res) {
res.render('admin') res.render('admin/admin', {
title: 'Digital-Store | Вход в панель управления сайтом'
})
} }
// function registerRoute(req, res) { // function registerRoute(req, res) {

View File

@ -13,6 +13,7 @@ function indexRoute(req, res, dbo) {
const categories = result.map(category => category.title[0].toUpperCase() + category.title.slice(1)); const categories = result.map(category => category.title[0].toUpperCase() + category.title.slice(1));
res.render('index', { res.render('index', {
pageName: 'index', pageName: 'index',
title: 'Digital-Store | Главная',
categories categories
}); });
}); });
@ -134,30 +135,37 @@ function onePageItemRoute(req, res, dbo) {
function howToBuyRoute(req, res) { function howToBuyRoute(req, res) {
res.render('how-to-buy', { res.render('how-to-buy', {
pageName: 'how-to-buy' pageName: 'how-to-buy',
title: 'Digital-Store | Как купить товар'
}); });
} }
function contactsRoute(req, res) { function contactsRoute(req, res) {
res.render('contacts', { res.render('contacts', {
pageName: 'contacts' pageName: 'contacts',
title: 'Digital-Store | Контакты'
}); });
} }
function commentsRoute(req, res) { function commentsRoute(req, res) {
res.render('comments', { res.render('comments', {
pageName: 'comments' pageName: 'comments',
title: 'Digital-Store | Отзывы'
}); });
} }
function myOrdersRoute(req, res) { function myOrdersRoute(req, res) {
res.render('my-orders', { res.render('my-orders', {
pageName: 'my-orders' pageName: 'my-orders',
title: 'Digital-Store | Мои покупки'
}); });
} }
function controlPanelRoute(req, res) { function controlPanelRoute(req, res) {
res.render('control-panel', {name: req.user.name}); res.render('admin/control-panel', {
name: req.user.name,
title: 'Digital-Store | Панель управления сайтом'
});
} }
module.exports = function (server, db) { module.exports = function (server, db) {

View File

@ -49,7 +49,7 @@ hr {
width: 300px; width: 300px;
position: fixed; position: fixed;
right: 30px; right: 30px;
z-index: 1; z-index: 2;
} }
.block-title { .block-title {
@ -655,3 +655,19 @@ footer {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
} }
/* Control Panel login */
.login-form {
margin-top: 7rem;
}
.login-form__title h1 {
text-align: center;
font-weight: 400;
font-size: 18px;
}
.login-form__content {
margin-top: 2rem;
}
.login-form__content button {
width: 100%;
}

File diff suppressed because one or more lines are too long

View File

@ -2,4 +2,5 @@ document.addEventListener('DOMContentLoaded', function () {
// Nav-mobile menu init // Nav-mobile menu init
M.Sidenav.init(document.querySelectorAll('.sidenav')) M.Sidenav.init(document.querySelectorAll('.sidenav'))
M.FormSelect.init(document.querySelectorAll('select')) M.FormSelect.init(document.querySelectorAll('select'))
M.updateTextFields();
}); });

11
dist/views/admin.pug vendored
View File

@ -1,11 +0,0 @@
if messages.error
h3 #{messages.error}
h1 Login Page
form(action="/admin" method="POST")
div
label(for="email") Email
input(type="email" id="email" name="email" required)
div
label(for="password") Password
input(type="password" id="password" name="password" required)
button(type="submit") Login

25
dist/views/admin/admin.pug vendored Normal file
View File

@ -0,0 +1,25 @@
include ../assets/head.pug
main
if messages.error
#notification
.card-panel(style="background-color: #f34d53;")
span.white-text #{messages.error}
.container
.row
.col.m6.offset-m3.s12
.login-form
.login-form__content
.login-form__title
h1 Вход в панель управления
.login-form__content
form(action="/admin" method="POST")
div.input-field
i.material-icons.prefix email
label(for="email") Почта
input(type="email" id="email" name="email" required)
div.input-field
i.material-icons.prefix lock
label(for="password") Пароль
input(type="password" id="password" name="password" required)
button(class="waves-light btn-large" type="submit") Вход
include ../assets/scripts.pug

View File

@ -1,3 +1,4 @@
include ../assets/head.pug
h1 Control-Panel h1 Control-Panel
h3 Привет #{name} h3 Привет #{name}
form(action="/logout?_method=DELETE" method="POST") form(action="/logout?_method=DELETE" method="POST")

View File

@ -3,7 +3,7 @@ html(lang='ru')
head head
meta(charset='utf-8') meta(charset='utf-8')
meta(http-equiv='Cоntent-Type' cоntent='text/html;' charset='utf-8') meta(http-equiv='Cоntent-Type' cоntent='text/html;' charset='utf-8')
title Digital Shop title #{title}
// Materialize CSS // Materialize CSS
link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css") link(rel="stylesheet", href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css")
// Style CSS // Style CSS

5
dist/views/assets/scripts.pug vendored Normal file
View File

@ -0,0 +1,5 @@
// Maretialize JS
script(src='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js')
// Script JS
script(src='../js/bundle.js')
script(src='../js/materialize.config.js')

View File

@ -3,8 +3,4 @@ footer
.waves-effect.waves-light.pulse.cart-btn(id="cartOpen") .waves-effect.waves-light.pulse.cart-btn(id="cartOpen")
i.material-icons shopping_cart i.material-icons shopping_cart
span#counter.counter 0 span#counter.counter 0
// Maretialize JS include ../scripts.pug
script(src='https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js')
// Script JS
script(src='../js/bundle.js')
script(src='../js/materialize.config.js')

View File

@ -7,10 +7,12 @@ export class HeaderComponent extends Component {
} }
init() { init() {
const currentPage = this.$el.querySelector('#desktop-nav'); if (this.$el) {
const pages = Array.from(this.$el.querySelectorAll('#page')); const currentPage = this.$el.querySelector('#desktop-nav');
pages.forEach(li => li.dataset.page === currentPage.dataset.current ? li.classList.add('active') : false); const pages = Array.from(this.$el.querySelectorAll('#page'));
// ф-я счетика товаров pages.forEach(li => li.dataset.page === currentPage.dataset.current ? li.classList.add('active') : false);
localStorage.getItem('cart') ? insertCount('counter', JSON.parse(localStorage.getItem('cart'))) : false; // ф-я счетика товаров
localStorage.getItem('cart') ? insertCount('counter', JSON.parse(localStorage.getItem('cart'))) : false;
}
} }
} }

View File

@ -24,7 +24,7 @@ export class Modal {
} }
} }
function openHandler(e) { function openHandler() {
this.show(); this.show();
} }

View File

@ -5,9 +5,11 @@ export class CartModal extends Modal {
constructor(id, open, close, {items}) { constructor(id, open, close, {items}) {
super(id, open, close); super(id, open, close);
this.items = items; this.items = items;
this.open.addEventListener('click', this.openHandler.bind(this)); if (this.$el) {
this.close.addEventListener('click', this.closeHandler.bind(this)); this.open.addEventListener('click', this.openHandler.bind(this));
this.list = this.$el.querySelector('#modalList'); this.close.addEventListener('click', this.closeHandler.bind(this));
this.list = this.$el.querySelector('#modalList');
}
} }
closeHandler() { closeHandler() {