blob: 65b7be11ccc946b7782e00f9de87d21fc877adc6 (
plain)
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
|
require 'sinatra'
require 'pp'
require 'json'
require '../lib/srp'
require 'models/user'
require 'models/log'
get '/' do
@user = User.current
erb :index
end
get '/signup' do
erb :signup
end
# TODO: Client should generate the salt!
# Getting things to work the srp-js way first.
# Also these are the urls srp-js is used to - it's easy
# to overwrite them though by writing your own srp-js wrapper
post '/register/salt/' do
Log.clear
@user = User.new(params.delete('I'))
content_type :json
{ :salt => @user.salt.to_s(16) }.to_json
end
post '/register/user/' do
User.current.verifier = params.delete('v').hex
content_type :json
{ :ok => true }.to_json
end
get '/login' do
@user = User.current
erb :login
end
post '/handshake/' do
@user = User.current
Log.log(:handshake, params)
@handshake = @user.handshake(params)
Log.log(:init_auth, @handshake)
content_type :json
@handshake.to_json
end
post '/authenticate/' do
@user = User.current
Log.log(:authenticate, params)
@auth = @user.validate(params)
Log.log(:confirm_authentication, @auth)
content_type :json
@auth.to_json
end
get '/verify' do
erb :verify
end
helpers do
def button_link(action, options = {})
action = action.to_s
label = action.capitalize
klass = "btn btn-large"
if options.delete(:primary)
klass += " btn-primary"
label += " now..."
end
%Q(<a href="#{action}" class="#{klass}" id="#{action}-view-btn">#{label}</a>)
end
end
|