Class: Auth::OauthsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/auth/oauths_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/auth/oauths_controller.rb', line 4

def create
  session[:open_id] = oauth_params['uid']
  type = (oauth_params[:provider].to_s + '_user').classify

  @oauth_user = OauthUser.find_or_initialize_by(type: type, uid: oauth_params[:uid])
  @oauth_user.save_info(oauth_params)

  if @oauth_user.user.nil? && current_user
    @oauth_user.user = current_user
  elsif @oauth_user.user.nil? && !current_user
    if @oauth_user.same_user
      @oauth_user.user_id = @oauth_user.same_user.id
      redirect_back_or_default(my_root_url, alert: 'Oauth Success!') and return if @oauth_user.save
    else
      redirect_to join_mobile_url and return if @oauth_user.save
    end
  elsif @oauth_user.user
    redirect_back_or_default(my_root_url, alert: 'Oauth Success!')
  end
end

#failureObject



25
26
27
# File 'app/controllers/auth/oauths_controller.rb', line 25

def failure
  redirect_to root_url, alert: "错误: #{params[:message].humanize}"
end