Class: SignupsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/signups_controller.rb

Instance Method Summary collapse

Instance Method Details

#email_confirmationObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/signups_controller.rb', line 17

def email_confirmation
  @user = User.where(email_validation_token: params[:token]).first
  if @user && @user.email_validation_token_sent_at >= Time.zone.now - 1.hour
    @user.email_validated = true
    @user.save
    @email_confirmed = true
  elsif @user && @user.email_validation_token_sent_at <= Time.zone.now - 1.hour
    redirect_to root_url, alert: "Your verification token was created over an hour ago. Please restart the process."
  else
    @email_confirmed = false
  end
end

#email_verificationObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/controllers/signups_controller.rb', line 3

def email_verification
  unless params[:user][:email].blank?
    @user = User.find_or_initialize_by(email: params[:user][:email])
    set_email_validation_token
    @user.allow_newsletter = true
    @user.allow_daily_digests = true
    @user.save ? @validation_ready=true : @validation_ready=false
    SignupMailer.verification_email(@user).deliver
    Activity.create doer_id: @user.id, message: "signed up for the newsletter. Email: #{@user.email}"
  else
   redirect_to root_path, alert: 'Your email cannot be blank. Please enter your email address and try again'
  end
end