Guest User

Untitled

a guest
Jul 25th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1.  
  2. // ==========================================================================
  3. // MyApp.LoginView
  4. // ==========================================================================
  5.  
  6. MyApp.LoginChoices = SC.View.extend(SC.StaticLayout, SC.Control,
  7. /** @scope MyApp.LoginChoices.prototype */ {
  8.  
  9. useStaticLayout: YES,
  10. classNames: 'modal-container',
  11. wantsAcceleratedLayer: YES,
  12. childViews: 'firstname loginButton'.w(),
  13.  
  14.  
  15. user: SC.TextFieldView.design({
  16. classNames: 'textfield user',
  17. valueBinding: 'MyApp.authController.user'
  18. }),
  19.  
  20. password: SC.TextFieldView.design({
  21. classNames: 'textfield password',
  22. hint: 'password',
  23. isPassword: YES,
  24. valueBinding: 'MyApp.authController.password'
  25. }),
  26.  
  27. loginButton: SC.ButtonView.design({
  28. acceptsFirstResponder: true,
  29. classNames: 'button',
  30. title: 'Login!',
  31. isDefault: YES,
  32. action: 'submitLogin'
  33. })
  34.  
  35. });
  36.  
  37. // ==========================================================================
  38. // MyApp.authStatechart
  39. // ==========================================================================
  40.  
  41. authLogin: Ki.State.design({
  42. submitLogin: function (evt) {
  43. valid = MyApp.authController.validateLogin();
  44. if (valid) {
  45. authLogin: function () {
  46. MyApp.authController.set('errorMessage', '');
  47. var user = MyApp.authController.get('user');
  48. var password = MyApp.authController.get('password');
  49.  
  50. if (user !== null && password !== null) {
  51. SC.$.ajax({
  52. type: 'POST',
  53. async: false,
  54. url: "/login/",
  55. data: { username: user, password: password },
  56. success: function(data){
  57. console.info('login success:', data);
  58. if (data.loggedin) {
  59. MyApp.coreStatechart.sendAction('loginOk');
  60. }
  61. if (data.notActive) {
  62. MyApp.coreStatechart.sendAction('notActive');
  63. }
  64. if (data.invalid) {
  65. MyApp.authController.set('errorMessage', 'Username or password not valid');
  66. MyApp.coreStatechart.sendAction('invalidLogin');
  67. }
  68. },
  69. error: function(data){
  70. console.info('Do something there is an error');
  71. }
  72. });
  73. }else{
  74. console.info('some field is not filled in');
  75. }
  76. }
  77. }
  78. }
  79. });
  80.  
  81. // ==========================================================================
  82. // MyApp.authController
  83. // ==========================================================================
  84.  
  85. MyApp.authController = SC.ObjectController.create(
  86. /** @scope MyApp.authController.prototype */ {
  87.  
  88. user: null,
  89. password: null
  90.  
  91. });
Add Comment
Please, Sign In to add comment