Class: UsersController

Inherits:
ApplicationController
  • Object
show all
Defined in:
lib/generators/authkit/templates/app/controllers/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/authkit/templates/app/controllers/users_controller.rb', line 11

def create
  @user = User.new(user_create_params)
  if @user.save
    @user.send_confirmation
    (@user)
    respond_to do |format|
      format.json { head :no_content }
      format.html { redirect_to root_path }
    end
  else
    respond_to do |format|
      format.json { render json: { status: 'error', errors: @user.errors }.to_json, status: 422 }
      format.html { render :new }
    end
  end
end

#editObject



28
29
30
# File 'lib/generators/authkit/templates/app/controllers/users_controller.rb', line 28

def edit
  @user = current_user
end

#newObject

Signup



7
8
9
# File 'lib/generators/authkit/templates/app/controllers/users_controller.rb', line 7

def new
  @user = User.new
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/generators/authkit/templates/app/controllers/users_controller.rb', line 32

def update
  @user = current_user

  orig_confirmation_email = @user.confirmation_email

  if @user.update_attributes(user_update_params)
    # Send a new email confirmation if the user updated their email address
    if @user.confirmation_email.present? &&
       @user.confirmation_email != @user.email &&
       @user.confirmation_email != orig_confirmation_email
       @user.send_confirmation
    end
    respond_to do |format|
      format.json { head :no_content }
      format.html { redirect_to @user }
    end
  else
    respond_to do |format|
      format.json { render json: { status: 'error', errors: @user.errors }.to_json, status: 422 }
      format.html { render :edit }
    end
  end
end