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 @@
+ <%= erb :'_error', locals: {user: @user, param: :username}%>

Username:


+ <%= erb :'_error', locals: {user: @user, param: :password}%>

Password:


-
- - - + \ 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 @@

Welcome to Dophin Flashcards!

-

Username:


+

<%= "Invalid Username or password" if @failed_loggin %>

+

Username:


Password:


diff --git a/app/views/layout.erb b/app/views/layout.erb index d95ae46..8bb2fc5 100644 --- a/app/views/layout.erb +++ b/app/views/layout.erb @@ -15,5 +15,9 @@
<%= yield %>
+ +
+ +
diff --git a/app/views/show_card.erb b/app/views/show_card.erb index eeeaa02..ac95a43 100644 --- a/app/views/show_card.erb +++ b/app/views/show_card.erb @@ -5,7 +5,7 @@
-

Question: <%= @card.question %> +

Question: <%= @card.question %>

diff --git a/app/views/show_decks.erb b/app/views/show_decks.erb index e4903b1..139383d 100644 --- a/app/views/show_decks.erb +++ b/app/views/show_decks.erb @@ -1,5 +1,5 @@ diff --git a/db/seeds.rb b/db/seeds.rb index de07372..96aaab8 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -11,21 +11,21 @@ end -CARDS = [{question: "واحد", answer: "one", deck_id: 1}, - {question: "اثنين", answer: "two", deck_id: 1}, - {question: "ثلاثة", answer: "three", deck_id: 1}, - {question: "كيفك", answer: "how are you?", deck_id: 1}, - {question: "صباح الخير", answer: "good morning", deck_id: 1}, - {question: "مرحبا", answer: "hello", deck_id: 1}, - {question: "d'accord", answer: "OK", deck_id: 1}, +CARDS = [{question: "one", answer: "one", deck_id: 1}, + # {question: "اثنين", answer: "two", deck_id: 1}, + # {question: "ثلاثة", answer: "three", deck_id: 1}, + # {question: "كيفك", answer: "how are you?", deck_id: 1}, + # {question: "صباح الخير", answer: "good morning", deck_id: 1}, + # {question: "مرحبا", answer: "hello", deck_id: 1}, + {question: "d'accord", answer: "OK", deck_id: 2}, {question: "qui", answer: "who", deck_id: 2}, {question: "quand", answer: "when", deck_id: 2}, - {question: "où", answer: "where", deck_id: 2}, + {question: "ou", answer: "where", deck_id: 2}, {question: "pourquoi", answer: "why", deck_id: 2}, {question: "comment", answer: "how", deck_id: 2}, {question: "Parlez-vous anglais?", answer: "Do you speak English?", deck_id: 2}, {question: "et", answer: "and", deck_id: 2}, - {question: "s'il vous plaît", answer: "please", deck_id: 2}, + {question: "s'il vous plait", answer: "please", deck_id: 2}, {question: "merci ", answer: "thank you", deck_id: 2}, {question:"What is the Caesium Chloride crystal structure? (abbreviation)", answer:"BCC", deck_id: 3}, {question:"What is the Sodium Chloride (rock salt) crystal structure?", answer:"Cubic", deck_id: 3}, diff --git a/public/css/application.css b/public/css/application.css index 23b4c11..a211d74 100644 --- a/public/css/application.css +++ b/public/css/application.css @@ -122,7 +122,8 @@ form { ul { list-style: none; - margin: 30px 10px auto; + margin: 5% auto; + } @@ -140,7 +141,7 @@ ul li { } ul li a { - color: yellow; + color: black; text-decoration: none; } @@ -152,8 +153,6 @@ ul li a:visited { margin: 0 auto; text-align: center; width: 80%; -/* position: absolute; - left: 150px;*/ } .card h2 { @@ -213,3 +212,26 @@ ul li a:visited { width: 500px; z-index: 1; } + +.error-msg{ + border-radius: 5px; + width:40%; + text-align: center; + background-color: rgb(250, 149, 149); +} + +.Gir_cage { + margin: auto; + + height: 20%; + position: relative; + top: 60%; + width: 40%; +} + +.GIR { + border: 10px solid #D9CDCD; + display: block; + margin: auto; + +} \ No newline at end of file diff --git a/public/js/application.js b/public/js/application.js index 52e01e6..19687d7 100644 --- a/public/js/application.js +++ b/public/js/application.js @@ -4,4 +4,49 @@ $(document).ready(function() { // when we try to bind to them // See: http://docs.jquery.com/Tutorials:Introducing_$(document).ready() + Dophin.addGuessListener() + Dophin.addDeckListener() + + }); + + +var Dophin = { + + addGuessListener: function(){ + $(document).on("submit","form",function(event){ + event.preventDefault(); + Dophin.cardGuess(this); + }); + }, + + addDeckListener: function(){ + $(".choose-deck").on("click",function(event){ + event.preventDefault(); + console.log(this) + Dophin.deckChoice(this); + }) + }, + + deckChoice: function(){ + $.ajax({ + type: "GET", + url: this.deckChoice.arguments[0].attributes.href.nodeValue, + success: function(response){ + $('.container').html(response) + } + }) + }, + + cardGuess: function(){ + // debugger + $.ajax({ + type: "POST", + url: this.cardGuess.arguments[0].attributes.action.nodeValue, + data: $('form').serialize(), + success: function(response){ + $('.container').html(response) + } + }) + } +} \ No newline at end of file diff --git a/spec/deck_controller_spec.rb b/spec/deck_controller_spec.rb index ad5e343..21fdb13 100644 --- a/spec/deck_controller_spec.rb +++ b/spec/deck_controller_spec.rb @@ -2,12 +2,12 @@ describe "Deck controller" do + let(:first_deck){FactoryGirl.create(:deck)} + let(:first_user){FactoryGirl.create(:user)} before(:all) do FactoryGirl.create(:card) first_user.decks << first_deck end - let(:first_deck){FactoryGirl.create(:deck)} - let(:first_user){FactoryGirl.create(:user)} describe "answering a question correctly" do before(:each) do