基于设计current_user帮助程序编辑用户是否安全?

时间:2016-09-22 05:03:03

标签: ruby-on-rails devise

我使用Devise,Omniauth-twitter和Omniauth-facebook进行我的rails app身份验证,我不得不制作自己的控制器来编辑用户参数,而不需要为Facebook和Twitter等提供商提供密码。 而不是通过用户ID将用户路由到他的配置文件,我使用设计帮助器current_user来显示和编辑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 %>

1 个答案:

答案 0 :(得分:0)

如果你正在使用Devise,你可以使用他们现有的视图而不是你试图自己实现它们。但是,我目前的方法并没有看到任何安全威胁,只是浪费时间。

查看设计文档并查看配置视图部分,

https://github.com/plataformatec/devise