email reg
This commit is contained in:
parent
11bfeb2d41
commit
1f82c948ac
2 changed files with 50 additions and 11 deletions
|
@ -312,21 +312,46 @@
|
|||
let emails = []
|
||||
let bod
|
||||
let html = false
|
||||
function reg() {
|
||||
console.log(document.getElementById('email').value)
|
||||
sendenc('/reg', { 'address': document.getElementById('email').value, 'host': document.getElementById('host').value, 'port': document.getElementById('port').value, 'creds': document.getElementById('auth').value }).then(() => {
|
||||
update()
|
||||
})
|
||||
}
|
||||
function update() {
|
||||
//console.log('hi')
|
||||
let promie = new Promise((resolve, reject) => {
|
||||
sendenc('/get/update', { 'user': 'root', 'requested': 0, 'login_key': getCookie('login_key') }).then(res => {
|
||||
res = JSON.parse(res)
|
||||
console.log('parsed')
|
||||
emails = res.messages.reverse()
|
||||
//console.log(res)
|
||||
console.log(res)
|
||||
bod = res.bod
|
||||
if (res.bod == 'body[2]') {
|
||||
html = true
|
||||
if (res.messages == 'reg') {
|
||||
document.body.style.backgroundColor = '#444444'
|
||||
document.body.innerHTML = `
|
||||
<h1>welcome! please add an email:)</h1>
|
||||
|
||||
email: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'id="email"></input>
|
||||
</br>
|
||||
auth/password: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'type="password" id="auth"></input>
|
||||
</br>
|
||||
host: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'id="host"></input>
|
||||
</br>
|
||||
port: <input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;'value='993' id="port"></input>
|
||||
</br>
|
||||
<input style='background-color:rgba(200,200,200,.3);border-color:rgba(80,80,80,.1);border:line;border-radius:4px;padding:5px;' type='button' value='submit' onclick='reg()'>
|
||||
`;
|
||||
} else {
|
||||
|
||||
|
||||
emails = res.messages.reverse()
|
||||
//console.log(res)
|
||||
console.log(res)
|
||||
bod = res.bod
|
||||
if (res.bod == 'body[2]') {
|
||||
html = true
|
||||
}
|
||||
umail()
|
||||
resolve(res)
|
||||
}
|
||||
umail()
|
||||
resolve(res)
|
||||
})
|
||||
})
|
||||
return promie
|
||||
|
@ -436,7 +461,7 @@
|
|||
if (getCookie('login_key') == null) {
|
||||
window.location.href = '/'
|
||||
}
|
||||
await init()
|
||||
await update()
|
||||
//return
|
||||
//document.getElementsByClassName('loading')[0].style.display = 'none'
|
||||
let xx = document.getElementsByClassName('card')[0]
|
||||
|
|
16
index.ts
16
index.ts
|
@ -123,6 +123,13 @@ app.post('/mail/get/update',async(req:any,res:any)=>{
|
|||
mail =JSON.parse(decrypt(user.mail,logkey)).emails[parseInt(dec.data.requested)]
|
||||
}
|
||||
}
|
||||
if(mail==''){
|
||||
const skey = new NodeRSA()
|
||||
let mail;
|
||||
skey.importKey(keyring[req.body.sid].theirpub,'pkcs8-public')
|
||||
res.send(JSON.stringify({data:skey.encrypt(JSON.stringify({messages:'reg'}),'base64'),enc:true,html:true}))
|
||||
return
|
||||
}
|
||||
var client = new ImapClient(mail.host, parseInt(mail.port), {
|
||||
auth: {
|
||||
user: mail.address,
|
||||
|
@ -181,7 +188,7 @@ app.post('/mail/del',async(req:any,res:any)=>{
|
|||
key.importKey(keyring[req.body.sid].mypriv,'pkcs1-private')
|
||||
let dec:any = JSON.parse((atob(key.decrypt(req.body.data,'base64','base64'))))
|
||||
const users:any = await User.findAll();
|
||||
let logkey:any,mail:any
|
||||
let logkey:any,mail:any;
|
||||
for(let user of users){
|
||||
//console.log(user,dec)
|
||||
if(user.name==dec.data.user){
|
||||
|
@ -254,6 +261,13 @@ app.post('/mail/get/storage',async(req:any,res:any)=>{
|
|||
mail =JSON.parse(decrypt(user.mail,logkey))
|
||||
}
|
||||
}
|
||||
if(mail==''){
|
||||
const skey = new NodeRSA()
|
||||
let mail;
|
||||
skey.importKey(keyring[req.body.sid].theirpub,'pkcs8-public')
|
||||
res.send(JSON.stringify({data:skey.encrypt(JSON.stringify({messages:'reg'}),'base64'),enc:true,html:true}))
|
||||
return
|
||||
}
|
||||
let d = skey.encrypt((mail.emails[parseInt(dec.data.requested)].storage),'base64')
|
||||
res.send(JSON.stringify({data:d,enc:true,html:true}))
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue