diff --git a/README.md b/README.md index c3325d4..26e74ba 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,19 @@ -### Dolphin Flash Cards -Created by Chris, Phil, Anne, Armando, Jaime and Mason +Restful Dolphins Flashcards +=========================== + + Created by Chris, Phil, Anne, Armando, Jaime and Mason ### Features: -1. etc -2. etc -4. etc -5. etc -6. +1. Flash Cards Quiz +2. Supports Multiple Decks +3. Tracking of Number of Correct and Incorrect Guesses +4. User Login Authentication +5. New User Register +6. Arabic, French and Chemistry sample decks + +**Try on Heroku:** +http://obscure-wave-1778.herokuapp.com/ + **Trello at:** https://trello.com/b/cU6Dl8uK/dolphin-restful-cards diff --git a/app/controllers/deck.rb b/app/controllers/deck.rb index 9efc231..df47961 100644 --- a/app/controllers/deck.rb +++ b/app/controllers/deck.rb @@ -8,7 +8,7 @@ User.find(session[:id]).rounds.create(deck_id: deck.id) session[:cards] = deck.cards.shuffle @card = session[:cards].pop - erb :show_card + erb :show_card, layout: false end post '/decks/:deck_id/cards/:card_id' do @@ -18,11 +18,12 @@ session.delete(:cards) @answer_eval = (params[:answer].downcase == @current_card.answer.downcase) assign_score(@answer_eval) + p "inside nil" redirect to("/users/stats/#{params[:deck_id]}") else @answer_eval = (params[:answer].downcase == @current_card.answer.downcase) assign_score(@answer_eval) - erb :show_card + erb :show_card, layout: false end end @@ -33,6 +34,6 @@ session.delete(:cards) redirect to("/users/stats/#{params[:deck_id]}") else - erb :show_card + erb :show_card, layout: false end end diff --git a/app/controllers/user.rb b/app/controllers/user.rb index c85b52d..d202e28 100644 --- a/app/controllers/user.rb +++ b/app/controllers/user.rb @@ -1,11 +1,15 @@ get '/users/new' do - erb :create_user + erb :create_user, layout: false end post '/users' do - new_user = User.create params - session[:id] = new_user.id - redirect '/decks' + @user = User.create params + if @user.valid? + session[:id] = @user.id + redirect '/decks' + else + erb :create_user, layout: false + end end @@ -14,17 +18,19 @@ end get '/users/stats/:deck_id' do - p params @user = User.find(session[:id]) @deck = Deck.find(params[:deck_id].to_i) - erb :show_stats + erb :show_stats, layout: false end post '/login' do - if auth_user(params) + auth_user(params) + p params + if loggedin? redirect '/decks' else - redirect to '/' + @failed_loggin = true + erb :index, layout: false end end diff --git a/app/helpers/user.rb b/app/helpers/user.rb index 194e143..e80d65f 100644 --- a/app/helpers/user.rb +++ b/app/helpers/user.rb @@ -1,15 +1,13 @@ helpers do def loggedin? - !!session["id"] + !!session[:id] end def auth_user(params) - @user = User.find_by_username(params[:username]) - if @user && @user.password == params[:password] - session[:id] = @user.id - true - else - false + user = User.find_by_username(params[:username]) + if user && user.password == params[:password] + session[:id] = user.id + user end end end \ No newline at end of file diff --git a/app/views/_error.erb b/app/views/_error.erb new file mode 100644 index 0000000..0b42566 --- /dev/null +++ b/app/views/_error.erb @@ -0,0 +1,5 @@ +<% if user && user.errors.messages[param] %> + <% user.errors.messages[param].each do |error| %> +
<%= error %>
+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/_invalid_login.erb b/app/views/_invalid_login.erb new file mode 100644 index 0000000..e13f13f --- /dev/null +++ b/app/views/_invalid_login.erb @@ -0,0 +1,5 @@ +<% if user %> + <% user.errors.messages[param].each do |error| %> +<%= error %>
+ <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/create_user.erb b/app/views/create_user.erb index 5fe1a7e..151ec91 100644 --- a/app/views/create_user.erb +++ b/app/views/create_user.erb @@ -3,10 +3,9 @@ - - - + \ No newline at end of file diff --git a/app/views/index.erb b/app/views/index.erb index e263568..5b6a5a0 100644 --- a/app/views/index.erb +++ b/app/views/index.erb @@ -1,7 +1,8 @@