spacedeck_account.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. SpacedeckAccount
  3. This module contains functions dealing with the spacedeck account.
  4. */
  5. SpacedeckAccount = {
  6. data: {
  7. account_confirmed_sent: false,
  8. account_tab: 'invoices',
  9. password_change_error: null,
  10. feedback_text: "",
  11. importables: [], // spacedeck.com zip import files
  12. },
  13. methods: {
  14. show_account: function() {
  15. this.activate_dropdown('account');
  16. },
  17. start_zip_import: function(f) {
  18. if (confirm("Your archive will be imported in the background. This can take a few minutes. You can continue using Spacedeck in the meantime.")) {
  19. import_zip(this.user, f);
  20. }
  21. },
  22. account_save_user_digest: function(val) {
  23. this.user.prefs_email_digest = val;
  24. this.save_user(function() {
  25. });
  26. },
  27. account_save_user_notifications: function(val) {
  28. this.user.prefs_email_notifications = val;
  29. this.save_user(function() {
  30. });
  31. },
  32. save_user_email: function() {
  33. this.save_user(function() {
  34. }.bind(this));
  35. },
  36. save_user_language: function(lang) {
  37. localStorage.lang = lang;
  38. this.user.prefs_language = lang;
  39. this.save_user(function() {
  40. window._spacedeck_location_change = true;
  41. location.href="/spaces";
  42. }.bind(this));
  43. },
  44. save_user: function(on_success) {
  45. if (this.user.email_changed) {
  46. this.user.confirmed_at = null;
  47. }
  48. window._spacedeck_location_change = true;
  49. save_user(this.user, function(user) {
  50. if (on_success) on_success();
  51. else location.href="/spaces";
  52. }.bind(this), function(xhr){
  53. console.error(xhr)
  54. });
  55. },
  56. save_user_password: function(oldPass, newPass, newPassConfirm) {
  57. this.password_change_error = null;
  58. if (!oldPass) {
  59. this.password_change_error = "Current password required";
  60. return;
  61. }
  62. if (!newPass || !newPassConfirm) {
  63. this.password_change_error = "New password/password confirmation required";
  64. return;
  65. }
  66. if (newPass!=newPassConfirm) {
  67. this.password_change_error = "New Passwords do not match";
  68. return;
  69. }
  70. if (newPass.length < 6) {
  71. this.password_change_error = "New Password to short";
  72. return;
  73. }
  74. save_user_password(this.user, oldPass, newPass, function() {
  75. alert("OK. Password Changed.");
  76. this.password_change_current = "";
  77. this.password_change_new = "";
  78. this.password_change_new_confirmation = "";
  79. }.bind(this), function(xhr) {
  80. if (xhr.status == 403) {
  81. this.password_change_error = "Old Password not correct";
  82. } else {
  83. this.password_change_error = "Something went wrong. Please try again later.";
  84. }
  85. }.bind(this));
  86. },
  87. confirm_again: function() {
  88. resent_confirm_mail(this.user, function(re) {
  89. this.account_confirmed_sent = true;
  90. alert(__("confirm_again"));
  91. }.bind(this), function(xhr){
  92. console.error(xhr);
  93. alert("Something went wrong, please try again.");
  94. });
  95. },
  96. confirm_account: function(token) {
  97. confirm_user(this.user, token, function(re) {
  98. smoke.alert(__("confirmed"), function() {
  99. this.redirect_to("/spaces");
  100. }.bind(this));
  101. }.bind(this), function(xhr) {
  102. console.error(xhr);
  103. alert(xhr.responseText);
  104. this.redirect_to("/spaces");
  105. }.bind(this));
  106. },
  107. }
  108. }