Skip to content

Commit

Permalink
Registration fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SebassCoates committed May 31, 2019
1 parent 248d9eb commit db8648a
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
57 changes: 57 additions & 0 deletions nodejs/immuto.js
Expand Up @@ -110,6 +110,63 @@ exports.init = (debug, debugHost) => {
})
}


this.get_registration_token = function(address) {
return new Promise((resolve, reject) => {
var http = new XMLHttpRequest()

let sendstring = "address=" + address

http.open("POST", this.host + "/get-signature-data", true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

http.onreadystatechange = () => {
if (http.readyState == 4 && http.status == 200) {
resolve(http.responseText)
} else if (http.readyState == 4) {
reject(http.responseText)
}
}
http.send(sendstring)
})
}

this.register_user = function(email, password, orgToken) {
return new Promise((resolve, reject) => {
let salt = this.web3.utils.randomHex(32)
let account = this.web3.eth.accounts.create()
let address = account.address
let encryptedKey = this.web3.eth.accounts.encrypt(account.privateKey, password + salt);

this.get_registration_token(address).then((token) => {
let signature = account.sign(token)
var http = new XMLHttpRequest()

let sendstring = "email=" + email
sendstring += "&password=" + this.web3.utils.sha3(password)
sendstring += "&salt=" + salt
sendstring += "&address=" + address
sendstring += "&keyInfo=" + JSON.stringify(encryptedKey)
sendstring += "&signature=" + JSON.stringify(signature)

if (orgToken)
sendstring += "&registrationCode=" + orgToken

http.open("POST", this.host + "/submit-registration", true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

http.onreadystatechange = () => {
if (http.readyState == 4 && http.status == 204) {
resolve()
} else if (http.readyState == 4) {
reject(http.responseText)
}
}
http.send(sendstring)
})
})
}

this.authenticate = function(email, password) {
return new Promise((resolve, reject) => {
if (!email) {
Expand Down
58 changes: 57 additions & 1 deletion testing/browser/immuto.js
Expand Up @@ -94,7 +94,7 @@ exports.init = (debug, debugHost) => {

let signature = sigUtil.concatSig(v, r, s)
return sigUtil.recoverPersonalSignature({data: message, sig: signature})
}
},
}

this.establish_connection = function(email) {
Expand Down Expand Up @@ -141,6 +141,62 @@ exports.init = (debug, debugHost) => {
})
}

this.get_registration_token = function(address) {
return new Promise((resolve, reject) => {
var http = new XMLHttpRequest()

let sendstring = "address=" + address

http.open("POST", this.host + "/get-signature-data", true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

http.onreadystatechange = () => {
if (http.readyState == 4 && http.status == 200) {
resolve(http.responseText)
} else if (http.readyState == 4) {
reject(http.responseText)
}
}
http.send(sendstring)
})
}

this.register_user = function(email, password, orgToken) {
return new Promise((resolve, reject) => {
let salt = this.web3.utils.randomHex(32)
let account = this.web3.eth.accounts.create()
let address = account.address
let encryptedKey = this.web3.eth.accounts.encrypt(account.privateKey, password + salt);

this.get_registration_token(address).then((token) => {
let signature = account.sign(token)
var http = new XMLHttpRequest()

let sendstring = "email=" + email
sendstring += "&password=" + this.web3.utils.sha3(password)
sendstring += "&salt=" + salt
sendstring += "&address=" + address
sendstring += "&keyInfo=" + JSON.stringify(encryptedKey)
sendstring += "&signature=" + JSON.stringify(signature)

if (orgToken)
sendstring += "&registrationCode=" + orgToken

http.open("POST", this.host + "/submit-registration", true)
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded")

http.onreadystatechange = () => {
if (http.readyState == 4 && http.status == 204) {
resolve()
} else if (http.readyState == 4) {
reject(http.responseText)
}
}
http.send(sendstring)
})
})
}

this.authenticate = function(email, password) {
return new Promise((resolve, reject) => {
if (this.salt && this.encryptedKey && this.authToken && this.email) {
Expand Down

0 comments on commit db8648a

Please sign in to comment.