2016-09-22 26 views
2

我正在使用Devise,Omniauth-twitter和Omniauth-facebook進行我的Rails應用程序認證,並且我不得不使用自己的控制器來編輯用戶參數,而無需使用Facebook和Twitter等提供程序提供的用戶密碼。 而不是用他的用戶ID路由用戶到他的個人資料,我用設計助手current_user顯示和編輯current_user參數 我的問題是..是否安全地做到這一點? 我是初學者..所以,當一件事情完成時,我很擔心安全漏洞。這是我的代碼。基於devise current_user helper編輯用戶是否安全?

profile_controller.rb

class ProfileController < ApplicationController 
    before_action :authenticate_user! 
    def show 
     @user = current_user 
    end 

    def edit 
     @profile = current_user 
    end 
    def update 
     @profile = current_user 
     if @profile.update(profile_params) 
      redirect_to profile_path(@profile) 
     else 
      render 'edit' 
     end 
    end 
    private 
    def profile_params 
     params.require(:user).permit(:username,:first_name,:last_name,:gender) 
    end 
end 

的routes.rb

get'profile' => 'profile#show' 
get'profile/edit' => 'profile#edit' 
patch'profile/edit' => 'profile#update' 

edit.html.erb

<%= form_for @profile, url: {action: "edit"} do |f| %> 

    <%= f.text_field :username, autofocus: true %> 

    <%= f.text_field :first_name, autofocus: true %> 

    <%= f.text_field :last_name, autofocus: true %> 

    <%= f.text_field :gender, autofocus: true %> 

    <%= f.submit "Sign up" %> 

<% end %> 

回答

0

那麼,如果你使用的是設計,你可以讓他們現有的用戶意見而不是你試圖自己實現它們。但是,我認爲目前的方法沒有發現任何安全威脅,只是浪費時間。

看一看的色器件文檔並檢查配置視圖部分,

https://github.com/plataformatec/devise

相關問題