relita

an encrypted, decentralized, peer-to-peer social network
Log | Files | Refs | README | LICENSE | git clone https://git.ne02ptzero.me/git/relita

commit ba9cf9a67caebdc16f353dc9b00ffcdb471f14a3
parent c5987a6b3bee1ca0703a274708067aff4dbc7415
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Sun,  9 Apr 2017 22:52:44 +0200

Add(Register): Add a new way to register and join a Pub

Diffstat:
Mcss/main.css | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ajs/register.js | 27+++++++++++++++++++++++++++
Mjs/renderer.js | 4++--
Mmain.js | 44+++++++++++++++++++++++++++++++++++++++++---
Aregister.html | 41+++++++++++++++++++++++++++++++++++++++++
5 files changed, 187 insertions(+), 5 deletions(-)

diff --git a/css/main.css b/css/main.css @@ -53,3 +53,79 @@ html, body { .add_post { display: none; } + +.register { + height: 90%; + width: 100%; + display: flex; + align-items: center; + justify-content: center; +} + +.register h1 { + font-weight: lighter; + margin-bottom: 30px; +} + +.register ul { + list-style: none; + text-align: center; + margin-top: 20px; +} + +.input { + list-style: none; + display: inline-block; + padding: 0; + margin: 0; + margin-top: 2px; +} + +.input li { + display: block; + float: left; + padding: 0; + margin: 0; +} + +.input .title { + width: 100px; + height: 15px; + text-align: center; + background: #404040; + padding-top: 5px; + padding-bottom: 5px; +} + +.input .box { + height: 25px; + width: 250px; +} + +.input .box input { + width: 100%; + height: 100%; + border: 0; +} + +.input .box .file_button { + width: 245px; + height: 20px; + background: #FFFFFF; + display: inline-block; + color: #404040; + text-align: left; + padding-left: 5px; + padding-top: 5px; + overflow: hidden; +} + +.button_input { + margin-top: 30px; + width: 150px; + height: 30px; + text-align: center; + border: 0; + font-family: "Inconsolata"; + background: #8C8979; +} diff --git a/js/register.js b/js/register.js @@ -0,0 +1,27 @@ +$(function() { + const {ipcRenderer} = require('electron') + const {dialog} = require('electron').remote + + ipcRenderer.send('connect_client', null); + + ipcRenderer.on('register_client', (event, arg) => { + $(".register").fadeOut(200) + }) + + $(".button_input").on("click", function() { + username = $(".input [name='name']").val() + pic = $(".input .file_button").html() + invite = $(".input [name='invite']").val() + ipcRenderer.send('register_client', {username: username, pic: pic, invite: invite}) + }) + + $(".file_button").on("click", function() { + file_p = dialog.showOpenDialog({ + properties: ['openFile'], + filters: [ + {name: 'Images', extensions: ['jpg', 'png', 'gif']}, + ] + }) + $(this).html(file_p) + }) +}) diff --git a/js/renderer.js b/js/renderer.js @@ -11,7 +11,7 @@ $(function() { }) ipcRenderer.on('add_post', (event, arg) => { - ipcRenderer.send('get_feed', null); + //ipcRenderer.send('get_feed', null); }) ipcRenderer.on('get_feed', (event, arg) => { @@ -23,7 +23,7 @@ $(function() { }) ipcRenderer.on('new_entry', (event, arg) => { - if (arg.sync === true) + if (arg.sync === true || arg.value.content.type != "post") return ; $(".posts_list").append("<strong>"+ arg.value.author + "</strong>: "+ arg.value.content.value + "<br />") }) diff --git a/main.js b/main.js @@ -26,14 +26,19 @@ const default_port = 6666; const default_name = "Relita" let mainWindow -let sbot_client +let sbot_client = null let user_id +let first_connection = false function launch_sbot_server() { config.keys = keys manifestFile = path.join(config.path, 'manifest.json') config.port = default_port; + if (fs.existsSync(manifestFile) == false) { + first_connection = true + } + var server = sbot(config) // write RPC manifest to ~/.ssb/manifest.json fs.writeFileSync(manifestFile, JSON.stringify(server.getManifest(), null, 2)) @@ -50,7 +55,7 @@ function create_window() { title: default_name }) mainWindow.loadURL(url.format({ - pathname: path.join(__dirname, 'index.html'), + pathname: path.join(__dirname, first_connection ? 'register.html' : 'index.html'), protocol: 'file:', slashes: true })) @@ -61,6 +66,7 @@ function create_window() { } function live_drain(msg) { + console.log(msg) mainWindow.webContents.send('new_entry', msg) } @@ -80,6 +86,11 @@ app.on('activate', function () { ipcMain.on('connect_client', (event, arg) => { console.log("Attempting to connect client...") + if (sbot_client !== null) + { + event.sender.send('connect_client', 'OK') + return; + } ssb_client({port: default_port}, function(err, sbot) { if (err) event.sender.send('connect_client', 'KO') @@ -106,7 +117,6 @@ ipcMain.on('get_feed', (event, arg) => { pull.collect(function (err, msgs) { if (err) throw err; - console.log(msgs) event.sender.send('get_feed', msgs); }) ) @@ -126,3 +136,31 @@ ipcMain.on('add_post', (event, arg) => { } ) }) + +ipcMain.on('register_client', (event, arg) => { + console.log("Adding pub: "+ arg.invite) + sbot_client.invite.accept(arg.invite, function(err) { + if (err) + { + event.sender.send('register_client', 'KO') + return ; + } + + }) + sbot_client.publish({ + type: 'about', + about: user_id, + name: arg.username + }, function(err, msg) { + if (err) { + event.sender.send('register_client', 'KO') + return ; + } else { + mainWindow.loadURL(url.format({ + pathname: path.join(__dirname, 'index.html'), + protocol: 'file:', + slashes: true + })) + } + }) +}) diff --git a/register.html b/register.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> + <link rel="stylesheet" href="./css/main.css"> + <link rel="stylesheet" href="./css/font-awesome/css/font-awesome.min.css"> + </head> + <body> + <div class='register'> + <ul> + <li><h1>Hey there !</h1></li> + <li><span>Seems like you're new ! Let's get some basic informations about you.</span></li> + <li> + <ul class='input'> + <li class='title'>Username</li> + <li class='box'><input type="text" name="name" required /></li> + </ul> + </li> + <li> + <ul class='input'> + <li class='title'>Picture</li> + <li class='box'><div class="file_button">Upload a Picture ...</div> + </ul> + </li> + <li> + <ul class='input'> + <li class='title'>Invitation</li> + <li class='box'><input type="text" name="invite" required /></li> + </ul> + </li> + + <li><input type="submit" class='button_input' value="Submit" /></li> + </ul> + </div> + </body> + +<script>window.$ = window.jQuery = require('./js/jquery.min.js');</script> +<script> +require('./js/register.js') +</script> +</html>