Sha256: 423cc50ec6b24f590c60a313c225fea2c3eb24fddb80a7a9510bcf39009c2d64
Contents?: true
Size: 1.2 KB
Versions: 3
Compression:
Stored size: 1.2 KB
Contents
# frozen_string_literal: true module Decidim # This command updates the user's account. class UpdateAccount < Rectify::Command # Updates a user's account. # # user - The user to be updated. # form - The form with the data. def initialize(user, form) @user = user @form = form end def call return broadcast(:invalid) unless @form.valid? update_personal_data update_avatar update_password if @user.valid? @user.save! @form.remove_avatar = false broadcast(:ok, @user.unconfirmed_email.present?) else if @user.errors.has_key? :avatar @form.errors.add :avatar, @user.errors[:avatar] end broadcast(:invalid) end end private def update_personal_data @user.name = @form.name @user.email = @form.email end def update_avatar if @form.avatar @user.avatar = @form.avatar elsif @form.remove_avatar @user.remove_avatar = true end end def update_password return unless @form.password.present? @user.password = @form.password @user.password_confirmation = @form.password_confirmation end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
decidim-core-0.1.0 | app/commands/decidim/update_account.rb |
decidim-core-0.0.8.1 | app/commands/decidim/update_account.rb |
decidim-core-0.0.7 | app/commands/decidim/update_account.rb |