You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

96 lines
1.9 KiB

  1. define([
  2. 'js/system/events',
  3. 'js/system/client',
  4. 'ui/factory',
  5. 'html!ui/templates/login/template',
  6. 'css!ui/templates/login/styles',
  7. 'js/rendering/renderer'
  8. ], function (
  9. events,
  10. client,
  11. uiFactory,
  12. template,
  13. styles,
  14. renderer
  15. ) {
  16. return {
  17. tpl: template,
  18. centered: true,
  19. postRender: function () {
  20. this.onEvent('onHandshake', this.onHandshake.bind(this));
  21. this.on('.btnLogin', 'click', this.onLoginClick.bind(this));
  22. this.on('.btnRegister', 'click', this.onRegisterClick.bind(this));
  23. this.find('.extra, .version')
  24. .appendTo($('<div class="uiLoginExtra"></div>')
  25. .appendTo('.ui-container'));
  26. $('.uiLoginExtra').find('.button').on('click', this.redirect.bind(this));
  27. $('.news, .version').on('click', this.redirect.bind(this));
  28. this.find('input')
  29. .on('keyup', this.onKeyDown.bind(this))
  30. .eq(0).focus();
  31. renderer.buildTitleScreen();
  32. },
  33. redirect: function (e) {
  34. let location = $(e.target).attr('location');
  35. window.open(location, '_blank');
  36. },
  37. onKeyDown: function (e) {
  38. if (e.keyCode == 13)
  39. this.onLoginClick();
  40. },
  41. onHandshake: function () {
  42. this.show();
  43. },
  44. onLoginClick: function () {
  45. if (this.el.hasClass('disabled'))
  46. return;
  47. this.el.addClass('disabled');
  48. client.request({
  49. cpn: 'auth',
  50. method: 'login',
  51. data: {
  52. username: this.val('.txtUsername'),
  53. password: this.val('.txtPassword')
  54. },
  55. callback: this.onLogin.bind(this)
  56. });
  57. },
  58. onLogin: function (res) {
  59. this.el.removeClass('disabled');
  60. if (!res) {
  61. uiFactory.build('characters', {});
  62. $('.uiLoginExtra').remove();
  63. this.el.remove();
  64. } else
  65. this.el.find('.message').html(res);
  66. },
  67. onRegisterClick: function () {
  68. this.el.addClass('disabled');
  69. client.request({
  70. cpn: 'auth',
  71. method: 'register',
  72. data: {
  73. username: this.val('.txtUsername'),
  74. password: this.val('.txtPassword')
  75. },
  76. callback: this.onLogin.bind(this)
  77. });
  78. }
  79. };
  80. });