functional register user
parent
68766a03ad
commit
0a8aeb96d8
|
|
@ -8,4 +8,5 @@ String apiVersion = '';
|
|||
class Endpoints {
|
||||
static final String version = '$baseURL/version';
|
||||
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/resources/arrays.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:validatorless/validatorless.dart';
|
||||
import 'package:velocity_x/velocity_x.dart';
|
||||
|
|
@ -27,6 +29,7 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
String companyname = '';
|
||||
String email = '';
|
||||
String password = '';
|
||||
String password2 = '';
|
||||
String channel = '';
|
||||
|
||||
return Container(
|
||||
|
|
@ -66,57 +69,22 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
),
|
||||
child: Column(
|
||||
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(
|
||||
label: 'Nome',
|
||||
value: name,
|
||||
validator: Validatorless.required('Nome é obrigatório'),
|
||||
onChanged: (value) => name = value,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 16.0,
|
||||
),
|
||||
label: 'Email',
|
||||
value: email,
|
||||
validator: Validatorless.multiple([Validatorless.email('Email inválido'), Validatorless.required('Email é obrigatório')]),
|
||||
onChanged: (value) => email = value),
|
||||
NCFormField(label: 'Senha', value: password, obscureText: true, validator: Validatorless.required('Senha é obrigatória'), onChanged: (value) => password = value),
|
||||
NCFormField(
|
||||
label: 'Empresa',
|
||||
value: companyname,
|
||||
validator: Validatorless.required('Nome da empresa é obrigatório'),
|
||||
onChanged: (value) => companyname = value,
|
||||
),
|
||||
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,
|
||||
),
|
||||
label: 'Confirme Senha',
|
||||
value: password,
|
||||
obscureText: true,
|
||||
validator: Validatorless.required('Senha de confirmação é obrigatória'),
|
||||
onChanged: (value) => password2 = value),
|
||||
NCFormField(label: 'Canal', value: channel, validator: Validatorless.required('Nome do canal é obrigatório'), onChanged: (value) => channel = value),
|
||||
const SizedBox(height: 16.0),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color.fromRGBO(166, 0, 249, 1),
|
||||
|
|
@ -126,38 +94,12 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
),
|
||||
),
|
||||
onPressed: () 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(
|
||||
'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);
|
||||
var result = await registerUser(name, companyname, email, password, password2, channel);
|
||||
if (result) {
|
||||
var result = await processAuth(formKey, store, email, password);
|
||||
if (result) {
|
||||
router.go('/user');
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Padding(
|
||||
|
|
@ -197,6 +139,40 @@ class _RegisterPageState extends State<RegisterPage> {
|
|||
).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 {
|
||||
Function? close;
|
||||
if (formKey.currentState!.validate()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue