register page completed
This commit is contained in:
@@ -21,8 +21,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
String email = '';
|
||||
String password = '';
|
||||
TextEditingController email = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
return Container(
|
||||
color: const Color.fromRGBO(166, 0, 249, 1),
|
||||
child: Center(
|
||||
@@ -61,24 +61,22 @@ class _LoginPageState extends State<LoginPage> {
|
||||
children: [
|
||||
NCFormField(
|
||||
label: 'Email',
|
||||
value: email,
|
||||
controller: 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,
|
||||
controller: password,
|
||||
obscureText: true,
|
||||
validator: Validatorless.required('Senha é obrigatória'),
|
||||
onChanged: (value) => password = value,
|
||||
),
|
||||
const SizedBox(
|
||||
height: 32.0,
|
||||
@@ -92,7 +90,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var result = await processAuth(formKey, store, email, password);
|
||||
var result = await processAuth(formKey, store, email.text, password.text);
|
||||
if (result) {
|
||||
switch (store.userType) {
|
||||
case 'A':
|
||||
|
||||
@@ -6,6 +6,7 @@ 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/models/user_model.dart';
|
||||
import 'package:pcastlivetv/routes.dart';
|
||||
import 'package:pcastlivetv/stores/login_store.dart';
|
||||
import 'package:validatorless/validatorless.dart';
|
||||
@@ -25,12 +26,12 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
String name = '';
|
||||
String companyname = '';
|
||||
String email = '';
|
||||
String password = '';
|
||||
String password2 = '';
|
||||
String channel = '';
|
||||
TextEditingController name = TextEditingController();
|
||||
TextEditingController companyname = TextEditingController();
|
||||
TextEditingController email = TextEditingController();
|
||||
TextEditingController password = TextEditingController();
|
||||
TextEditingController password2 = TextEditingController();
|
||||
TextEditingController channel = TextEditingController();
|
||||
|
||||
return Container(
|
||||
color: const Color.fromRGBO(166, 0, 249, 1),
|
||||
@@ -69,21 +70,17 @@ 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', controller: name, validator: Validatorless.required('Nome é obrigatório')),
|
||||
NCFormField(label: 'Empresa', controller: companyname, validator: Validatorless.required('Nome da empresa é obrigatório')),
|
||||
NCFormField(label: 'Email', controller: email, validator: Validatorless.multiple([Validatorless.email('Email inválido'), Validatorless.required('Email é obrigatório')])),
|
||||
NCFormField(label: 'Senha', controller: password, obscureText: true, validator: Validatorless.required('Senha é obrigatória')),
|
||||
NCFormField(
|
||||
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: '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),
|
||||
label: 'Confirme Senha',
|
||||
controller: password2,
|
||||
obscureText: true,
|
||||
validator: Validatorless.multiple([Validatorless.required('Senha é obrigatória'), Validatorless.compare(password, 'Senhas não conferem')]),
|
||||
),
|
||||
NCFormField(label: 'Canal', controller: channel, validator: Validatorless.required('Nome do canal é obrigatório')),
|
||||
const SizedBox(height: 16.0),
|
||||
ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
@@ -94,9 +91,9 @@ class _RegisterPageState extends State<RegisterPage> {
|
||||
),
|
||||
),
|
||||
onPressed: () async {
|
||||
var result = await registerUser(name, companyname, email, password, password2, channel);
|
||||
var result = await registerUser(formKey, store, name.text, companyname.text, email.text, password.text, password2.text, channel.text);
|
||||
if (result) {
|
||||
var result = await processAuth(formKey, store, email, password);
|
||||
var result = await processAuth(formKey, store, email.text, password.text);
|
||||
if (result) {
|
||||
router.go('/user');
|
||||
}
|
||||
@@ -139,36 +136,45 @@ 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",
|
||||
});
|
||||
Future<bool> registerUser(GlobalKey<FormState> formKey, LoginStore store, String name, String companyname, String email, String password, String password2, String channel) async {
|
||||
if (formKey.currentState!.validate()) {
|
||||
formKey.currentState!.save();
|
||||
store.email = email;
|
||||
store.password = password;
|
||||
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 dio = Dio();
|
||||
|
||||
var response = await dio.request(
|
||||
Endpoints.register,
|
||||
options: Options(method: 'POST', contentType: 'application/json'),
|
||||
data: data,
|
||||
);
|
||||
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!);
|
||||
switch (response.statusCode) {
|
||||
case 200:
|
||||
var u = UserModel.fromJson(response.data);
|
||||
if (u.message != "") {
|
||||
_displayErrorMotionToast(u.message!);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 406:
|
||||
_displayErrorMotionToast('Usuário já cadastrado');
|
||||
break;
|
||||
default:
|
||||
_displayErrorMotionToast(response.statusMessage!);
|
||||
}
|
||||
}
|
||||
return Future.value(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user