Advertisement
Guest User

Untitled

a guest
Jun 28th, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. userSpecificData:any = {_id:'-',name: '-', email: '-', username: '-', password: '-', phone: '-',education:'-',location:'-',title:'-',company:'-'}
  2. onEditFormSubmit(){
  3. const user = {
  4. _id:this.userSpecificData._id,
  5. name: this.userSpecificData.name,
  6. email: this.userSpecificData.email,
  7. username: this.userSpecificData.username,
  8. password: this.userSpecificData.password,
  9. phone:this.userSpecificData.phone,
  10. location:this.userSpecificData.location,
  11. title:this.userSpecificData.title,
  12. company:this.userSpecificData.company,
  13. education:this.userSpecificData.education
  14. }
  15. if (this.EditPageUserForm.dirty && this.EditPageUserForm.valid) {
  16. this.authService.updateUserData(user).subscribe(data => {
  17. console.log(data);
  18. if(data.success){
  19. this.flashMessage.show('You are now successfully registered, redirecting to Login page..', {cssClass: 'alert-success', timeout: 4000});
  20. //setTimeout(function(){
  21. this.navCtrl.push(LoginPage);
  22. // },4000)
  23.  
  24. console.log('sucess');
  25. } else {
  26. this.flashMessage.show('Something went wrong', {cssClass: 'alert-danger', timeout: 4000});
  27. // this.router.navigate(['/register']);
  28. console.log('faild');
  29. return false;
  30. }
  31. });
  32. }
  33. }
  34.  
  35. updateUserData(user) {
  36. let headers = new Headers();
  37. console.log(headers,user);
  38. headers.append('Content-Type','application/json');
  39. return this.http.put('http://localhost:3000/users/user/:id', user,{headers: headers})
  40. .map(res => res.json());
  41. }
  42.  
  43. router.put('/user/:id', function(req, res){
  44. User.findByIdAndUpdate({_id: req.params.id},
  45. {
  46. name: req.body.name,
  47. email: req.body.email,
  48. username: req.body.username,
  49. phone:req.body.phone,
  50. location:req.body.location,
  51. title:req.body.title,
  52. company:req.body.company,
  53. education:req.body.education
  54. }, function(err, docs){
  55. if(err) res.json(err);
  56. else
  57. {
  58. console.log(docs);
  59. res.redirect('/user/'+req.params.id);
  60. }
  61. });
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement