Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- login(email: string, password: string) {
- let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
- let options = new RequestOptions({ headers: headers });
- let body = { EmailAddress: email, Password: password };
- return this.http.post('http://localhost:3000/api/user/login', body, options )
- .map((response: Response) => {
- let user = response.json();
- if (user && user.token) {
- localStorage.setItem('currentUser', JSON.stringify(user));
- }
- });
- }
- app.post('/api/user/login', urlencodedBodyparser, function (req, res) {
- console.log(req.body);
- User.find({ "EmailAddress": req.body["EmailAddress"], "Password": req.body["Password"] }, function (err, users) {
- console.log(users.length);
- if (err != null) {
- sendError(err, res);
- }
- if (users != null) {
- var count = users.length;
- if (count > 0) {
- response.data = users[0];
- res.json(response);
- }
- else {
- sendError({ message :'No user found'}, res);
- console.log("Login Failed");
- }
- }
- else {
- sendError(err, res);
- }
- })
- });
Add Comment
Please, Sign In to add comment