Class: Remotty::Users::RegistrationsController

Inherits:
Devise::RegistrationsController
  • Object
show all
Includes:
BaseController
Defined in:
app/controllers/remotty/users/registrations_controller.rb

Instance Method Summary collapse

Instance Method Details

#avatarObject

POST /resource/avatar 회원 프로필 이미지 수정



96
97
98
99
100
101
102
103
104
105
# File 'app/controllers/remotty/users/registrations_controller.rb', line 96

def avatar
  resource.avatar = params[:file]

  if resource.save
    render json: resource
  else
    render_error 'VALIDATION_ERROR',
                 resource.errors.full_messages.first
  end
end

#createObject

POST /resource 회원가입



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/controllers/remotty/users/registrations_controller.rb', line 8

def create
  build_resource()
  resource.use_password = true

  # oauth정보가 있으면 validation 체크
  if params[:oauth]
    unless valid_credential?(oauth_params)
      render_error 'UNAUTHORIZED', 'Oauth credentials information is invalid', :unauthorized and return
    end
  end

  if resource.save
    yield resource if block_given?

    resource.add_oauth_info(oauth_params) if params[:oauth]

    if resource.active_for_authentication?
      (resource_name, resource)

      token = resource.generate_auth_token!(auth_source)

      render json: resource.with_token(token)
    else
      expire_data_after_sign_in!

      render_error 'UNAUTHORIZED',
                   find_message("signed_up_but_#{resource.inactive_message}"),
                   :unauthorized
    end
  else
    clean_up_passwords resource

    render_error 'VALIDATION_ERROR',
                 resource.errors.full_messages.first
  end
end

#destroy {|resource| ... } ⇒ Object

DELETE /resource 회원탈퇴

Yields:

  • (resource)


122
123
124
125
126
127
128
# File 'app/controllers/remotty/users/registrations_controller.rb', line 122

def destroy
  resource.destroy
  Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
  set_flash_message :notice, :destroyed if is_flashing_format?
  yield resource if block_given?
  render nothing: true, status: :no_content
end

#remove_avatarObject

DELETE /resource/avatar 회원 프로필 이미지 삭제



109
110
111
112
113
114
115
116
117
118
# File 'app/controllers/remotty/users/registrations_controller.rb', line 109

def remove_avatar
  resource.avatar = nil

  if resource.save
    render json: resource
  else
    render_error 'VALIDATION_ERROR',
                 resource.errors.full_messages.first
  end
end

#updateObject

PUT /resource 회원정보 수정 (password 제외한 일반 정보)



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/controllers/remotty/users/registrations_controller.rb', line 47

def update
  self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
  prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)

  if [:password].blank? # password 수정이 아니면
    .delete("password")
    .delete("password_confirmation")

    if resource.update_without_password()
      yield resource if block_given?

      message_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
        :update_needs_confirmation : :updated

       resource_name, resource, :bypass => true, :store => false

      if message_key == :updated
        render json: resource
      else
        render_error 'UNAUTHORIZED',
                     find_message(message_key),
                     :unauthorized
      end
    else
      clean_up_passwords resource

      render_error 'VALIDATION_ERROR',
                   resource.errors.full_messages.first
    end
  else # password 수정이면
    if resource.use_password
      resource.update_with_password()
    else
      resource.use_password = true
      resource.update_attributes()
      clean_up_passwords resource
    end

    if resource.errors.blank?
      render json: resource
    else
      render_error 'VALIDATION_ERROR',
                   resource.errors.full_messages.first
    end
  end
end