Guest User

Untitled

a guest
Feb 18th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. My.coreStateChart = SC.Statechart.create({
  2. rootState: SC.State.design({
  3. initialSubstate: 'checkingState',
  4.  
  5. checkingState: SC.State.design({
  6. enterState: function(){
  7. return SC.Async.perform('isLoggedInCheck');
  8. },
  9.  
  10. exitState: function() {
  11.  
  12. },
  13.  
  14. isLoggedInCheck: function() {
  15. SC.Request.getUrl('/api/user/is_logged').notify(this, 'isLoggedInResponse').header({ 'Accept': 'applicaton/json' }).send();
  16. },
  17.  
  18. isLoggedInResponse: function(response) {
  19. this.resumeGotoState();
  20.  
  21. if (SC.ok(response)) {
  22. var response = SC.json.decode(response.encodedBody());
  23.  
  24. if (response.status == 'OK') {
  25. this.gotoState('mainState');
  26. }
  27. else {
  28. this.gotoState('displayState');
  29. }
  30. }
  31. }
  32. }),
  33.  
  34. displayState: SC.State.design({
  35. enterState: function() {
  36. My.getPath('LoginPage').append();
  37. },
  38.  
  39. exitState: function() {
  40. My.getPath('LoginPage').remove();
  41. },
  42.  
  43. loginClicked: function() {
  44. return SC.Async.perform('loginCheck');
  45. },
  46.  
  47. loginCheck: function() {
  48. if (My.loginController.username == '' || My.loginController.password == '') My.displayController.showError('Username or password field empty.', 'Please try again.');
  49. else
  50. if (!isRFC822ValidEmail(this.username)) My.displayController.showError('Email address not valid.', 'Please try again.');
  51. else {
  52. var tmp = sha1(this.password);
  53. var object = { username: this.username, password: tmp };
  54. SC.Request.postUrl('/api/user/login').notify(this, 'loginResponse').header({ 'Accept': 'applicaton/json' }).json().send(object);
  55. }
  56. },
  57.  
  58. loginResponse: function(response) {
  59. if (SC.ok(response)) {
  60. var response = SC.json.decode(response.encodedBody());
  61.  
  62. this.resumeGotoState();
  63.  
  64. if (response.status == 'OK') {
  65. gotoState('mainState');
  66. }
  67. else {
  68. My.displayController.showError("Wrong username or password.", "Please try again.");
  69. this.gotoState('displayState');
  70. }
  71. }
  72. }
  73. }),
  74.  
  75. mainState: SC.State.design({
  76. enterState: function() {
  77. My.getPath('MainPage').append();
  78. },
  79.  
  80. exitState: function() {
  81. My.getPath('MainPage').remove();
  82. }
  83.  
  84. })
  85. })
  86. });
Add Comment
Please, Sign In to add comment