-
Notifications
You must be signed in to change notification settings - Fork 24
/
controller.rb
75 lines (64 loc) · 1.75 KB
/
controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'rho'
require 'rho/rhocontroller'
require 'rho/rhoerror'
require 'helpers/browser_helper'
class SettingsController < Rho::RhoController
include BrowserHelper
def index
@msg = @params['msg']
render
end
def login
@msg = @params['msg']
render :action => :login, :back => '/app'
end
def login_callback
errCode = @params['error_code'].to_i
if errCode == 0
# run sync if we were successful
WebView.navigate Rho::RhoConfig.options_path
SyncEngine.dosync
else
if errCode == Rho::RhoError::ERR_CUSTOMSYNCSERVER
@msg = @params['error_message']
end
if !@msg || @msg.length == 0
@msg = Rho::RhoError.new(errCode).message
end
WebView.navigate ( url_for :action => :login, :query => {:msg => @msg} )
end
end
def do_login
if @params['login'] and @params['password']
begin
SyncEngine.login(@params['login'], @params['password'], (url_for :action => :login_callback) )
render :action => :wait
rescue Rho::RhoError => e
@msg = e.message
render :action => :login
end
else
@msg = Rho::RhoError.err_message(Rho::RhoError::ERR_UNATHORIZED) unless @msg && @msg.length > 0
render :action => :login
end
end
def logout
SyncEngine.logout
@msg = "You have been logged out."
render :action => :login
end
def reset
render :action => :reset
end
def do_reset
Rhom::Rhom.database_full_reset
SyncEngine.dosync
@msg = "Database has been reset."
redirect :action => :index, :query => {:msg => @msg}
end
def do_sync
SyncEngine.dosync
@msg = "Sync has been triggered."
redirect :action => :index, :query => {:msg => @msg}
end
end