http icon indicating copy to clipboard operation
http copied to clipboard

Error singin

Open Elgabor opened this issue 4 years ago • 0 comments

//error on flutter

  unawaited(xhr.onError.first.then((_) {
  // Unfortunately, the underlying XMLHttpRequest API doesn't expose any
  // specific information about the error itself.
  completer.completeError(
      ClientException('XMLHttpRequest error.', request.url),
      StackTrace.current);
}));

//backend node.js app.post('/', express.urlencoded(), function(req, res) { // in a production environment you would ideally add salt and store that in the database as well // or even use bcrypt instead of sha256. No need for external libs with sha256 though var password = crypto.createHash('sha256').update(req.body.password).digest('hex'); connection.query("SELECT FROM users WHERE name = ?", [query.body.username], function(err, row) { if(row != undefined ) { console.error("can't create user " + req.body.username); res.status(409); res.send("An user with that username already exists"); } else { console.log("Can create user " + req.body.username); connection.query('INSERT INTO users (name, surname, username, password, mail, ruolo, appauth ) VALUES (?, ?, ?, ?, ?, ?, ?)', [req.body.name, surname, username, password, mail, ruolo, appauth]); res.status(201); res.send("Success"); } }); });

//flutter code

Future<String> attemptSignUp(String name, String surname, String username, String password, String mail, String ruolo, String appauth) async { var res = await http.post(Uri.parse("$SERVER_IP/"), body: { "name": name, "surname": surname, "username": username, "password": password, "mail": mail, "ruolo": ruolo, "appautorizzate": appauth }); if (res.statusCode == 200) return res.body; return ""; }

@override Widget build(BuildContext context) { return AlertDialog( title: Center( child: Text("CREAZIONE UTENTI"), ), content: Form( child: SingleChildScrollView( child: Column( children: [ //tasti per inserimento dati Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _nameTextController, decoration: buildInputDecoration( label: "Nome Account", hintText: "Nome"), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _surnameTextController, decoration: buildInputDecoration( label: "Cognome Account", hintText: "Cognome"), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _usernameTextController, decoration: buildInputDecoration( label: "Username Account", hintText: "Username"), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _passwordTextController, decoration: buildInputDecoration( label: "Password Account", hintText: "Password"), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _mailTextController, decoration: buildInputDecoration( label: "Indirizzo email Account", hintText: "[email protected]"), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _ruoloTextController, decoration: buildInputDecoration( label: "Ruolo Account", hintText: "admin, utente"), ), ), Padding( padding: const EdgeInsets.all(8.0), child: TextFormField( controller: _applicationTextController, decoration: buildInputDecoration( label: "Applicazioni abilitate", hintText: "Aplicazione abilitata"), ), ), ], ), ), ), actions: [ Padding( padding: const EdgeInsets.all(8.0), child: TextButton( onPressed: () async { var name = _nameTextController.text; var surname = _surnameTextController.text; var username = _usernameTextController.text; var password = _passwordTextController.text; var mail = _mailTextController.text; var ruolo = _ruoloTextController.text; var appauth = _applicationTextController.text; //controlli dei vari campi per la creazione utenti if (name.length < 4) showDialog( context: context, builder: (context) { return Text( "Il nome deve essere piu lungo di 4 caratteri"); }, ); else if (surname.length < 4) showDialog( context: context, builder: (context) { return Text( "Il cognome deve essere piu lungo di 4 caratteri"); }, ); else if (password.length < 7) showDialog( context: context, builder: (context) { return Text( "La password deve essere piu lunga di 7 caratteri"); }, ); else if (ruolo != "Admin" && ruolo != "Utente") showDialog( context: context, builder: (context) { return Text("Il ruolo deve essere o Admin o Utente"); }, ); //aggiungere controllo email e appauth //creazione account o errori else { var res = await attemptSignUp( name, surname, username, password, mail, ruolo, appauth); if (res == 201) showDialog( context: context, builder: (context) { return Text("L'account è stato creato con successo"); }, ); else if (res == 409) showDialog( context: context, builder: (context) { return Text( "L'utente risulta gia registrato, inserire nome diverso"); }, ); else { showDialog( context: context, builder: (context) { return Text("Errore, errore sconosciuto"); }, ); } } }, child: Text("Conferma")),

in my opinion the problem is in the backend but I don't know how to solve it

Elgabor avatar Oct 28 '21 08:10 Elgabor