Commit fc4559c5 authored by qorri_di's avatar qorri_di

user api

-setting signIn
-setting signOut
-setting signUp
-setting resetPassword
-setting get_user
parent 297a0bd5
import 'dart:convert'; import 'dart:convert';
import 'package:http/http.dart' as http; import 'package:http/http.dart' as http;
import 'package:medapp_eksad/model/user_model.dart';
Future<bool> signup(nama, email, nohp, username, password)async{ Future<bool> signUp(nama, email, nohp, username, password)async{
final response = await http.post( final response = await http.post(
Uri.parse('http://10.3.4.250:8081/medapp/v1/api/user/save'), Uri.parse('http://10.3.4.250:8081/medapp/v1/api/user/signup'),
body: jsonEncode({ body: jsonEncode({
"namaUser": nama, "namaUser": nama,
"emailUser": email, "emailUser": email,
...@@ -22,3 +23,64 @@ Future<bool> signup(nama, email, nohp, username, password)async{ ...@@ -22,3 +23,64 @@ Future<bool> signup(nama, email, nohp, username, password)async{
} }
// return response.statusCode; // return response.statusCode;
} }
Future<bool> signIn(username, password)async{
final response = await http.post(
Uri.parse('http://10.3.4.250:8081/medapp/v1/api/user/signin'),
body: jsonEncode({
"username": username,
"password": password}),
headers: {
'Content-type' : 'application/json; charset=UTF-8',
}
);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
// return response.statusCode;
}
Future<bool> signOut(username)async{
final response = await http.post(
Uri.parse('http://10.3.4.250:8081/medapp/v1/api/user/signout'),
body: jsonEncode({
"username": username}),
headers: {
'Content-type' : 'application/json; charset=UTF-8',
}
);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
// return response.statusCode;
}
Future<bool> resetPassword(username, password, verifypass)async{
final response = await http.put(
Uri.parse('http://10.3.4.250:8081/medapp/v1/api/user/resetPassword'),
body: jsonEncode({
"username": username,
"password": password,
"passwordBaru": verifypass
}),
headers: {
'Content-type' : 'application/json; charset=UTF-8',
}
);
if (response.statusCode == 200) {
return true;
} else {
return false;
}
// return response.statusCode;
}
Future<List<dynamic>> getUser() async {
var response = await http
.get(Uri.parse('http://10.3.4.231:8082/medapp/v1/api/user/get'));
var resultJson = jsonDecode(response.body)['data'];
List<user> walist = await resultJson
.map<user>((json) => user.fromJson(json))
.toList();
return walist;
}
...@@ -96,7 +96,7 @@ class _RegisterState extends State<Register> { ...@@ -96,7 +96,7 @@ class _RegisterState extends State<Register> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceEvenly, mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [ children: [
Spacer(), const Spacer(),
Container( Container(
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: screenize.width * 0.05 left: screenize.width * 0.05
...@@ -339,9 +339,9 @@ class _RegisterState extends State<Register> { ...@@ -339,9 +339,9 @@ class _RegisterState extends State<Register> {
height: 30, height: 30,
width: screenize.width * 0.09, width: screenize.width * 0.09,
child: ElevatedButton( child: ElevatedButton(
onPressed: ()async{ onPressed: () async {
if (_formKey.currentState!.validate()){ if (_formKey.currentState!.validate()){
final response = await signup( final response = await signUp(
nameController.value.text, nameController.value.text,
emailController.value.text, emailController.value.text,
phoneController.value.text, phoneController.value.text,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment