diff options
author | DavisLWebb <davislwebb@ymail.com> | 2014-03-06 14:23:11 -0500 |
---|---|---|
committer | DavisLWebb <davislwebb@ymail.com> | 2014-03-06 14:23:11 -0500 |
commit | cd020cb3c9f8a1d40af4958c26dcdfb97e1a80c1 (patch) | |
tree | 13d21ffad45f55b7c6b7c8516b1105240127cf67 | |
parent | 5bd262333beb533cc08f21f7398e3ed1e890a23d (diff) |
Users can now log in with user_name and email but I could not make one text box for both
-rw-r--r-- | app/controllers/sessions_controller.rb | 24 | ||||
-rw-r--r-- | app/views/sessions/new.html.erb | 7 |
2 files changed, 20 insertions, 11 deletions
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index b5ea29b..f857f27 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -11,7 +11,13 @@ class SessionsController < ApplicationController # POST /sessions.json def create # find the user... - @user = User.find_by(email: params[:session][:email].downcase) + + @user = User.find_by(email: params[:session][:email]) + + if @user.nil? + @user = User.find_by_user_name(params[:session][:user_name]) + end + #@session = Session.new(@user) # ... and create a new session respond_to do |format| @@ -39,13 +45,13 @@ class SessionsController < ApplicationController private - # Use callbacks to share common setup or constraints between actions. - def set_session - #@session = Session.find(cookies[:remember_token]) - end + # Use callbacks to share common setup or constraints between actions. + def set_session + #@session = Session.find(cookies[:remember_token]) + end - # Never trust parameters from the scary internet, only allow the white list through. - def session_params - params.require(:session).permit(:session_email, :session_password) - end + # Never trust parameters from the scary internet, only allow the white list through. + def session_params + params.require(:session).permit(:session_email, :session_user_name, :session_password) + end end diff --git a/app/views/sessions/new.html.erb b/app/views/sessions/new.html.erb index 550a54d..6d73b1f 100644 --- a/app/views/sessions/new.html.erb +++ b/app/views/sessions/new.html.erb @@ -1,13 +1,16 @@ <h1>Sign in</h1> <% if @user.nil? %> - <p class="errors"> The username or password is incorrect. Verify that CAPS LOCK is not on, and then retype the current username and password. </p> + <p class="errors"> The email or password is incorrect. Verify that CAPS LOCK is not on, and then retype the current email and password. </p> <% end %> <div class="row"> <div class="span6 offset3"> <%= form_for(:session, url: sessions_path) do |f| %> <%= f.label :email %> - <%= f.text_field :email %> + <%= f.text_field :email%> + + <%= f.label :user_name %> + <%= f.text_field :user_name%> <%= f.label :password %> <%= f.password_field :password %> |