Plan-B
authorRemixDev <deezloaderremix@gmail.com>
Thu, 7 Mar 2019 09:48:19 +0000 (10:48 +0100)
committerRemixDev <deezloaderremix@gmail.com>
Thu, 7 Mar 2019 09:48:19 +0000 (10:48 +0100)
app/app.js
app/public/index.html
app/public/js/frontend.js

index 9e32dcdd47f44d99c4cae912e6bcd31948a7ba7a..e573ef56e61b47e976f1931329b04413703d27c7 100644 (file)
@@ -124,6 +124,20 @@ io.sockets.on('connection', function (s) {
                        s.emit("login", {error: err.message})
                        logger.error(`Login failed: ${err.message}`)
                }
+       })
+
+       // Function for login with userToken
+       s.on("loginViaUserToken", async function (userToken) {
+               try{
+                       logger.info("Logging in");
+                       await s.Deezer.loginViaUserToken(userToken)
+                       s.emit("login", {user: s.Deezer.user})
+                       logger.info("Logged in successfully")
+                       s.emit('getCookies', s.Deezer.getCookies())
+               }catch(err){
+                       s.emit("login", {error: err.message})
+                       logger.error(`Login failed: ${err.message}`)
+               }
        });
 
        // Function for autologin
index 61ffaaf2716ac556c2737484d04eb331388f6a43..a9fe99c5b54dea1928646608e0edc0d32b28d6a7 100644 (file)
        <div class="modal-content container" id="login-page">
                <div class="card">
                        <div class="card-content">
-                               <span class="card-title">Please login to your deezer account.</span>
+                               <span class="card-title">Please paste here your userToken</span>
                                <h6 class="red-text" id="login-res-text"></h6>
                                <div class="input-field col s12">
-                                       <input autocomplete="off" type="text" id="modal_login_input_username"/>
-                                       <label for="modal_login_input_username">Email</label>
-                               </div>
-                               <div class="input-field col s12">
-                                       <input autocomplete="off" type="password" id="modal_login_input_password"/>
-                                       <label for="modal_login_input_password">Password</label>
+                                       <input autocomplete="off" type="password" id="modal_login_input_userToken"/>
+                                       <label for="modal_login_input_userToken">userToken</label>
                                </div>
                        </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>
index 014526d91663aca80d9d097276a6055c6173a5a6..d66520c52dad876c4eb350a5622853b5a2e42b5a 100644 (file)
@@ -29,6 +29,7 @@ socket.on("printObj", function(obj){
 $('#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")
@@ -37,6 +38,10 @@ $('#modal_login_btn_login').click(function () {
        }
        //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)
 })
 
 // New login system (uses cookies)
@@ -51,7 +56,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(data.user.email)
+               $("#side_email").text("id:"+data.user.id)
                $('#initializing').addClass('animated fadeOut').on('webkitAnimationEnd', function () {
                        $(this).css('display', 'none')
                        $(this).removeClass('animated fadeOut')
@@ -97,11 +102,12 @@ $(document).ready(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_username').val(localStorage.getItem('autologin_email'))
+               //$('#modal_login_input_password').val("password")
+               $('#modal_login_input_userToken').val(localStorage.getItem('userToken'))
                M.updateTextFields()
        }
 
@@ -341,15 +347,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_username').val("")
+       //$('#modal_login_input_password').val("")
+       //$('#modal_login_input_autologin').prop("checked",false)
+       $('#modal_login_input_userToken').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("autologin_email")
        socket.emit('logout')
 })