Module: Credible::Controllers::UsersController

Extended by:
ActiveSupport::Concern
Included in:
UsersController
Defined in:
lib/credible/controllers/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#confirmObject

GET /users/confirm/:confirmation_token GET /users/confirm/:confirmation_token.json



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/credible/controllers/users_controller.rb', line 38

def confirm
  @user = ::User.find_by(email: params[:email])

  @user.confirm(params[:confirmation_token])

  if @user.save
    @session = current_user ? current_session : ::Session.create(user: @user)
    render :show, status: :created, location: @user
  else
    render json: @user.errors, status: :unprocessable_entity
  end
end

#createObject

POST /users POST /users.json



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/credible/controllers/users_controller.rb', line 24

def create
  @user = ::User.new(user_params)

  if @user.save
    Credible::ConfirmationMailer.with(user: @user).confirmation_email.deliver_later
    @session = ::Session.create(user: @user)
    render :show, status: :created, location: @user
  else
    render json: @user.errors, status: :unprocessable_entity
  end
end

#destroyObject

DELETE /users/1 DELETE /users/1.json



82
83
84
85
# File 'lib/credible/controllers/users_controller.rb', line 82

def destroy
  @user.destroy
  head :no_content
end

#editObject

GET /users/1/edit



67
68
# File 'lib/credible/controllers/users_controller.rb', line 67

def edit
end

#newObject

GET /users/new



18
19
20
# File 'lib/credible/controllers/users_controller.rb', line 18

def new
  @user = ::User.new
end

#reset_passwordObject

POST /users/reset_password POST /users/reset_password.json



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/credible/controllers/users_controller.rb', line 53

def reset_password
  @user = ::User.find_by(email: user_params[:email])

  @user.reset_password

  if @user.save
    Credible::ResetPasswordMailer.with(user: @user).reset_password_email.deliver_later
    render :show, status: :ok, location: @user
  else
    render json: @user.errors, status: :unprocessable_entity
  end
end

#showObject

GET /users/1 GET /users/1.json



14
15
# File 'lib/credible/controllers/users_controller.rb', line 14

def show
end

#updateObject

PATCH/PUT /users/1 PATCH/PUT /users/1.json



72
73
74
75
76
77
78
# File 'lib/credible/controllers/users_controller.rb', line 72

def update
  if @user.update(user_params)
    render :show, status: :ok, location: @user
  else
    render json: @user.errors, status: :unprocessable_entity
  end
end