Compare commits

..

2 Commits

Author SHA1 Message Date
Matjaz
0f739adfb2 Začetek obrazca za prijavo. 2022-02-09 19:32:45 +01:00
Matjaz
32f7c6caa1 Testiranje modelov. 2022-02-09 19:32:06 +01:00
9 changed files with 4053 additions and 28 deletions

5
app.js
View File

@ -7,11 +7,13 @@ var logger = require('morgan');
var indexRouter = require('./routes/index');
var usersRouter = require('./routes/user');
var messagesRouter = require('./routes/message');
var loginRouter = require('./routes/login');
var app = express();
const db = require('./models');
db.sequelize.sync({ force: true });
//db.sequelize.sync({ force: true });
db.sequelize.sync();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
@ -26,6 +28,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/user', usersRouter);
app.use('/message', messagesRouter);
app.use('/login', loginRouter);
// catch 404 and forward to error handler
app.use(function(req, res, next) {

Binary file not shown.

View File

@ -24,8 +24,8 @@ fs
db[model.name] = model;
});
db.User.hasMany(db.Message, {foreignKey: 'UserId'});
db.Message.belongsTo(db.User);
db.User.belongsToMany(db.Message, {foreignKey: 'UserId', through: 'UserMessages'});
db.Message.belongsTo(db.User, {through: 'UserMessages'});
Object.keys(db).forEach(modelName => {
if (db[modelName].associate) {

3798
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -16,6 +16,7 @@
"sqlite3": "^5.0.2"
},
"devDependencies": {
"jshint": "^2.13.4",
"postcss": "^8.4.6",
"sequelize-cli": "^6.4.1",
"tailwind-scrollbar": "^1.3.1",

View File

@ -423,6 +423,11 @@ Ensure the default browser behavior of the `hidden` attribute.
display: none;
}
* {
scrollbar-color: initial;
scrollbar-width: initial;
}
*, ::before, ::after {
--tw-translate-x: 0;
--tw-translate-y: 0;
@ -502,21 +507,25 @@ Ensure the default browser behavior of the `hidden` attribute.
margin-right: auto;
}
.mx-2 {
margin-left: 0.5rem;
margin-right: 0.5rem;
}
.my-4 {
margin-top: 1rem;
margin-bottom: 1rem;
}
.mx-2 {
margin-left: 0.5rem;
margin-right: 0.5rem;
}
.my-5 {
margin-top: 1.25rem;
margin-bottom: 1.25rem;
}
.mt-2 {
margin-top: 0.5rem;
}
.mt-5 {
margin-top: 1.25rem;
}
@ -525,6 +534,14 @@ Ensure the default browser behavior of the `hidden` attribute.
margin-right: 0.5rem;
}
.mr-4 {
margin-right: 1rem;
}
.mb-4 {
margin-bottom: 1rem;
}
.mr-3 {
margin-right: 0.75rem;
}
@ -533,12 +550,8 @@ Ensure the default browser behavior of the `hidden` attribute.
margin-top: 0.75rem;
}
.mb-4 {
margin-bottom: 1rem;
}
.mr-4 {
margin-right: 1rem;
.mt-4 {
margin-top: 1rem;
}
.block {
@ -569,6 +582,10 @@ Ensure the default browser behavior of the `hidden` attribute.
max-height: 2.5rem;
}
.min-h-screen {
min-height: 100vh;
}
.w-6 {
width: 1.5rem;
}
@ -601,6 +618,10 @@ Ensure the default browser behavior of the `hidden` attribute.
align-items: center;
}
.items-baseline {
align-items: baseline;
}
.justify-end {
justify-content: flex-end;
}
@ -640,6 +661,10 @@ Ensure the default browser behavior of the `hidden` attribute.
border-radius: 0.375rem;
}
.rounded-lg {
border-radius: 0.5rem;
}
.border {
border-width: 1px;
}
@ -658,6 +683,11 @@ Ensure the default browser behavior of the `hidden` attribute.
background-color: rgb(255 255 255 / var(--tw-bg-opacity));
}
.bg-blue-500 {
--tw-bg-opacity: 1;
background-color: rgb(59 130 246 / var(--tw-bg-opacity));
}
.bg-gray-700 {
--tw-bg-opacity: 1;
background-color: rgb(55 65 81 / var(--tw-bg-opacity));
@ -678,6 +708,11 @@ Ensure the default browser behavior of the `hidden` attribute.
background-color: rgb(75 85 99 / var(--tw-bg-opacity));
}
.bg-gray-100 {
--tw-bg-opacity: 1;
background-color: rgb(243 244 246 / var(--tw-bg-opacity));
}
.object-none {
-o-object-fit: none;
object-fit: none;
@ -730,6 +765,21 @@ Ensure the default browser behavior of the `hidden` attribute.
padding-right: 1rem;
}
.px-8 {
padding-left: 2rem;
padding-right: 2rem;
}
.py-6 {
padding-top: 1.5rem;
padding-bottom: 1.5rem;
}
.px-6 {
padding-left: 1.5rem;
padding-right: 1.5rem;
}
.pl-2 {
padding-left: 0.5rem;
}
@ -746,6 +796,14 @@ Ensure the default browser behavior of the `hidden` attribute.
padding-right: 1.25rem;
}
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.align-bottom {
vertical-align: bottom;
}
@ -760,6 +818,11 @@ Ensure the default browser behavior of the `hidden` attribute.
line-height: 1.75rem;
}
.text-2xl {
font-size: 1.5rem;
line-height: 2rem;
}
.font-bold {
font-weight: 700;
}
@ -769,14 +832,19 @@ Ensure the default browser behavior of the `hidden` attribute.
color: rgb(75 85 99 / var(--tw-text-opacity));
}
.text-white {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
.text-gray-400 {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
}
.text-white {
.text-blue-600 {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
color: rgb(37 99 235 / var(--tw-text-opacity));
}
.shadow {
@ -791,6 +859,56 @@ Ensure the default browser behavior of the `hidden` attribute.
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.shadow-lg {
--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
}
.scrollbar.overflow-y-hidden {
overflow-y: hidden;
}
.scrollbar-thin {
--scrollbar-track: initial;
--scrollbar-thumb: initial;
scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
overflow: overlay;
}
.scrollbar-thin.overflow-x-hidden {
overflow-x: hidden;
}
.scrollbar-thin.overflow-y-hidden {
overflow-y: hidden;
}
.scrollbar-thin::-webkit-scrollbar-track {
background-color: var(--scrollbar-track);
}
.scrollbar-thin::-webkit-scrollbar-thumb {
background-color: var(--scrollbar-thumb);
}
.scrollbar-thin {
scrollbar-width: thin;
}
.scrollbar-thin::-webkit-scrollbar {
width: 8px;
height: 8px;
}
.scrollbar-track-gray-\37 00 {
--scrollbar-track: #374151 !important;
}
.scrollbar-thumb-gray-\39 00 {
--scrollbar-thumb: #111827 !important;
}
.focus-within\:text-gray-400:focus-within {
--tw-text-opacity: 1;
color: rgb(156 163 175 / var(--tw-text-opacity));
@ -801,6 +919,16 @@ Ensure the default browser behavior of the `hidden` attribute.
background-color: rgb(75 85 99 / var(--tw-bg-opacity));
}
.hover\:bg-blue-900:hover {
--tw-bg-opacity: 1;
background-color: rgb(30 58 138 / var(--tw-bg-opacity));
}
.hover\:underline:hover {
-webkit-text-decoration-line: underline;
text-decoration-line: underline;
}
.focus\:text-blue-400:focus {
--tw-text-opacity: 1;
color: rgb(96 165 250 / var(--tw-text-opacity));
@ -811,6 +939,17 @@ Ensure the default browser behavior of the `hidden` attribute.
outline-offset: 2px;
}
.focus\:ring-1:focus {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}
.focus\:ring-blue-600:focus {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(37 99 235 / var(--tw-ring-opacity));
}
@media (prefers-color-scheme: dark) {
.dark\:bg-gray-800 {
--tw-bg-opacity: 1;
@ -849,6 +988,11 @@ Ensure the default browser behavior of the `hidden` attribute.
}
@media (min-width: 1024px) {
.lg\:mx-10 {
margin-left: 2.5rem;
margin-right: 2.5rem;
}
.lg\:mx-3 {
margin-left: 0.75rem;
margin-right: 0.75rem;
@ -862,6 +1006,10 @@ Ensure the default browser behavior of the `hidden` attribute.
height: 100vh;
}
.lg\:w-1\/4 {
width: 25%;
}
.lg\:w-72 {
width: 18rem;
}
@ -878,4 +1026,12 @@ Ensure the default browser behavior of the `hidden` attribute.
padding-left: 6rem;
padding-right: 6rem;
}
.scrollbar.lg\:overflow-y-hidden {
overflow-y: hidden;
}
.scrollbar-thin.lg\:overflow-y-hidden {
overflow-y: hidden;
}
}

9
routes/login.js Normal file
View File

@ -0,0 +1,9 @@
var express = require('express');
var router = express.Router();
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
module.exports = router;

View File

@ -4,13 +4,54 @@ var router = express.Router();
var Message = db.Message;
var User = db.User;
/* GET users listing. */
router.get('/', async function(req, res, next) {
router.get('/get', async function(req, res, next) {
var messages = await Message.findAll();
res.send(messages);
});
router.get('/get/:user', async function(req, res, next) {
var user = await User.findAll({
attributes: ['id'],
where: {
'name': req.params.user,
}
});
res.send(user);
});
router.get('/getmsg/:user', async function(req, res, next) {
var msgs = await User.findOne({
where: { id:3 },
include: Message
});
res.send(msgs);
});
router.get('/getmsg2/:user', async function(req, res, next) {
var user = await User.findOne({
where: { id:3 },
});
msgs = await user.getMessages();
res.send(msgs);
});
router.get('/new', async function(req, res, next) {
var message = await Message.create({'body':'My First Message', UserId:3});
var user = await User.findOne({
where: { id:3 }
});
var message = await user.addMessage(12);
//user.addMessage({body:'A dela tole?'});
res.send(message);
});
router.get('/new2', async function(req, res, next) {
var user = await User.findOne({
where: { id:4 }
});
var message = await user.createMessage({
body: 'WooHoo :)'
});
//user.addMessage({body:'A dela tole?'});
res.send(message);
});

37
views/login.ejs Normal file
View File

@ -0,0 +1,37 @@
<!DOCTYPE html>
<html class="dark">
<head>
<title>Social Robot</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/stylesheets/style.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/fork-awesome@1.2.0/css/fork-awesome.min.css"
integrity="sha256-XoaMnoYC5TH6/+ihMEnospgm0J1PM/nioxbOUdnM8HY=" crossorigin="anonymous">
</head>
<div class="flex items-center justify-center min-h-screen bg-gray-100">
<div class="px-8 py-6 mt-4 text-left bg-white shadow-lg">
<h3 class="text-2xl font-bold text-center">Login to your account</h3>
<form action="">
<div class="mt-4">
<div>
<label class="block" for="email">Email<label>
<input type="text" placeholder="Email"
class="w-full px-4 py-2 mt-2 border rounded-md focus:outline-none focus:ring-1 focus:ring-blue-600">
</div>
<div class="mt-4">
<label class="block">Password<label>
<input type="password" placeholder="Password"
class="w-full px-4 py-2 mt-2 border rounded-md focus:outline-none focus:ring-1 focus:ring-blue-600">
</div>
<div class="flex items-baseline justify-between">
<button class="px-6 py-2 mt-4 text-white bg-blue-600 rounded-lg hover:bg-blue-900">Login</button>
<a href="#" class="text-sm text-blue-600 hover:underline">Forgot password?</a>
</div>
</div>
</form>
</div>
</div>
</html>