forked from MohammadAkthamObeidat/Movies-Galaxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
54f457b
commit 4774047
Showing
5 changed files
with
268 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,53 @@ | ||
const user = require('../models/User'); | ||
|
||
const homePage = (req, res, next) => { | ||
res.send('<h1>HELLO FROM USER CONTROLLER</h1>'); | ||
res.send('<h1>HELLO FROM USER CONTROLLER</h1>'); | ||
}; | ||
|
||
// USER FUNCTIONS **************************************************************************** | ||
|
||
// Get one user. | ||
const login = (req, res, next) => { | ||
user.getUser(req.body, result => { | ||
console.log('RESULT FROM LOGIN RESPONSE: ', result); | ||
// res.json(result); | ||
res.status(200).json({ | ||
status: 'Success', | ||
data: { | ||
user: result | ||
} | ||
user.getUser(req.body, result => { | ||
console.log('RESULT FROM LOGIN RESPONSE: ', result); | ||
// res.json(result); | ||
res.status(200).json({ | ||
status: 'Success', | ||
data: { | ||
user: result | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
// Add new user to database. | ||
const signUp = (req, res, next) => { | ||
user.addUser(req.body, result => { | ||
console.log('RESULT FROM SIGN UP RESPONSE: ', result); | ||
// res.json(result); | ||
res.status(200).json({ | ||
status: 'Success', | ||
data: { | ||
user: result | ||
} | ||
user.addUser(req.body, result => { | ||
console.log('RESULT FROM SIGN UP RESPONSE: ', result); | ||
// res.json(result); | ||
res.status(201).json({ | ||
status: 'Success', | ||
data: { | ||
user: result | ||
} | ||
}); | ||
}); | ||
}); | ||
}; | ||
|
||
// Logout the users | ||
const logout = (req, res, next) => { | ||
// Delete session from the database to logout users. | ||
req.session.destroy(error => { | ||
console.log(error); | ||
// redirect user to the home page after logging out. | ||
res.redirect('/'); | ||
}); | ||
// Delete session from the database to logout users. | ||
req.session.destroy(error => { | ||
console.log(error); | ||
// redirect user to the home page after logging out. | ||
res.redirect('/'); | ||
}); | ||
}; | ||
|
||
// Exporting Methods. | ||
module.exports = { | ||
homePage, | ||
login, | ||
signUp, | ||
logout | ||
homePage, | ||
login, | ||
signUp, | ||
logout | ||
}; |
Oops, something went wrong.