다음은 사용자 (로그인하지 않은 사용자)가 내가 이메일로 보낸 확인 링크를 따라갈 때 사용자 확인이 작동하는 방식입니다.
업데이트 : 좋습니다. 사용자 확인은 단순히 이메일 주소가 존재하는지 테스트하는 것이며 보안과는 아무 관련이 없습니다. 그렇긴하지만이 질문을 예로 들어 양식의 리디렉션 위치를 변경하는 방법을 알고 싶습니다.
they follow confirm path -> redirect to sign in form -> they sign in correctly -> they have to follow link again -> they reach the confirm action -> they are confirmed
이것은 약간 어색합니다. 차라리 이런 일이 발생합니다.
they follow confirm path -> redirect to sign in form -> they sign in correctly -> they reach the confirm action -> they are confirmed
두 번째로 링크를 따라갈 필요를 없애고 싶지만 어떻게 진행해야할지 잘 모르겠습니다. 내 로그인 양식은 다음과 같습니다.
<%= form_for(:session, url: sessions_path) do |f| %>
<%= f.label 'Email address' %><br>
<%= f.text_field :email, class: 'form-control', placeholder: 'Enter email' %><br>
<%= f.label 'Password' %><br>
<%= f.password_field :password, class: 'form-control', placeholder: 'Enter password' %><br>
<%= f.submit 'Sign In', class: 'btn btn-default' %>
<% end %>
내 세션에 매개 변수를 전달합니다. # create 작업 :
def create
user = User.find_by(email: params[:session][:email].downcase )
if user && user.authenticate(params[:session][:password])
sign_in(user)
redirect_to user_path(current_user)
else
flash.now[:error] = 'Wrong email or password!'
render 'new'
end
end
이제 핵심이 조치의 5 행에 있다고 생각합니다.
redirect_to user_path(current_user)
그것은 변경되어야합니다. 여기서 함께 뭔가를 해킹 할 수 있다고 확신하지만 어떻게 문제를 해결할 수 있는지 알고 싶습니다.
그렇긴하지만이 질문을 예로 들어 양식의 리디렉션 위치를 변경하는 방법을 알고 싶습니다.
나는 당신에게 아이디어와 모든 사람들이 따르는 가장 일반적인 연습을 줄 수 있습니다.
사용자가 로그인하지 않은 경우 요청 된 경로를 저장하고 해당 부분으로 리디렉션하면됩니다. Devise gem은 동일한 전략을 사용합니다. 사용하는 경우 이점을 활용할 수 있습니다.
일반적인 해결책을 설명하고 있습니다. 저장된 위치를 저장하고 얻으려면 application
컨트롤러에 두 가지 방법이 필요합니다.
store_location
: 위치를 저장하기 위해 로그인 후 리디렉션합니다.def store_location(location)
if location
uri = URI.parse(location)
session["return_path"] = [uri.path.sub(/\A\/+/, '/'), uri.query].compact.join('?')
end
end
stored_location
: 저장된 위치 (시도한 위치)를 검색합니다. 세션 경로도 삭제합니다 (마지막 부분에서 설명하겠습니다).def stored_location
location = session["return_path"]
session.delete("return_path")
location
end
confirmation
컨트롤러 에서 이와 같은 작업을해야합니다.
before_action: authenticated!
def authenticated!
unless signed_in?
store_location_for(request.original_url)
redirect_to sign_in_path
end
end
session#create
컨트롤러를 사용자 지정하기 만하면 다음과 같이 작동합니다.
redirect_to stored_location || user_path(current_user)
자, 당신의 senerio를 고려하십시오
session.delete("return_path")
.이것이 명확 해지기를 바랍니다.
추신 : 위의 코드는 추상적 인 아이디어입니다. 역할 기반 앱이있는 경우 위치 범위를 다르게 지정해야합니다.이 주제를 훨씬 넘어서서 설명하지 않았습니다. 더 자세히 알고 싶다면 gem 사양을 읽어보세요.devise
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다