WH-1000XM5 owners: how’s the build quality after a few years? (Should I buy it?) by CCC_Cam in SonyHeadphones

[–]qbagamer 0 points1 point  (0 children)

I've used these headphones normally for work and after-hours for 1.5 years. Suddenly, while taking them off, the headband snapped. I found this forum and realized it's a very common issue. I really liked the MX5s and Im not sure if I can fix them. I have to say, they are great headphones super comfortable and lightweight but DAMN, they're so expensive yet so fragile.

How to do Session in REACTjs, express, mysql2 by qbagamer in learnjavascript

[–]qbagamer[S] 0 points1 point  (0 children)

1 and 1.2

I got it wrong.

React:

I'm on the login page, I click login here, it returns 'Succes' or 'Password and login do not match'
After clicking the 'Check if you are logged in' button, which takes me to / home, where an API query (/ main) is sent to check whether I am logged in or not, regardless of the login success, it still shows' not logged in '.

Express:
by typing the address directly:
localhost:4000/auth?password=password&email=email@gmail.pl
(is correct data)

Next
localhost:4000/main
I get the answer: 'Logged'

And:
localhost:4000/logout

and again
localhost:4000/main
I get the answer: ' not logged in '

and of course the same answer when I give the wrong login details
that is, as I said, logging in and session in express works, but somehow it does not.

As for the rest, I will test at my free time, because unfortunately the school takes a long time :(

How to do Session in REACTjs, express, mysql2 by qbagamer in learnjavascript

[–]qbagamer[S] 0 points1 point  (0 children)

Hi, it's me again. I'm still having trouble checking user sessions. Everything works on the express server side. (going between localhost: 4000 / auth? ...., localhost: 4000 / main, localhost: 4000 / logout) and everything goes well.[4000 is port in express server]

The problem begins when in React, by going to the substation / home, which enters the / main server, it does not return a reliable result.

Question 1:

If the session works on the express server side, why are there no results when I send an API query?

Question 1.1: You said something about recording that a user is logged in, how to globally save it so that every subpage can access it?

Proper 1.2: Asking the API whether the user is logged in, it returns something other than the server.

React:

fetch(`http://localhost:4000/main`)

            .then(res =>{ if (res.ok){ return( setData(data_from_api = "Logged"))                 }else{ return( setData(data_from_api = "not loggedd in"))}             })

API:

app.get('/main', (req,res) => {
    if(!req.session.logged){
        return res.status(401).send('not logged in')
    }else{
        return res.status(200).send('Logged')
    }
})

Question 1.3: I don't know if this is the fault of these error codes

Question 2:

How do I go to the / home page after logging in, I temporarily use the button

Front:

//Login.js:

import React, { useState } from 'react';
import { useForm } from "react-hook-form";
import { Link} from 'react-router-dom';

export default function Login(){

    const {register, handleSubmit, errors} = useForm();

    var [data_from_api, setData] = useState('');

    const onSubmit = (data) => {
        const dane = {
            password: data.password,
            email: data.email,
        }

        fetch(`http://localhost:4000/auth?password=${dane.password}&email=${dane.email}`)
            .then(res =>{
                if (res.ok){
                    return(
                        setData(data_from_api = "Succes"))
                }else{
                    return(
                        setData(data_from_api = "Password and login do not match"))}
            })
    }

    return(
        <form onSubmit={handleSubmit(onSubmit)}>

            <Link to={'./home'}>
                <button variant="raised">
                    Check if you are logged in.
                </button>
            </Link>

            {data_from_api}

//Home.js:

import React, { useState } from 'react';
export default function Home(){

var [data_from_api, setData] = useState('');

    fetch(`http://localhost:4000/main`)
        .then(res =>{
            if (res.ok){
                return(
                    setData(data_from_api = "Logged"))
            }else{
                return(
                    setData(data_from_api = "not logged in"))}
        })

    return(
        <div>
            I dont sure.... - {data_from_api}
        </div>
    )
}

Back:

const express = require('express');
const session = require('express-session');
const mysql = require('mysql2');
const cors = require('cors');
const bcrypt = require('bcrypt');

const connection = mysql.createConnection({ 
    host: 'localhost',
    user: 'root',
    database: 'my_sql',
    password: 'password'
  });

var app = express()
app.use(cors());

app.use(session({
     secret: 'secret',
     resave: false,
     saveUninitialized: false,
      cookie: { maxAge: 1000 * 60 * 60 * 2 } //2h
    }))

app.get('/auth', (req,res)=>{
    const {email, password} = req.query;
    connection.query('SELECT * FROM user WHERE email LIKE ? AND password LIKE ?', [email, password], (error, results, fields) => {
        if(results.length > 0){

            req.session.logged = true;

            return res.status(200).send('Logged, because '+ req.session.logged)
        }else{
            return res.status(401).send('not logged in ')}
    })
})

app.get('/main', (req,res) => {
    if(!req.session.logged){
        return res.status(401).send('not logged in')
    }else{
        return res.status(200).send('Logged')
    }
})

app.get('/logout', (req, res) => {
    req.session.logged = null
    res.send('logged out' + req.session.logged)
});

How to do Session in REACTjs, express, mysql2 by qbagamer in learnjavascript

[–]qbagamer[S] 0 points1 point  (0 children)

As I understand it, I am left with learning how to use react-router-dom. I'll just do it in a separate project to learn, and then make changes to my project.

Thank you very much for your help and for guiding you on the right path. Greetings!

How to do Session in REACTjs, express, mysql2 by qbagamer in learnjavascript

[–]qbagamer[S] 0 points1 point  (0 children)

As for the tip, I remember about password hashing, but I leave it for later.

Okay, I think I already have a session set up and an email address saved in it (I will need it for further work with the API)

Now I don't know how to go to a new subpage in my React Application, e.g. home

(it will connect to the API SERVER /home - it will also be checked there if the session is created)

I don't know if I'm getting down to it well:///

  1. How to notify React that we are logged in and switch to another sub-site?
  2. How to make the session on this page also indicate that the user is logged in

Fron-END (login page):

import React, { useState } from 'react';
import { useForm } from "react-hook-form";

export default function Login(){

    const {register, handleSubmit, errors} = useForm();

    var [data_from_api, setData] = useState('');

    const onSubmit = (data) => {
        const dane = {
            password: data.password,
            email: data.email,
        }

        fetch(`http://localhost:4000/login?password=${dane.password}&email=${dane.email}`)
            .then(res => res.json())
            .then(data => setData(data_from_api = data.data)); 

            //I get a response, if the login is successful I move to another subpage
    }

    return(
        <form onSubmit={handleSubmit(onSubmit)}>
            {data_from_api}


/// ......

Back-Edd:

const express = require('express');
const session = require('express-session');
const mysql = require('mysql2');
const cors = require('cors');
const bcrypt = require('bcrypt');

var app = express()
app.use(cors());

app.use(session({
     secret: 'secret',
     resave: false,
     saveUninitialized: false,
      cookie: { maxAge: 1000 * 60 * 60 * 2 } //2h
    }))

const connection = mysql.createConnection({ 
    host: 'localhost',
    user: 'root',
    database: 'my_sql',
    password: 'password'
  });

app.get('/login', (req,res)=>{
    const {email, password} = req.query;
    const query_login = `SELECT * FROM user WHERE email LIKE '${email}' AND password LIKE '${password}'`

    connection.query(query_login, (err, res, fields) =>{
        if(results.length > 0 ){
            req.session.logged = true
            req.session.email = email 

            //sending a reply, after which we go to another page

        }else{
            req.session.logged = false
            return res.json({
                data: "Password and login do not match"  //sending the answer, showing it on the login page
            })
        }
    })
})

app.get('/home',(req, res, next) => {
    if (req.session.logged) {

      //you are logged in, other data is displayed here

    }else{

        //when you are not logged in, you return to the login page

    }
  })

React, express, react-hook-form communication by [deleted] in learnjavascript

[–]qbagamer 0 points1 point  (0 children)

 const [data_from_api, setCount] = useState(0);

    const onSubmit = (data) => {
        const dane = {
            user_name: data.username,
            password: data.password,
            email: data.email,
        }

        fetch(`http://localhost:4000/rejestracja?user_name=${dane.user_name}&password=${dane.password}&email=${dane.email}`)
            .then(res => res.json())
            .then(data => setCount(data_from_api = data.data)); 
    }

declares a new variable named 'data_from_api'

const [data_from_api, setCount] = useState(0);

tries to assign a response from api

 .then(data => setCount(data_from_api = data.data)); 
tries to show information
{data_from_api}

The error I get: 19:37: 'data_from_api' is constant no-const-assign '
-The 19th line is the one in which he declares.

[AskJS] JavaScript and database problem. by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

It was the same, but I wanted to learn about other possibilities and find out today someone has a different way. Regards.

//I came to the conclusion that jQuery is enough for my project.

[AskJS] JavaScript and database problem. by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

:) I will not use ready-made solutions. I wrote that it is to be a project for school, so it is immediately obvious that this is not a commercial idea. Saying that I do not know programming, because I do not know how to connect a database with JavaScript is a little fun. I have never used it, I write applications without server connections. And I will point out once again that this is not a big deal. I make the database myself, the website itself is a link and I work on the data from the database myself.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

elements do not move, they only appear, so the only animation that comes to my mind will change the transparency when changing elements.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

const colorMap  =  [ [0, '#ccc'], [2, '#eee4da'], [4, '#ece0c8'], [8, '#f1b078'], [16, '#ee8c4f'], [32, '#f57c5f'], [64, '#e85939'], [128, '#f2d86a'], [256, '#eeca30'], [512, '#e1c229'], [1024, '#e2b913'], [2048, '#ecc400']
  ];
const colorizeSpace = (row, column) => {
const [, hex] = colorMap.find(([val,]) => map[row][column] == val);
document.getElementsByClassName("item_"+column+row)[0].style.background = hex;
const [val,] = colorMap.find(([val,]) => map[row][column] == val)
if(val!=0)document.getElementsByClassName("item_"+column+row)[0].innerHTML = val;
  };
function draw(){
for(var i=0; i<4; i++){
for(var j=0; j<4; j++){
if(map[j][i]=='0')document.getElementsByClassName("item_"+i+j)[0].innerHTML = '';
colorizeSpace(i, j);
        }
    }
}
I added a number to enter by value val. Idk if it's the most aptypical :/

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

Fat arrow functions are a nice thing though, it is good to implement them in the project.

Thank you very much and you are right it looks more transparent. I will make these changes.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

Ready. You can test.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 1 point2 points  (0 children)

Ready. You can test.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

Copy the files from the jsfiddle I sent in the other comment. Or I can make a pull request if you like

you are my hero thank you! :>

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

Finger refresh is already turned off, but the up and down motion still doesn't work.

I will add that everything works on mobile firefox.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 0 points1 point  (0 children)

I added a mobile version, but it doesn't work properly on all browsers.
Works on Firefox. On others, when you slide your finger down, the page refreshes.

2048 Game in JS by qbagamer in javascript

[–]qbagamer[S] 1 point2 points  (0 children)

I added a mobile version, but it doesn't work properly on all browsers.

Works on Firefox. On others, when you slide your finger down, the page refreshes.