Sprankelprachtig aan/afmeldsysteem

dashboard_controller.rb 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. class DashboardController < ApplicationController
  2. before_action :require_login!
  3. def home
  4. @upcoming = current_person
  5. .participants
  6. .joins(:activity)
  7. .where('activities.end >= ? OR (activities.end IS NULL AND activities.start >= ?)', Time.zone.now, Time.zone.now)
  8. .order('activities.start ASC')
  9. @user_organized = @upcoming
  10. .where(is_organizer: true)
  11. .limit(3)
  12. @upcoming = @upcoming
  13. .paginate(page: params[:upage], per_page: 10)
  14. @need_response = @upcoming
  15. .where(attending: nil)
  16. .paginate(page: params[:nrpage], per_page: 5)
  17. end
  18. def set_settings_params!
  19. @person = current_person
  20. @send_attendance_reminder = @person.send_attendance_reminder
  21. @active_sessions = Session.where(user: current_user).where(active: true).where('expires > ?', Time.zone.now).count
  22. end
  23. def settings
  24. set_settings_params!
  25. end
  26. def update_email_settings
  27. p = current_person
  28. p.send_attendance_reminder = params[:send_attendance_reminder]
  29. p.save
  30. flash_message(:success, t('settings.saved'))
  31. redirect_to root_path
  32. end
  33. def logout_all_sessions
  34. u = current_user
  35. u.logout_all_sessions!
  36. log_out
  37. redirect_to login_path
  38. end
  39. def update_password
  40. u = current_user
  41. current = params[:current_password]
  42. new = params[:new_password]
  43. confirm = params[:new_password_confirm]
  44. unless u.authenticate(current)
  45. flash_message(:danger, t('authentication.invalid_pass'))
  46. redirect_to settings_path
  47. return
  48. end
  49. if new.blank?
  50. flash_message(:danger, t('authentication.password_blank'))
  51. redirect_to settings_path
  52. return
  53. end
  54. if new != confirm
  55. flash_message(:danger, t('authentication.password_repeat_mismatch'))
  56. redirect_to settings_path
  57. return
  58. end
  59. u.password = new
  60. u.password_confirmation = confirm
  61. if u.save
  62. flash_message(:success, t('authentication.password_changed'))
  63. u.logout_all_sessions!
  64. log_out
  65. redirect_to login_path
  66. return
  67. else
  68. flash_message(:danger, t(:somethingbroke))
  69. Rails.logger.error('Password change failure')
  70. redirect_to settings_path
  71. end
  72. end
  73. end