functional register user
parent
68766a03ad
commit
0a8aeb96d8
|
|
@ -8,4 +8,5 @@ String apiVersion = '';
|
||||||
class Endpoints {
|
class Endpoints {
|
||||||
static final String version = '$baseURL/version';
|
static final String version = '$baseURL/version';
|
||||||
static final String login = '$baseURL/login';
|
static final String login = '$baseURL/login';
|
||||||
|
static final String register = '$baseURL/register';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,8 @@ import 'package:flutter/material.dart';
|
||||||
import 'package:motion_toast/motion_toast.dart';
|
import 'package:motion_toast/motion_toast.dart';
|
||||||
import 'package:motion_toast/resources/arrays.dart';
|
import 'package:motion_toast/resources/arrays.dart';
|
||||||
import 'package:pcastlivetv/components/nc_form_field.dart';
|
import 'package:pcastlivetv/components/nc_form_field.dart';
|
||||||
|
import 'package:pcastlivetv/globals.dart';
|
||||||
|
import 'package:pcastlivetv/routes.dart';
|
||||||
import 'package:pcastlivetv/stores/login_store.dart';
|
import 'package:pcastlivetv/stores/login_store.dart';
|
||||||
import 'package:validatorless/validatorless.dart';
|
import 'package:validatorless/validatorless.dart';
|
||||||
import 'package:velocity_x/velocity_x.dart';
|
import 'package:velocity_x/velocity_x.dart';
|
||||||
|
|
@ -27,6 +29,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
String companyname = '';
|
String companyname = '';
|
||||||
String email = '';
|
String email = '';
|
||||||
String password = '';
|
String password = '';
|
||||||
|
String password2 = '';
|
||||||
String channel = '';
|
String channel = '';
|
||||||
|
|
||||||
return Container(
|
return Container(
|
||||||
|
|
@ -66,57 +69,22 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
),
|
),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
|
NCFormField(label: 'Nome', value: name, validator: Validatorless.required('Nome é obrigatório'), onChanged: (value) => name = value),
|
||||||
|
NCFormField(label: 'Empresa', value: companyname, validator: Validatorless.required('Nome da empresa é obrigatório'), onChanged: (value) => companyname = value),
|
||||||
NCFormField(
|
NCFormField(
|
||||||
label: 'Nome',
|
label: 'Email',
|
||||||
value: name,
|
value: email,
|
||||||
validator: Validatorless.required('Nome é obrigatório'),
|
validator: Validatorless.multiple([Validatorless.email('Email inválido'), Validatorless.required('Email é obrigatório')]),
|
||||||
onChanged: (value) => name = value,
|
onChanged: (value) => email = value),
|
||||||
),
|
NCFormField(label: 'Senha', value: password, obscureText: true, validator: Validatorless.required('Senha é obrigatória'), onChanged: (value) => password = value),
|
||||||
const SizedBox(
|
|
||||||
height: 16.0,
|
|
||||||
),
|
|
||||||
NCFormField(
|
NCFormField(
|
||||||
label: 'Empresa',
|
label: 'Confirme Senha',
|
||||||
value: companyname,
|
value: password,
|
||||||
validator: Validatorless.required('Nome da empresa é obrigatório'),
|
obscureText: true,
|
||||||
onChanged: (value) => companyname = value,
|
validator: Validatorless.required('Senha de confirmação é obrigatória'),
|
||||||
),
|
onChanged: (value) => password2 = value),
|
||||||
const SizedBox(
|
NCFormField(label: 'Canal', value: channel, validator: Validatorless.required('Nome do canal é obrigatório'), onChanged: (value) => channel = value),
|
||||||
height: 16.0,
|
const SizedBox(height: 16.0),
|
||||||
),
|
|
||||||
NCFormField(
|
|
||||||
label: 'Email',
|
|
||||||
value: email,
|
|
||||||
validator: Validatorless.multiple(
|
|
||||||
[
|
|
||||||
Validatorless.email('Email inválido'),
|
|
||||||
Validatorless.required('Email é obrigatório'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
onChanged: (value) => email = value,
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 16.0,
|
|
||||||
),
|
|
||||||
NCFormField(
|
|
||||||
label: 'Senha',
|
|
||||||
value: password,
|
|
||||||
obscureText: true,
|
|
||||||
validator: Validatorless.required('Senha é obrigatória'),
|
|
||||||
onChanged: (value) => password = value,
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 32.0,
|
|
||||||
),
|
|
||||||
NCFormField(
|
|
||||||
label: 'Canal',
|
|
||||||
value: channel,
|
|
||||||
validator: Validatorless.required('Nome do canal é obrigatório'),
|
|
||||||
onChanged: (value) => channel = value,
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 16.0,
|
|
||||||
),
|
|
||||||
ElevatedButton(
|
ElevatedButton(
|
||||||
style: ElevatedButton.styleFrom(
|
style: ElevatedButton.styleFrom(
|
||||||
backgroundColor: const Color.fromRGBO(166, 0, 249, 1),
|
backgroundColor: const Color.fromRGBO(166, 0, 249, 1),
|
||||||
|
|
@ -126,38 +94,12 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
var data = json.encode(
|
var result = await registerUser(name, companyname, email, password, password2, channel);
|
||||||
{
|
if (result) {
|
||||||
"name": name,
|
var result = await processAuth(formKey, store, email, password);
|
||||||
"companyname": companyname,
|
if (result) {
|
||||||
"email": email,
|
router.go('/user');
|
||||||
"password": password,
|
}
|
||||||
"channel": channel,
|
|
||||||
"usertype": "U",
|
|
||||||
"blocked": "N",
|
|
||||||
"cancelled": "N",
|
|
||||||
"createdby": "Site",
|
|
||||||
},
|
|
||||||
);
|
|
||||||
var dio = Dio();
|
|
||||||
var response = await dio.request(
|
|
||||||
'http://localhost:8112/register',
|
|
||||||
options: Options(
|
|
||||||
method: 'POST',
|
|
||||||
contentType: 'application/json',
|
|
||||||
),
|
|
||||||
data: data,
|
|
||||||
);
|
|
||||||
|
|
||||||
switch (response.statusCode) {
|
|
||||||
case 200:
|
|
||||||
print(json.encode(response.data));
|
|
||||||
break;
|
|
||||||
case 406:
|
|
||||||
print('Usuário já cadastrado');
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
print(response.statusMessage);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
child: const Padding(
|
child: const Padding(
|
||||||
|
|
@ -197,6 +139,40 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||||
).show(context);
|
).show(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> registerUser(String name, String companyname, String email, String password, String password2, String channel) async {
|
||||||
|
var data = json.encode({
|
||||||
|
"name": name,
|
||||||
|
"companyname": companyname,
|
||||||
|
"email": email,
|
||||||
|
"password": password,
|
||||||
|
"channel": channel,
|
||||||
|
"usertype": "U",
|
||||||
|
"blocked": "N",
|
||||||
|
"cancelled": "N",
|
||||||
|
"createdby": "Site",
|
||||||
|
});
|
||||||
|
|
||||||
|
var dio = Dio();
|
||||||
|
|
||||||
|
var response = await dio.request(
|
||||||
|
Endpoints.register,
|
||||||
|
options: Options(method: 'POST', contentType: 'application/json'),
|
||||||
|
data: data,
|
||||||
|
);
|
||||||
|
|
||||||
|
switch (response.statusCode) {
|
||||||
|
case 200:
|
||||||
|
print(json.encode(response.data));
|
||||||
|
break;
|
||||||
|
case 406:
|
||||||
|
_displayErrorMotionToast('Usuário já cadastrado');
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
_displayErrorMotionToast(response.statusMessage!);
|
||||||
|
}
|
||||||
|
return Future.value(true);
|
||||||
|
}
|
||||||
|
|
||||||
Future<bool> processAuth(GlobalKey<FormState> formKey, LoginStore store, String email, String password) async {
|
Future<bool> processAuth(GlobalKey<FormState> formKey, LoginStore store, String email, String password) async {
|
||||||
Function? close;
|
Function? close;
|
||||||
if (formKey.currentState!.validate()) {
|
if (formKey.currentState!.validate()) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue