Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I_Helmet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
21_22-J 62
I_Helmet
Commits
3b725380
Commit
3b725380
authored
Apr 28, 2022
by
Balasuriya D.A.M.
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Login API with new pointers
parent
dd2525eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletion
+25
-1
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
...emedicine-Chat-App/backend/controllers/userControllers.js
+24
-0
IT18021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
...021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
+1
-1
No files found.
IT18021080/Telemedicine-Chat-App/backend/controllers/userControllers.js
View file @
3b725380
...
@@ -2,6 +2,7 @@ const asyncHandler = require("express-async-handler");
...
@@ -2,6 +2,7 @@ const asyncHandler = require("express-async-handler");
const
User
=
require
(
"
../models/userModel
"
);
const
User
=
require
(
"
../models/userModel
"
);
const
generateToken
=
require
(
"
../config/generateToken
"
);
const
generateToken
=
require
(
"
../config/generateToken
"
);
//Add registerUser function
const
registerUser
=
asyncHandler
(
async
(
req
,
res
)
=>
{
const
registerUser
=
asyncHandler
(
async
(
req
,
res
)
=>
{
const
{
name
,
email
,
password
,
pic
}
=
req
.
body
;
const
{
name
,
email
,
password
,
pic
}
=
req
.
body
;
...
@@ -39,4 +40,27 @@ const registerUser = asyncHandler(async (req, res) => {
...
@@ -39,4 +40,27 @@ const registerUser = asyncHandler(async (req, res) => {
}
}
});
});
//Add authUser function
const
authUser
=
asyncHandler
(
async
(
req
,
res
)
=>
{
//login user
const
{
email
,
password
}
=
req
.
body
;
//Find our user
const
user
=
await
User
.
findOne
({
email
});
//If user is already exist check it with DB data such as password
if
(
user
)
{
res
.
json
({
_id
:
user
.
_id
,
name
:
user
.
name
,
email
:
user
.
email
,
pic
:
user
.
pic
,
token
:
generateToken
(
user
.
_id
),
});
}
else
{
res
.
status
(
401
);
throw
new
Error
(
"
Invalid Email or Password
"
);
}
});
module
.
exports
=
{
registerUser
};
module
.
exports
=
{
registerUser
};
\ No newline at end of file
IT18021080/Telemedicine-Chat-App/backend/routes/userRoutes.js
View file @
3b725380
...
@@ -4,6 +4,6 @@ const { registerUser } = require("../controllers/userControllers");
...
@@ -4,6 +4,6 @@ const { registerUser } = require("../controllers/userControllers");
const
router
=
express
.
Router
();
const
router
=
express
.
Router
();
router
.
route
(
"
/
"
).
post
(
registerUser
);
router
.
route
(
"
/
"
).
post
(
registerUser
);
//router.post("/login",authUser)
router
.
post
(
"
/login
"
,
authUser
);
module
.
exports
=
router
;
module
.
exports
=
router
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment