recaptcha login support 284/head 286/head
authordhsfcuz <cigixohuga@topikt.com>
Fri, 29 Mar 2019 18:58:08 +0000 (19:58 +0100)
committerdhsfcuz <cigixohuga@topikt.com>
Fri, 29 Mar 2019 18:58:08 +0000 (19:58 +0100)
.gitignore
app/app.js
app/main.js
app/public/css/style.css
app/public/html/captcha.html [new file with mode: 0644]
app/public/index.html
app/public/js/captcha.js [new file with mode: 0644]
app/public/js/frontend.js

index a01f7b32c05618eec0c8663064bd664ea99eb97f..d3918462442c820cc933c48fb2473048d195238f 100644 (file)
@@ -64,3 +64,6 @@ dist
 app/authCredentials.js
 .DS_Store
 */.DS_Store
+
+# JetBrains
+.idea
index e527ca76bf16c7deaa6e62629f1fdc8cc695088d..32ddf4ad5fc9f74e95b933ef7a88629f3544e813 100644 (file)
@@ -123,11 +123,16 @@ io.sockets.on('connection', function (s) {
        s.emit("getDefaultSettings", defaultSettings, defaultDownloadFolder)
        s.emit("populateDownloadQueue", downloadQueue)
 
+       const captcha = require('./public/js/captcha');
+       captcha.callbackResponse = function (data) {
+               s.emit("getCaptcha", data)
+       };
+
        // Function for logging in
-       s.on("login", async function (username, password, autologin) {
+       s.on("login", async function (username, password, captchaResponse, autologin) {
                try{
                        logger.info("Logging in");
-                       await s.Deezer.login(username, password)
+                       await s.Deezer.login(username, password, captchaResponse)
                        s.emit("login", {user: s.Deezer.user})
                        logger.info("Logged in successfully")
                        if (autologin){
index 41d3b12de5bd284da2825ae4083e013ce25fa4b5..17b5ef465d9604dc9ed0350b09613be1901b22b6 100644 (file)
@@ -6,6 +6,9 @@ const {app, BrowserWindow, ipcMain, Menu, Tray, Notification} = require('electro
 const os = require('os');
 loadSettings();
 
+const captcha = require('./public/js/captcha');
+captcha.registerScheme();
+
 const theApp = require('./app');
 const WindowStateManager = require('electron-window-state-manager');
 const url = require('url');
@@ -108,7 +111,7 @@ function createWindow () {
                frame: false,
                icon: __dirname + "/icon.png",
                minWidth: 415,
-               minHeight: 32,
+               minHeight: 930,
                backgroundColor: "#23232c"
        });
 
@@ -160,6 +163,7 @@ app.on('ready', function(){
                createWindow();
                createTray();
        }
+       captcha.registerProtocol();
 });
 
 // Quit when all windows are closed.
index 08471e944ad0e2dccbc9755e1b778f4846ccfc86..6d9ad2f8fbe037d8e23db0686b22cd408afbb095 100644 (file)
@@ -396,3 +396,9 @@ a[href^="ftp://"] {
        cursor:pointer;
        text-decoration: underline;
 }
+
+#modal_login_iframe_captcha{
+       width: 100%;
+       height: 500px;
+       border: 0;
+}
diff --git a/app/public/html/captcha.html b/app/public/html/captcha.html
new file mode 100644 (file)
index 0000000..d84fee9
--- /dev/null
@@ -0,0 +1,22 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>captcha</title>
+</head>
+<body>
+    <form id="modal_captcha_form" action="/submit" method="get">
+        <div class="g-recaptcha" data-sitekey="6Lf4g34UAAAAAF2O2sScZKutelN7GM1FYVBmMom4" data-callback="onCaptchaSolved"></div>
+        <script type="text/javascript" src="https://www.google.com/recaptcha/api.js"></script>
+    </form>
+    <!-- the following src ends in cap://deezer.com/js/jquery-3.3.1.min.js -->
+    <!--<script type="text/javascript" src="./../js/jquery-3.3.1.min.js"></script>-->
+    <!-- therefore we use the http protocol, possible fix: https://github.com/electron/electron/issues/4506#issuecomment-299645031 -->
+    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
+    <script>
+        function onCaptchaSolved() {
+            $.get("/submit", $("#modal_captcha_form").serialize());
+        }
+    </script>
+</body>
+</html>
index 1b190fb7c9e4c2c973c538764ae38ddf109ad8af..ca1990184593743fb3bdd1e990132d6e5f539822 100644 (file)
        <div class="modal-content container" id="login-page">
                <div class="card">
                        <div class="card-content">
-                               <span class="card-title">Please paste here your userToken</span>
+                               <span class="card-title">Please login to your deezer account.</span>
                                <h6 class="red-text" id="login-res-text"></h6>
                                <div class="input-field col s12">
-                                       <input autocomplete="off" type="password" id="modal_login_input_userToken"/>
-                                       <label for="modal_login_input_userToken">userToken</label>
+                                       <input autocomplete="off" type="text" id="modal_login_input_username"/>
+                                       <label for="modal_login_input_username">Email</label>
                                </div>
-        <p><a href="https://notabug.org/RemixDevs/DeezloaderRemix/wiki/Login+via+userToken" target="_blank">How do I get my userToken?</a></p>
+                               <div class="input-field col s12">
+                                       <input autocomplete="off" type="password" id="modal_login_input_password"/>
+                                       <label for="modal_login_input_password">Password</label>
+                               </div>
+                               <input id="modal_login_input_captchaResponse" type="hidden" value=""/>
+                               <iframe id="modal_login_iframe_captcha" src="cap://deezer.com/"></iframe>
                        </div>
                        <div class="card-action row">
+                               <div class="col s12 m2 right center" id="modal_login_autologin">
+                                       <label>
+                                               <input type="checkbox" class="filled-in" id="modal_login_input_autologin"/>
+                                               <span>Remember me</span>
+                                       </label>
+                               </div>
                                <a href="#" class="deezloader-primary col s12 m2 waves-effect waves-light btn" id="modal_login_btn_login">Log in</a>
                                <a href="#" class="deezloader-secondary col s12 m2 waves-effect waves-light btn" id="modal_login_btn_signup">Sign up</a>
                        </div>
diff --git a/app/public/js/captcha.js b/app/public/js/captcha.js
new file mode 100644 (file)
index 0000000..3a82a76
--- /dev/null
@@ -0,0 +1,35 @@
+const {protocol} = require('electron');
+const url = require('url');
+const fs = require('fs');
+const path = require('path');
+
+
+let captchaPage = fs.readFileSync(path.join(__dirname, '..', 'html', 'captcha.html'), 'utf8');
+
+
+module.exports = {
+    callbackResponse: function (data) {
+        // registerProtocol must be called before callback can set
+        // so this is just a placeholder for the real callback function
+        console.log(data);
+    },
+    registerScheme: function () {
+        protocol.registerStandardSchemes(['cap']);
+    },
+    registerProtocol: function () {
+        protocol.registerBufferProtocol('cap', (request, callback) => {
+            let ReUrl = url.parse(request.url, true);
+            if(ReUrl.query["g-recaptcha-response"])
+            {
+                let response = ReUrl.query["g-recaptcha-response"];
+                this.callbackResponse(response);
+            }
+            callback({
+                mimeType: 'text/html',
+                data: Buffer.from(captchaPage)
+            })
+        }, (error) => {
+            if (error) console.error('Failed to register protocol')
+        })
+    }
+};
index c72498bc7f66ce1b62a1ec48831b5bcf3a7dac3e..677099c4e4639744c91db11d77da6e3aa0d455ad 100644 (file)
@@ -34,7 +34,6 @@ socket.on("getDefaultSettings", function(defaultSettings, defaultDownloadFolder)
 $('#modal_login_btn_login').click(function () {
        $('#modal_login_btn_login').attr("disabled", true)
        $('#modal_login_btn_login').html("Logging in...")
-       /*
        var username = $('#modal_login_input_username').val()
        var password = $('#modal_login_input_password').val()
        var autologin = $('#modal_login_input_autologin').prop("checked")
@@ -42,11 +41,15 @@ $('#modal_login_btn_login').click(function () {
                localStorage.setItem('autologin_email', username)
        }
        //Send to the software
-       socket.emit('login', username, password, autologin)
-       */
-       var userToken = $('#modal_login_input_userToken').val()
-       localStorage.setItem('userToken', userToken)
-       socket.emit('loginViaUserToken', userToken)
+       var captchaResponse = $('#modal_login_input_captchaResponse').val()
+       localStorage.setItem('captchaResponse', captchaResponse)
+    socket.emit('login', username, password, captchaResponse, autologin)
+})
+
+// Get captcha response
+socket.on('getCaptcha', function (data) {
+       $('#modal_login_input_captchaResponse').val(data)
+       console.log('captcha token received')
 })
 
 // New login system (uses cookies)
@@ -61,7 +64,7 @@ socket.on("login", function (data) {
                $("#modal_settings_picture").attr("src",data.user.picture)
                $("#side_user").text(data.user.name)
                $("#side_avatar").attr("src",data.user.picture)
-               $("#side_email").text("id:"+data.user.id)
+               $("#side_email").text(data.user.email)
                $('#initializing').addClass('animated fadeOut').on('webkitAnimationEnd', function () {
                        $(this).css('display', 'none')
                        $(this).removeClass('animated fadeOut')
@@ -100,12 +103,12 @@ socket.on('checkAutologin', function(){
        socket.emit("getUserSettings")
        if (localStorage.getItem('autologin')){
                socket.emit('autologin', localStorage.getItem('autologin'), localStorage.getItem('autologin_email'))
-               //$('#modal_login_input_autologin').prop('checked', true)
+               $('#modal_login_input_autologin').prop('checked', true)
                $('#modal_login_btn_login').attr("disabled", true)
                $('#modal_login_btn_login').html("Logging in...")
-               //$('#modal_login_input_username').val(localStorage.getItem('autologin_email'))
-               //$('#modal_login_input_password').val("password")
-               $('#modal_login_input_userToken').val(localStorage.getItem('userToken'))
+               $('#modal_login_input_username').val(localStorage.getItem('autologin_email'))
+               $('#modal_login_input_password').val("password")
+               $('#modal_login_input_captchaResponse').val(localStorage.getItem('captchaResponse'))
                M.updateTextFields()
        }
 })
@@ -354,17 +357,17 @@ $('#modal_login_btn_signup').click(function(){
 
 // Logout Button
 $('#modal_settings_btn_logout').click(function () {
-       //$('#modal_login_input_username').val("")
-       //$('#modal_login_input_password').val("")
-       //$('#modal_login_input_autologin').prop("checked",false)
-       $('#modal_login_input_userToken').val("")
+       $('#modal_login_input_username').val("")
+       $('#modal_login_input_password').val("")
+       $('#modal_login_input_autologin').prop("checked",false)
+       $('#modal_login_input_captchaResponse').val("")
        $('#initializing').css('display', '')
        $('#initializing').addClass('animated fadeIn').on('webkitAnimationEnd', function () {
                $(this).removeClass('animated fadeIn')
                $(this).css('display', '')
        })
        localStorage.removeItem("autologin")
-       localStorage.removeItem("userToken")
+       localStorage.removeItem("captchaResponse")
        localStorage.removeItem("autologin_email")
        socket.emit('logout')
 })