summaryrefslogtreecommitdiff
path: root/example/http-srp.rb
blob: e83036fd281a3d3ac2f43549306d36d6d9a0da94 (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
require 'sinatra'
require 'pp'

require 'models/user'
require 'models/log'
require '../lib/srp'

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.
post '/register/salt/' do
  Log.clear
  @user = User.new(params.delete('I'))
  erb :salt, :layout => false, :content_type => :xml
end

post '/register/user/' do
  User.current.verifier = params.delete('v').to_i
  erb :ok, :layout => false, :content_type => :xml
end

get '/login' do
  @user = User.current
  erb :login
end

post '/handshake/' do
  @user = User.current
  Log.log(:handshake, params)
  @auth = @user.initialize_auth(params)
  Log.log(:init_auth, @auth)
  erb :handshake, :layout => false, :content_type => :xml
end

post '/authenticate/' do
  @user = User.current
  Log.log(:authenticate, params)
  @auth = @user.authenticate(params)
  Log.log(:confirm_authentication, @auth)
  erb :authenticate, :layout => false, :content_type => :xml
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