webui: createlogin with new pgpid

This commit is contained in:
zeners 2016-01-24 19:32:15 +01:00
parent e944ab6045
commit 2fc35cf707

View File

@ -3,6 +3,8 @@ var rs = require("retroshare");
var locationName = ""; var locationName = "";
var password =""; var password ="";
var ssl_name = "";
var newName = "";
function listprofiles(){ function listprofiles(){
var locations = rs("control/locations"); var locations = rs("control/locations");
@ -39,8 +41,47 @@ function setPasswd(passwd) {
password = passwd; password = passwd;
} }
function setSslName(ssl) {
ssl_name = ssl;
}
function createLocation(loc) { function setNewName(name) {
newName = name;
}
function checkpasswd(){
var status = "";
var color = "red";
var lbl = document.getElementById("lblpwdinfo");
var passwd2 = document.getElementById("txtpasswd2").value;
if (passwd2 == password && passwd2 != "") {
color = "lime";
status = "password ok";
} else if (passwd2 == "") {
color = "yellow";
status = "password required";
} else {
color = "red";
status = "passwords don't match";
}
lbl.textContent = status;
lbl.style.color=color;
}
function createLocation() {
var profile = m.route.param("id");
var profname = m.route.param("name");
var loc ={
ssl_name: document.getElementById("txtlocation").value,
pgp_password: password,
};
if (profile != undefined) {
loc.pgp_id= profile;
} else {
loc.pgp_name = newName;
};
rs.request("control/create_location",loc,function(data){ rs.request("control/create_location",loc,function(data){
m.route("/accountselect", {}); m.route("/accountselect", {});
}); });
@ -56,55 +97,127 @@ module.exports = {
var hidden = m.route.param("hidden"); var hidden = m.route.param("hidden");
if (state == "wait"){ if (state == "wait"){
return m("div","waiting ..."); return m("div","waiting ...");
} else if (profile === undefined) { } if (state == "newid"){
m.initControl = "txtnewname";
return m("div",[
m("h2","create login - Step 2 / 2: create location"),
m("h3","- for new profile "),
m("hr"),
m("h2","PGP-profile name:"),
m("input",{
id: "txtnewname",
type:"text",
onchange:m.withAttr("value", setNewName),
onkeydown: function(event){
if (event.keyCode == 13){
document.getElementById("txtpasswd").focus();
}
},
}),
m("h2","enter password:"),
m("input", {
id: "txtpasswd",
type:"password",
onchange: m.withAttr("value",setPasswd),
onkeydown: function(event){
if (event.keyCode == 13){
setPasswd(this.value);
document.getElementById("txtpasswd2").focus();
};
checkpasswd;
}
}),
m("h2", "re-enter password:"),
m("input", {
id: "txtpasswd2",
type:"password",
onfocus: checkpasswd,
onchange: checkpasswd,
onkeyup: function(event){
if (event.keyCode == 13){
document.getElementById("txtlocation").focus();
}
checkpasswd();
}
}),
m("h3",{
id: "lblpwdinfo",
style:"color:yellow",
}, "password required"),
m("h2","location name:"),
m("input",{
id: "txtlocation",
type:"text",
onchange:m.withAttr("value", setLocationName),
onkeydown: function(event){
if (event.keyCode == 13){
setSslName(this.value);
createLocation();
}
},
}),
m("br"),
m("input",{
type: "button",
onclick: function(){
createLocation();
},
value: "create location",
}),
]);
} else if (profile != undefined) {
m.initControl = "txtpasswd";
return m("div",[
m("h2","create login - Step 2 / 2: create location"),
m("h3","- for " + profname + " (" +profile + ")"),
m("hr"),
m("h2","enter password:"),
m("input", {
id: "txtpasswd",
type:"password",
onchange: m.withAttr("value",setPasswd),
onkeydown: function(event){
if (event.keyCode == 13){
setPasswd(this.value);
document.getElementById("txtlocation").focus();
}
}
}),
m("h2","location name:"),
m("input",{
id: "txtlocation",
type:"text",
onchange:m.withAttr("value", setLocationName),
onkeydown: function(event){
if (event.keyCode == 13){
setSslName(this.value);
createLocation();
}
},
}),
m("br"),
m("input",{
type: "button",
onclick: function(){
createLocation();
},
value: "create location",
}),
]);
} else {
return m("div",[ return m("div",[
m("h2","create login - Step 1 / 2: select profile(PGP-ID)"), m("h2","create login - Step 1 / 2: select profile(PGP-ID)"),
m("hr"), m("hr"),
m("div.btn2",{} ,"<create new profile>"), m("div.btn2",{
m("div.btn2",{} ,"<import profile (drag and drop a profile here)>"), onclick: function(){
m.route("/createlogin", {state: "newid"});
},
} ,"<create new profile>"),
m("div.btn2",{
} ,"<import profile (drag and drop a profile here)>"),
listprofiles() listprofiles()
]); ]);
}; };
m.initControl = "txtpasswd";
return m("div",[
m("h2","create login - Step 2 / 2: create location"),
m("h3","- for " + profname + " (" +profile + ")"),
m("hr"),
m("h2","enter password:"),
m("input", {
id: "txtpasswd",
type:"password",
onchange: m.withAttr("value",setPasswd),
onkeydown: function(event){
if (event.keyCode == 13){
setPasswd(this.value);
document.getElementById("txtlocation").focus();
}
}
}),
m("h2","location name:"),
m("input",{
id: "txtlocation",
type:"text",
onchange:m.withAttr("value", setLocationName),
onkeydown: function(event){
if (event.keyCode == 13){
createLocation({
ssl_name: this.value,
pgp_id: profile,
pgp_password: password,
});
}
},
}),
m("br"),
m("input",{
type: "button",
onclick: function(){
createLocation(locationName);
},
value: "create location",
}),
]);
} }
} }