4
2
Fork 0

Merge branch 'orcas' of beep/frontend_flutter into master

pull/35/head^2
Sudharshan S. 2019-03-08 12:07:19 +00:00 committed by Gitea
commit a32575fb88
3 changed files with 55 additions and 2 deletions

View File

@ -11,6 +11,9 @@ class LoginApiProvider {
final response = await http.post("$baseUrlLogin/init",
headers: {"Content-Type": "application/json"},
body: jsonEncode({"phone_number": user.phoneNumber}));
if (response.statusCode == 400 || response.statusCode == 500) {
throw response.statusCode;
}
return response.body;
}
@ -18,6 +21,9 @@ class LoginApiProvider {
final response = await http.post("$baseUrlLogin/verify",
headers: {"Content-Type": "application/json"},
body: jsonEncode({"code": otp, "nonce": nonce, "clientid": clientid}));
if (response.statusCode == 400 || response.statusCode == 404 || response.statusCode == 500) {
throw response.statusCode;
}
return response.body;
}

View File

@ -0,0 +1,46 @@
import "../resources/login_api_provider.dart";
import "../models/user_model.dart";
import 'package:shared_preferences/shared_preferences.dart';
class LoginManager {
final loginApiProvider = LoginApiProvider();
User user;
String clientid;
String nonce;
LoginManager(User user, String clientid) {
this.user = user;
this.clientid = clientid;
this.nonce = "";
}
// Returns JWT, blank string if nothing is found
Future<String> getToken() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
final token = prefs.getString("token") ?? "";
return token;
}
// Throws error status code if it occurs
Future<void> initAuthentication(User user) async {
try {
final nonce = await loginApiProvider.initAuthentication(user);
this.nonce = nonce;
} catch(e) {
throw e;
}
}
// Throws error status code if it occurs, otherwise returns jwt
Future<String> processOTP(String otp) async {
try {
final jwt = await loginApiProvider.verifyOtp(otp, this.nonce, this.clientid);
SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString("token", jwt);
return jwt;
} catch(e) {
throw e;
}
}
}

View File

@ -1,5 +1,5 @@
name: frontend_flutter
description: The new way to communicate with your friends and family by merging the efficiency of voice calls with the convenience of messaging.
description: The new way to communicate with your friends and family by merging the efficiency of voice calls with the convenience of messaging.
version: 1.0.0+1
environment:
@ -15,6 +15,7 @@ dependencies:
flutter_webrtc: ^0.1.0
pin_code_text_field: ^1.1.3
flutter_svg: ^0.10.3
shared_preferences: ^0.5.1
dev_dependencies:
flutter_test:
@ -30,7 +31,7 @@ flutter_icons:
flutter:
uses-material-design: true
assets:
- assets/logo.png
- assets/phoneno.svg