MatrixChat.jl/src/users.jl

42 lines
1.2 KiB
Julia

using Nettle
function new_user(s::MatrixServer,
username::AbstractString, password::AbstractString;
admin::Bool = false)
path = "admin/register"
res = get(s, path)
nonce = JSON.parse(String(res.body))["nonce"]
h = HMACState("sha1", s.secret)
update!(h, nonce)
update!(h, "\x00")
update!(h, username)
update!(h, "\x00")
update!(h, password)
update!(h, "\x00")
update!(h, admin ? "admin" : "notadmin")
mac = hexdigest!(h)
data = Dict("nonce" => nonce,
"username" => username,
"password" => password,
"mac" => mac,
"admin" => admin)
raw_response = post(s, path, data)
parsed = String(raw_response.body)
write("$(username).json", parsed)
parsed = JSON.json(parsed)
MatrixUser(s,
parsed["user_id"], parsed["access_token"],
parsed["device_id"])
end
function getdisplayname(server::MatrixServer, userid::String)
# Errors: 404 not found
res = get(server,
string("profile/", userid, "/displayname")
).body |> String |> JSON.parse
res["displayname"]
end