Class: Symphonia::AccountsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/symphonia/accounts_controller.rb

Reset lost password collapse

Instance Method Summary collapse

Methods included from ControllerExtensions

#admin_require, #authorize, #back_url, #current_user, #current_user_session, #handle_unverified_request, #login_require, #menu_item, #redirect_back_or_default, #redirect_to_referer_or, #render_403, #render_404, #render_api_head, #render_api_ok, #set_default_locale, #set_locale, #store_location

Instance Method Details

#activationObject



85
86
87
88
89
90
91
92
93
# File 'app/controllers/symphonia/accounts_controller.rb', line 85

def activation
  @user = (params[:activation_code])
  if @user
    @user.activate!
    redirect_to , notice: t(:text_activation_success)
  else
    redirect_to root_path, flash: { error: t(:text_user_not_found_or_token_invalid) }
  end
end

#adminObject



99
100
101
# File 'app/controllers/symphonia/accounts_controller.rb', line 99

def admin

end

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/symphonia/accounts_controller.rb', line 23

def create
  menu_item(:register)
  @user.attributes = user_params
  @user.status = if Symphonia.config[:self_activation_enabled]
                   :active
                 else
                   :pending
                 end
  respond_to do |format|
    if @user.valid? && verify_registration && @user.save(validate: false)
      Notifier.activation_user(@user).deliver_later
      Notifier.user_registered(@user).deliver_later
      format.html { redirect_to '/', notice: t(:text_user_registered) }
      format.json { render status: :created }
    else
      format.html { render action: 'register' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

#currentObject



95
96
97
# File 'app/controllers/symphonia/accounts_controller.rb', line 95

def current

end

#editObject



44
45
46
# File 'app/controllers/symphonia/accounts_controller.rb', line 44

def edit
  @user = 
end

#lost_passwordObject



119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'app/controllers/symphonia/accounts_controller.rb', line 119

def lost_password
  @user = (params[:email]) if params[:email]
  if @user&.active?
    @user.reset_perishable_token!
    activation_url = url_for(action: "reset_password", id: @user.perishable_token, only_path: false)
    Notifier.reset_password_user(@user, activation_url).deliver_later
  end
  respond_to do |format|
    format.html do
      redirect_to , notice: t(:text_reset_password_resend)
    end
    format.js
  end
end

#new_activationObject




67
68
# File 'app/controllers/symphonia/accounts_controller.rb', line 67

def new_activation
end

#registerObject



19
20
21
# File 'app/controllers/symphonia/accounts_controller.rb', line 19

def register
  menu_item(:register)
end

#resend_activationObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/symphonia/accounts_controller.rb', line 70

def resend_activation
  @user = (params.require(:email))
  if @user
    if @user.active?
      redirect_to root_path, flash: { error: t(:text_user_alerady_active) }
    else
      @user.reset_perishable_token!
      Notifier.activation_user(@user).deliver_later
      redirect_to root_path, notice: t(:text_activation_resend)
    end
  else
    redirect_to root_path, flash: { error: t(:text_user_not_found) }
  end
end

#reset_passwordObject



105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'app/controllers/symphonia/accounts_controller.rb', line 105

def reset_password
  @user = (params.require(:id))
  return render_404 if @user.nil?

  if params[:password] # && params[:password_confirmation]
    @user.password = params[:password]
  end

  if @user.changed? && @user.save
    logger.info "#{@user.id} has changed password"
    return redirect_to(, notice: t(:text_password_reset_success))
  end
end

#showObject



10
11
12
13
14
15
16
17
# File 'app/controllers/symphonia/accounts_controller.rb', line 10

def show
  @user = 

  respond_to do |format|
    format.html { render(template: "#{@user.class.name.underscore.pluralize}/show") }
    format.json { render json: @user }
  end
end

#updateObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/controllers/symphonia/accounts_controller.rb', line 48

def update
  @user = 
  @user.attributes = user_params
  respond_to do |format|
    @user.edited_by = User.current.logged_in? && User.current
    @user.edited_at = Time.now
    if @user.save
      format.html { redirect_to({ action: 'show' }, notice: t(:text_updated)) }
      format.json { head :no_content }
      format.js
    else
      format.html { render action: 'edit' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end