Skip to content

Commit 1b572b1

Browse files
committedOct 21, 2022
add design system
1 parent 55b306f commit 1b572b1

26 files changed

+368
-838
lines changed
 

‎.DS_Store

6 KB
Binary file not shown.

‎app.js

+24-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
const express = require('express');
22
const app = express();
3-
const PORT = process.env.PORT || 8080;
3+
const dashboardRouter = require('./routes/dashboard')
4+
const { users, ROLE } = require('./data');
5+
const {authUser, authRole} = require('./basicAuth')
46

5-
// set the view engine to ejs
6-
app.use(express.static('public'))
7-
app.set('view engine', 'ejs');
87

9-
// use res.render to load up an ejs view file
8+
app.use(express.static('public'));
9+
app.set('view engine', 'ejs');
10+
app.use(express.json())
11+
app.use(setUser)
12+
// app.use('/dashboard', dashboardRouter);
1013

11-
// index page
1214
app.get('/', function(req, res) {
1315
res.render("pages/index")
16+
1417
});
1518

16-
// about page
17-
app.get('/dashboard', function(req, res) {
18-
res.send('You just logged in')
19-
});
19+
app.get('/design', (req, res) => {
20+
res.render('pages/design')
21+
})
22+
23+
24+
function setUser(req, res, next) {
25+
const userId = req.body.userId
26+
if (userId) {
27+
req.user = users.find(user => user.id === userId)
28+
29+
}
30+
31+
next()
32+
}
2033

34+
const PORT = process.env.PORT || 3000;
2135
app.listen(PORT, () => console.log(`Listening on ${ PORT }`))

‎basicAuth.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function authUser (req, res, next) {
2+
if(req.user == null) {
3+
res.status(403)
4+
5+
return res.send('You need to login first')
6+
}
7+
8+
next()
9+
}
10+
11+
function authRole (role) {
12+
return (req, res, next) => {
13+
if (role != req.user.role) {
14+
res.status(401)
15+
return res.send('UnAuthorized')
16+
}
17+
18+
next();
19+
}
20+
}
21+
22+
module.exports = {
23+
authUser,
24+
authRole
25+
}

‎data.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const ROLE = {
2+
ADMIN: 'admin',
3+
BASIC: 'basic'
4+
}
5+
6+
module.exports = {
7+
ROLE: ROLE,
8+
users: [
9+
{
10+
id: 1,
11+
email: 'admin@consuelo.com',
12+
password: `123456`,
13+
role: ROLE.ADMIN
14+
},
15+
{
16+
id: 2,
17+
email: 'user1@consuelo.com',
18+
password: `123456`,
19+
role: ROLE.BASIC
20+
},
21+
{
22+
id: 3,
23+
email: 'user2@consuelo.com',
24+
password: `123456`,
25+
role: ROLE.BASIC
26+
},
27+
{
28+
id: 4,
29+
email: 'user4@consuelo.com',
30+
password: `123456`,
31+
role: ROLE.BASIC
32+
},
33+
]
34+
}

‎permission/dashboard.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { ROLE } = require('../data')
2+
3+
function canViewDashboard(user, project) {
4+
return (user.role === ROLE.ADMIN || user.id === project.userId)
5+
}
6+
7+
function scopedProject(user, projects) {
8+
if (user.role === ROLE.ADMIN) {
9+
return res.json(projects)
10+
}
11+
12+
return projects.filter(project => user.id === project.userId)
13+
}
14+
15+
module.exports = {
16+
canViewDashboard,
17+
scopedProject
18+
}

‎public/.DS_Store

6 KB
Binary file not shown.

‎public/css/input.css

+5
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@
22
@tailwind components;
33
@tailwind utilities;
44

5+
6+
@font-face {
7+
font-family: "Montserrat";
8+
src: url("../public/fonts/ADELIA.otf");
9+
}

0 commit comments

Comments
 (0)
Please sign in to comment.