Add freeswitch integration

This commit is contained in:
Sam Dodrill 2015-01-07 08:42:49 -08:00
parent 3abce75db4
commit 3908042abd
4 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,3 @@
FROM xena/lapis
RUN moonrocks install xml

View File

@ -37,12 +37,14 @@ class App extends lapis.Application
@params.password_again = nil
@params.csrf_token = nil
@params.extension = "9001"
@params.registrar_password = encoding.encode_base64 encoding.hmac_sha1(@params.email, os.time!)
if Users\find email: @params.email
return status: 500, "User with that email already exists"
user = Users\create @params
user\write_session @
@session.sippw = @params.registrar_password
"Hi " .. user.name
}
@ -70,3 +72,11 @@ class App extends lapis.Application
else
return status: 500, "bad password"
}
[freeswitch: "/freeswitch"]: respond_to {
POST: =>
uid = @params["user"] or @params["sip_auth_username"]
@user = Users\find id: uid
render: true, layout: false
}

View File

@ -23,4 +23,7 @@ import add_column, create_table, types from require "lapis.db.schema"
[5]: =>
add_column "users", "is_agent", types.boolean
[6]: =>
add_column "users", "registrar_password", types.text
}

18
views/freeswitch.moon Normal file
View File

@ -0,0 +1,18 @@
import Widget from require "lapis.html"
class Freeswitch extends Widget
content: =>
document type: "freeswitch/xml", ->
section name: "directory", ->
domain name: "$${domain}", ->
params ->
param name: "dial-string", value: "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"
groups ->
group name: "default", ->
users ->
user id: "#{@user.id}", ->
params ->
param name: "password", value: "#{@user.registrar_password}"
variables ->
variable name: "accountcode", value: "#{@user.id}"
variable name: "user_context", value: "default"