Class: UsersController

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

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
# File 'app/controllers/users_controller.rb', line 11

def create
  @user.set_email_verification_key
  @user.save!
  UserMailer::email_verification(@user).deliver
  redirect_to root_path, :notice => "Thank you, please check your email to complete the registration."
rescue ActiveRecord::RecordInvalid
  render :action => :new
end

#destroyObject



56
57
58
59
60
61
# File 'app/controllers/users_controller.rb', line 56

def destroy
  logout
  @user.destroy
  flash[:alert] = "Your account has been deleted."
  redirect_to root_path
end

#editObject



20
# File 'app/controllers/users_controller.rb', line 20

def edit; end

#newObject



7
8
9
# File 'app/controllers/users_controller.rb', line 7

def new
  # ...
end

#resend_email_verificationObject



43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/users_controller.rb', line 43

def resend_email_verification
  if @user = User.where(:email_verification_key => params[:email_verification_key]).first
    # Just ignore it if the user is already verified
    if @user.is_verified?
      flash[:notice] = "Your account has already been validated. You can now login."
    else
      UserMailer::email_verification(@user).deliver
      flash[:notice] = "The email verification has been sent to #{@user.email}"
    end
  end
  redirect_to 
end

#updateObject



22
23
24
25
26
27
# File 'app/controllers/users_controller.rb', line 22

def update
  @user.update_attributes!(params[:user])
  redirect_to(user_path, :notice => 'Your profile has been updated')
rescue ActiveRecord::RecordInvalid
  render :action => :edit
end

#verify_emailObject



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/users_controller.rb', line 29

def verify_email
  if @user = User.where(:email_verification_key => params[:email_verification_key]).first
    @user.update_attributes(
      :verified_at => Time.now,
      :email_verification_key => nil
    )
    flash[:notice] = "Your email address has been verified. You can now login"
    redirect_to 
  else
    flash[:alert] = "We were not able to verify your account. Please contact us for assistance."
    redirect_to root_path
  end
end