login: refactor login form to use simple form.
Also change form to pass params as e.g. `session[name]` instead of just `name`.
This commit is contained in:
@@ -7,11 +7,12 @@ class SessionsController < ApplicationController
|
||||
end
|
||||
|
||||
def create
|
||||
session_creator = SessionCreator.new(session, params[:name], params[:password], request.remote_ip)
|
||||
session_params = params[:session].presence || params
|
||||
session_creator = SessionCreator.new(session, session_params[:name], session_params[:password], request.remote_ip)
|
||||
|
||||
if session_creator.authenticate
|
||||
url = params[:url] if params[:url] && params[:url].start_with?("/")
|
||||
url = posts_path if url.nil?
|
||||
url = session_params[:url]
|
||||
url = posts_path if !url&.start_with?("/")
|
||||
respond_with(session_creator.user, location: url, methods: [:api_token])
|
||||
else
|
||||
flash.now[:notice] = "Password was incorrect"
|
||||
|
||||
@@ -2,28 +2,17 @@
|
||||
<div id="a-new">
|
||||
<section>
|
||||
<h1>Sign in</h1>
|
||||
<%= form_tag(session_path, :class => "simple_form") do %>
|
||||
<%= hidden_field_tag "url", params[:url] %>
|
||||
|
||||
<div class="input">
|
||||
<label for="name">Name</label>
|
||||
<%= text_field_tag :name %>
|
||||
</div>
|
||||
|
||||
<div class="input">
|
||||
<label for="password">Password</label>
|
||||
<%= password_field_tag :password %>
|
||||
</div>
|
||||
|
||||
<p class="fineprint">
|
||||
New to <%= Danbooru.config.app_name %>? <%= link_to "Create a new account", new_user_path %>.
|
||||
</p>
|
||||
|
||||
<div class="input">
|
||||
<%= submit_tag "Submit", :data => { :disable_with => "Signing in..." } %>
|
||||
</div>
|
||||
<%= simple_form_for(:session, url: session_path) do |f| %>
|
||||
<%= f.input :url, as: :hidden, input_html: { value: params[:url] } %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :password, input_html: { autocomplete: "password" } %>
|
||||
<%= f.submit "Login" %>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<p class="fineprint">
|
||||
New to <%= Danbooru.config.app_name %>? <%= link_to "Create a new account", new_user_path %>.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user