Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project-bookcommu
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160118
project-bookcommu
Commits
6a91e8c2
Commit
6a91e8c2
authored
2 months ago
by
65160118
Browse files
Options
Downloads
Patches
Plain Diff
3 commit
parent
394c553e
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
app.js
+7
-0
7 additions, 0 deletions
app.js
controllers/authController.js
+6
-2
6 additions, 2 deletions
controllers/authController.js
models/userModel.js
+1
-1
1 addition, 1 deletion
models/userModel.js
with
14 additions
and
3 deletions
app.js
+
7
−
0
View file @
6a91e8c2
...
...
@@ -40,6 +40,13 @@ app.use(session({
saveUninitialized
:
true
}));
app
.
use
((
req
,
res
,
next
)
=>
{
if
(
!
req
.
session
.
returnTo
&&
req
.
method
===
"
GET
"
&&
!
req
.
path
.
startsWith
(
'
/login
'
)
&&
!
req
.
path
.
startsWith
(
'
/register
'
))
{
req
.
session
.
returnTo
=
req
.
originalUrl
;
}
next
();
});
// Database middleware
app
.
use
((
req
,
res
,
next
)
=>
{
req
.
db
=
db
;
...
...
This diff is collapsed.
Click to expand it.
controllers/authController.js
+
6
−
2
View file @
6a91e8c2
...
...
@@ -35,13 +35,17 @@ exports.postLogin = async (req, res) => {
return
res
.
render
(
'
login
'
,
{
error
:
'
อีเมลหรือรหัสผ่านไม่ถูกต้อง
'
});
}
const
isMatch
=
await
bcrypt
.
compare
(
password
,
user
.
password
);
const
isMatch
=
await
bcrypt
js
.
compare
(
password
,
user
.
password
);
if
(
!
isMatch
)
{
return
res
.
render
(
'
login
'
,
{
error
:
'
อีเมลหรือรหัสผ่านไม่ถูกต้อง
'
});
}
req
.
session
.
user
=
user
;
res
.
redirect
(
'
/
'
);
// Changed from '/booklists' to '/' to redirect to home page
// Redirect to saved URL or default to home
const
returnTo
=
req
.
session
.
returnTo
||
'
/
'
;
delete
req
.
session
.
returnTo
;
res
.
redirect
(
returnTo
);
}
catch
(
error
)
{
res
.
render
(
'
login
'
,
{
error
:
'
เกิดข้อผิดพลาดในการเข้าสู่ระบบ โปรดลองอีกครั้ง
'
});
}
...
...
This diff is collapsed.
Click to expand it.
models/userModel.js
+
1
−
1
View file @
6a91e8c2
...
...
@@ -6,7 +6,7 @@ module.exports = class User {
}
async
register
(
username
,
email
,
password
)
{
const
hashedPassword
=
await
bcrypt
.
hash
(
password
,
10
);
const
hashedPassword
=
await
bcrypt
js
.
hash
(
password
,
10
);
return
new
Promise
((
resolve
,
reject
)
=>
{
this
.
db
.
query
(
'
INSERT INTO users (username, email, password) VALUES (?, ?, ?)
'
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment