using authentication for app

This commit is contained in:
2012-10-25 16:11:49 +02:00
parent 5479d3760b
commit 28ec047f1d
14 changed files with 429 additions and 40 deletions
+67 -23
View File
@@ -35,32 +35,69 @@ var path_mapping = {
list_products_for_table: '/user/list_products_for_table',
list_products: '/user/list_products',
active_list: '/user/active_list',
history_list: '/user/history_list'
history_list: '/user/history_list',
obtain_user_token: '/user/obtain_token'
}
var translations = {
confirmations: {
move_to_another_table_title: 'Move to another table?',
move_to_another_table: 'Are you sure you want to move to another table?'
en: {
confirmations: {
},
list_needs_help: {
help_is_on_its_way: 'Help is already on its way',
title: 'Request a waiter',
content: 'Request a waiter to your table'
},
list_needs_payment: {
payment_already_requested: 'You already asked for the check',
title: 'Ask for the check',
content: 'Do you want to pay?'
},
selected_products: {
order: 'Order',
clear: 'Clear'
},
join_request: {
title: 'Join request',
body: '%{email} wants to join the table',
reject: 'Reject',
approve: 'Approve'
},
move_table: {
cannot_move_to_occupied_table: 'You cannot move to an occupied table',
moved_to_another_table: 'The table is changed.',
confirmation_title: 'Move to another table?',
confirmation_body: 'Are you sure you want to move to another table?'
}
},
list_needs_help: {
help_is_on_its_way: 'Help is already on its way',
title: 'Request a waiter',
content: 'Request a waiter to your table'
},
list_needs_payment: {
payment_already_requested: 'You already asked for the check',
title: 'Ask for the check',
content: 'Do you want to pay?'
},
selected_products: {
order: 'Order',
clear: 'Clear'
},
join_request: {
title: 'Join request',
body: '%{email} wants to join the table',
reject: 'Reject',
approve: 'Approve'
nl: {
confirmations: {
},
list_needs_help: {
help_is_on_its_way: 'Er wordt al iemand naar je tafel gestuurd',
title: 'Ik heb een vraag',
content: 'Wil je een vraag stellen?'
},
list_needs_payment: {
payment_already_requested: 'De rekening is reeds gevraagd',
title: 'Vraag om de rekening',
content: 'Wil je betalen?'
},
selected_products: {
order: 'Bestellen',
clear: 'Leegmaken'
},
join_request: {
title: 'Lijst deling',
body: '%{email} wil ook op jouw lijst bestellen',
reject: 'Afwijzen',
approve: 'Toestaan'
},
move_table: {
cannot_move_to_occupied_table: 'Je kan niet verhuizen naar een tafel die reeds gebruikt wordt.',
moved_to_another_table: 'De tafel is gewijzigd.',
confirmation_title: 'Naar een andere tafel verhuizen?',
confirmation_body: 'Ben je aan een andere tafel gaan zitten?'
}
}
}
function redirect_to(mapping, variables){
@@ -90,3 +127,10 @@ function t(path, vars){
$.each(vars, function(v, value){ result = result.replace('%{'+v+'}', value)});
return result;
}
$.ajaxSetup({
error: function(xhr, ajaxOptions, error){
if(xhr.status == 401 || xhr.status == 0){
window.location = data_host + '/user/obtain_token.html';
}
}
})
+5 -5
View File
@@ -304,19 +304,19 @@ window.Quser=
else if res.supplier_closed
redirect_to 'user_root', {message: 'supplier_is_closed'}
else
#TODO Offer to move table
## Offer to move table
Qwaiter.confirm(
ok: ->
$.post(data_host + '/user/move_table', $.extend({table_id: table.table_id}, authentication_object), (res2)->
if res2.occupied
alert('Cannot move to occupied table')
redirect_to 'user_root', {message: 'move_table.cannot_move_to_occupied_tabe'}
else
redirect_to 'list_products', {message: 'moved_to_another_table'}
redirect_to 'list_products', {message: 'move_table.moved_to_another_table'}
)
cancel: ->
redirect_to 'list_products'
title: t('confirmations.move_to_another_table_title')
content: t('confirmations.move_to_another_table')
title: t('move_table.confirmation_title')
content: t('move_table.confirmation_body')
)
else
if res.occupied
@@ -1,4 +1,5 @@
class ApplicationController < ActionController::Base
before_filter :set_locale
layout :layout_by_resource
@@ -6,6 +7,10 @@ class ApplicationController < ActionController::Base
private
def set_locale
I18n.locale = :nl
end
def layout_by_resource
if devise_controller?
"phone"
+10
View File
@@ -2,6 +2,15 @@ class UserController < ApplicationController
before_filter :allow_mobile, :authenticate_user!
layout 'phone'
def authenticate_user_wrapper!
authenticate_user! unless request.format.html?
authenticate_user! if params[:action] == 'obtain_token'
end
def obtain_token
end
alias :list :active_list
def allow_mobile
@@ -153,6 +162,7 @@ class UserController < ApplicationController
redirect_to(root_path, alert: t('messages.there_is_no_list_active')) and return unless list.present?
end
format.json do
render json: js_alert(t('messages.the_list_has_been_closed')) and return unless list.present?
render json: list.with_orders_and_join_requests_as_json.merge(supplier_name: list.supplier.name)
end
end
+4 -4
View File
@@ -11,10 +11,10 @@ html lang="en"
/[if lt IE 9]
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
= stylesheet_link_tag "application", :media => "all"
link href="images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144"
link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114"
link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72"
link href="images/apple-touch-icon.png" rel="apple-touch-icon-precomposed"
link href="/images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144"
link href="/images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114"
link href="/images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72"
link href="/images/apple-touch-icon.png" rel="apple-touch-icon-precomposed"
link href="/favicon.ico" rel="shortcut icon"
body
+7 -2
View File
@@ -18,6 +18,9 @@ html lang="en"
link href="/favicon.ico" rel="shortcut icon"
javascript:
var data_host = 'http://data.qwaiter.com';
//var data_host = 'http://localhost:3000';
//var data_host = 'http://192.168.1.240:3000';
var $locale = '#{I18n.locale}';
// Dummy holder when Qmobile object is not supplied by the mobile phone
var QMobile, Qwaiter, Quser;
QMobile || (QMobile = {
@@ -30,9 +33,11 @@ html lang="en"
this.authentication_string_storage = 'auth_token='+token;
this.authentication_object_storage = '{"auth_token": "'+token+'"}'
},
root_url: function(){return ''}
root_url: function(){return 'file:///Users/bterkuile/Documents/workspace/Qwaiter/assets'},
root_url: function(){return ''},
goHome: function(){ window.location = QMobile.root_url() + path_mapping['user_root'] + '.html'}
});
QMobile.setAuthToken('i5brDZ1HS1okoEq3pMyh');
//QMobile.setAuthToken('i5brDZ1HS1okoEq3pMyh');
body class=action_name
.navbar.navbar-fixed-top
+4 -4
View File
@@ -12,10 +12,10 @@ html lang="en"
= javascript_include_tag "http://html5shim.googlecode.com/svn/trunk/html5.js"
= stylesheet_link_tag "supplier/application", :media => "all"
= stylesheet_link_tag "supplier/application", :media => "all"
link href="images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144"
link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114"
link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72"
link href="images/apple-touch-icon.png" rel="apple-touch-icon-precomposed"
link href="/images/apple-touch-icon-144x144.png" rel="apple-touch-icon-precomposed" sizes="144x144"
link href="/images/apple-touch-icon-114x114.png" rel="apple-touch-icon-precomposed" sizes="114x114"
link href="/images/apple-touch-icon-72x72.png" rel="apple-touch-icon-precomposed" sizes="72x72"
link href="/images/apple-touch-icon.png" rel="apple-touch-icon-precomposed"
link href="/favicon.ico" rel="shortcut icon"
body
+4
View File
@@ -12,6 +12,10 @@ dl.dl-horizontal
tr
td colspan=2 = slider_image
tfoot
.form-actions
= link_to t("helpers.links.back"), suppliers_lists_path(date: @list.created_at.strftime('%Y-%m-%d')), class: 'btn'
'
= link_to t('helpers.links.edit'), [:edit, :suppliers, @list], class: 'btn btn-info'
- content_for :footer do
javascript:
jQuery(function(){
+4
View File
@@ -0,0 +1,4 @@
- content_for :footer do
javascript:
QMobile.setAuthToken('#{current_user.authentication_token}');
QMobile.goHome();
+1 -1
View File
@@ -6,4 +6,4 @@ test:
database: qrammer_test
production:
validation_framework: :active_model #optional
database: qrammer
database: qwaiter
+116
View File
@@ -0,0 +1,116 @@
# Sample localization file for English. Add more files in this directory for other locales.
# See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
nl:
helpers:
links:
are_you_sure: 'Weet je dit zeker?'
place_order: Bestellen
show_active_list: Toon %{list}
forms:
errors:
title: Er zijn een problemen opgetreden (%{count})
messages:
cannot_order_on_non_active_list: Je kan niet bestellen op een gesloten lijst
order_is_placed: Je bestelling is in goede orde aangekomen
the_list_has_been_closed: De %{list} is afgesloten
illegal_history_list_attempt: Je probeert een lijst op te vragen die niet van jou is
table_is_occupied: De tafel waar je aan wil gaan zitten is reeds bezet
table_is_reserved: De tafel waar je aan wil gaan zitten is gereserveerd
table_is_closed: De tafel waar je aan wil gaan zitten is niet beschikbaar voor bediening
supplier_is_closed: De eigenaar van deze tafel is momenteel gesloten
join_request_rejected: Je verzoek om te mogen bestellen op een bestaande lijst is afgewezen
table_is_from_other_supplier: Je kan geen lijst openen bij een andere zaak zolang je huidige %{list} nog niet is afgesloten
moved_to_another_table: De tafel is gewijzigd
cannot_identify_table: De applicatie kan niet bepalen om welke tafel het gaat
action:
index:
label: '%{models} overzicht'
new:
label: '%{model} toevoegen'
show:
label: Toon %{model}
edit:
label: Bewerk %{model}
create:
successfull: '%{model} is succesvol aangemaakt'
update:
successfull: '%{model} is succesvol aangepast'
destroy:
successfull: '%{model} is succesvol verwijderd'
table:
is_occupied: Deze tafel is bezet
has_no_section: "Niet geplaatst"
activemodel:
models:
user: Gebruiker
supplier: Restaurant
table: Tafel
list: Lijst
product: Product
order: Bestelling
product_category: Product categorie
section: Afdeling
plural:
user: Gebruikers
supplier: Restaurants
table: Tafels
list: Lijsten
product: Producten
order: Bestellingen
product_category: Product categorieen
section: Afdelingen
attributes:
product:
price: Prijs
list:
created_at: Aangemaakt
supplier:
menu:
active_lists: Actieve %{lists}
active_lists:
title: Actieve %{lists}
price: Prijs
active_orders:
title: Actieve %{orders}
price: Prijs
close: De zaak afsluiten voor bestellingen
you_are_currently_closed_alert: 'Je bent momenteel gesloten en kan geen orders ontvangen'
mark_as_open_button: 'Open de zaak!'
table_number: Tafel
tables:
qr_codes:
link: Qr codes
lists:
show:
title: "%{list} tonen"
user:
active_list:
title: Actieve %{list}
needs_payment: Rekening vragen!
history_list:
title: Afgesloten %{list}
show_products:
# The title gets products: Product.model_name.human_plural that can be used: e.g.: Showing %{products}
title: Menu
join_occupied_table:
title: Deze tafel is bezet
join_this_table: Ik wil ook bestellen bij deze tafel
show_the_products: Laat me het menu zien
back: Terug
home:
scan_qr: Scan qr code
show_active_list: Toon mijn bestellingen
show_active_list_products: Ga naar het menu
section:
first_section_title: Ruimte
manage_tables:
title: "Tafels beheren voor %{section}: %{title}"
general:
boolean:
boolean_yes: "Ja"
boolean_no: "Nee"
# FOLLOWING ARE BACKED BY DATA ATTRIBUTES
selected_products:
clear: Leegmaken
order: Bestellen
+199
View File
@@ -0,0 +1,199 @@
nl:
date:
abbr_day_names:
- zon
- maa
- din
- woe
- don
- vri
- zat
abbr_month_names:
-
- jan
- feb
- mar
- apr
- mei
- jun
- jul
- aug
- sep
- okt
- nov
- dec
day_names:
- zondag
- maandag
- dinsdag
- woensdag
- donderdag
- vrijdag
- zaterdag
formats:
default: ! '%d/%m/%Y'
long: ! '%e %B %Y'
short: ! '%e %b'
month_names:
-
- januari
- februari
- maart
- april
- mei
- juni
- juli
- augustus
- september
- oktober
- november
- december
order:
- :day
- :month
- :year
datetime:
distance_in_words:
about_x_hours:
one: ongeveer een uur
other: ongeveer %{count} uur
about_x_months:
one: ongeveer een maand
other: ongeveer %{count} maanden
about_x_years:
one: ongeveer een jaar
other: ongeveer %{count} jaar
almost_x_years:
one: bijna een jaar
other: bijna %{count} jaar
half_a_minute: een halve minuut
less_than_x_minutes:
one: minder dan een minuut
other: minder dan %{count} minuten
less_than_x_seconds:
one: minder dan een seconde
other: minder dan %{count} seconden
over_x_years:
one: meer dan een jaar
other: meer dan %{count} jaar
x_days:
one: 1 dag
other: ! '%{count} dagen'
x_minutes:
one: 1 minuut
other: ! '%{count} minuten'
x_months:
one: 1 maand
other: ! '%{count} maanden'
x_seconds:
one: 1 seconde
other: ! '%{count} seconden'
prompts:
day: dag
hour: uur
minute: minuut
month: maand
second: seconde
year: jaar
errors: &errors
format: ! '%{attribute} %{message}'
messages:
accepted: moet worden geaccepteerd
blank: moet opgegeven zijn
confirmation: komt niet met de bevestiging overeen
empty: moet opgegeven zijn
equal_to: moet gelijk zijn aan %{count}
even: moet even zijn
exclusion: is niet beschikbaar
greater_than: moet groter zijn dan %{count}
greater_than_or_equal_to: moet groter dan of gelijk zijn aan %{count}
inclusion: is niet in de lijst opgenomen
invalid: is ongeldig
less_than: moet minder zijn dan %{count}
less_than_or_equal_to: moet minder dan of gelijk zijn aan %{count}
not_a_number: is geen getal
not_an_integer: moet een geheel getal zijn
odd: moet oneven zijn
record_invalid: ! 'Validatie mislukt: %{errors}'
taken: is al in gebruik
too_long: is te lang (maximaal %{count} tekens)
too_short: is te kort (minimaal %{count} tekens)
wrong_length: heeft onjuiste lengte (moet %{count} tekens lang zijn)
template:
body: ! 'Controleer de volgende velden:'
header:
one: ! '%{model} niet opgeslagen: 1 fout gevonden'
other: ! '%{model} niet opgeslagen: %{count} fouten gevonden'
helpers:
select:
prompt: Selecteer
submit:
create: ! '%{model} toevoegen'
submit: ! '%{model} opslaan'
update: ! '%{model} bewaren'
number:
currency:
format:
delimiter: .
format: ! '%u%n'
precision: 2
separator: ! ','
significant: false
strip_insignificant_zeros: false
unit:
format:
delimiter: .
precision: 2
separator: ! ','
significant: false
strip_insignificant_zeros: false
human:
decimal_units:
format: ! '%n %u'
units:
billion: miljard
million: miljoen
quadrillion: biljard
thousand: duizend
trillion: biljoen
unit: ''
format:
delimiter: ''
precision: 3
significant: true
strip_insignificant_zeros: true
storage_units:
format: ! '%n %u'
units:
byte:
one: Byte
other: Bytes
gb: GB
kb: KB
mb: MB
tb: TB
percentage:
format:
delimiter: ''
precision:
format:
delimiter: ''
support:
array:
last_word_connector: ! ' en '
two_words_connector: ! ' en '
words_connector: ! ', '
time:
am: ! '''s ochtends'
formats:
default: ! '%a %d %b %Y %H:%M:%S %Z'
long: ! '%d %B %Y %H:%M'
short: ! '%d %b %H:%M'
pm: ! '''s middags'
# remove these aliases after 'activemodel' and 'activerecord' namespaces are removed from Rails repository
activemodel:
errors:
<<: *errors
activerecord:
errors:
<<: *errors
+2
View File
@@ -57,6 +57,8 @@ Qrammer::Application.routes.draw do
post '/user/reject_join_request' => 'user#reject_join_request'
post '/user/approve_join_request' => 'user#approve_join_request'
post '/user/check_table_join_status' => 'user#check_table_join_status'
get '/user/obtain_token' => 'user#obtain_token', as: :user_obtain_token
#match '/show_products' => 'dashboard#show_products', as: :user_products
+1 -1
View File
@@ -8,7 +8,7 @@ root_url = 'file:///android_asset'
mkdir_p File.join(android_root, 'user')
rm_rf File.join(android_root, 'assets')
Dir.glob(File.join('public', 'assets', '**', '*.gz')).each{|f| rm_f f}
move Rails.root.join('public', 'assets'), File.join(android_root, 'assets')
move Rails.root.join('public', 'assets'), File.join(android_root, 'assets') if File.directory?(Rails.root.join('public', 'assets'))
for css in Dir.glob(File.join(android_root, "**", "*.css"))
contents = File.read(css)
contents.gsub!(/url\("/, %|url("#{root_url}|)