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 '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(
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({
"namaUser": nama,
"emailUser": email,
......@@ -21,4 +22,65 @@ Future<bool> signup(nama, email, nohp, username, password)async{
return false;
}
// return response.statusCode;
}
\ No newline at end of file
}
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> {
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Spacer(),
const Spacer(),
Container(
padding: EdgeInsets.only(
left: screenize.width * 0.05
......@@ -339,9 +339,9 @@ class _RegisterState extends State<Register> {
height: 30,
width: screenize.width * 0.09,
child: ElevatedButton(
onPressed: ()async{
onPressed: () async {
if (_formKey.currentState!.validate()){
final response = await signup(
final response = await signUp(
nameController.value.text,
emailController.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