2016-09-22 7 views
2

私はDevils、Omniauth-twitter、Omniauth-facebookを使って私のレールアプリの認証をしています。私はfacebookとtwitterのようなプロバイダのユーザーのパスワードを必要とせずにユーザパラメータを編集するために自分のコントローラを作っていました。 そして、彼のユーザーIDで彼のプロフィールにユーザーをルーティングするのではなく、私はdeviseヘルパーcurrent_userを使用して、current_userパラメーターを表示および編集しました 私の質問は..それは安全ですか? 私は初心者です。何かが行われると、簡単にセキュリティ上の脆弱性が心配です。ここに私のコードです。devise current_userヘルパーに基づいてユーザーを編集するのは安全ですか?

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

関連する問題