Skip to content
Snippets Groups Projects
Commit cb94977b authored by Maximilian Betz's avatar Maximilian Betz
Browse files

remove obsolete login widget

parent 723b9bf7
No related branches found
No related tags found
No related merge requests found
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'datamodel.dart';
import 'dart:convert';
import 'package:http/http.dart' as http;
Future<int> login() async {
// Get Access to local configuration store. Token must be stored there!
ConfigurationStoreInstance configuration = ConfigurationStoreInstance();
String url = 'https://sandbox.sensor.awi.de/rest/sensors/contacts/login';
debugPrint("Start login to : " + url);
Map<String, dynamic> body = {'username': configuration.loginInformation.mail, 'authPassword': configuration.loginInformation.password};
String encodedBody = body.keys.map((key) => "$key=${body[key]}").join("&");
debugPrint(encodedBody);
final response = await http.post(Uri.parse(url),
body: encodedBody,
headers: {
'Accept' : 'application/json',
'Content-Type' : 'application/x-www-form-urlencoded'
},
encoding: Encoding.getByName("utf-8")
);
if (response.statusCode == 200) {
debugPrint('Login success');
debugPrint(response.body.toString());
debugPrint(response.headers.toString());
debugPrint(response.headers['set-cookie']);
} else {
debugPrint('Header: ' + response.headers.toString());
debugPrint('Body: ' + response.body.toString());
debugPrint('StatusCode: ' + response.statusCode.toString());
throw Exception('Failed to login');
}
return 0;
}
class LoginPage extends StatefulWidget{
static String tag = 'login-page';
const LoginPage({Key? key}) : super(key: key);
@override
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginPage> {
@override
Widget build(BuildContext context){
final ConfigurationStoreInstance configuration = ConfigurationStoreInstance();
var logo = Hero(
tag: 'blabla',
child: CircleAvatar(
backgroundColor: Colors.transparent,
radius: 48.0,
child: Image.asset('assets/awi_logo.png'),
)
);
final email = TextFormField(
keyboardType: TextInputType.emailAddress,
autofocus: false,
initialValue: configuration.loginInformation.mail,
decoration: InputDecoration(
hintText: 'sensor e-mail address',
contentPadding: const EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0)
)
),
onChanged: (value) {
configuration.loginInformation.mail = value;
},
);
final password = TextFormField(
autofocus: false,
initialValue: configuration.loginInformation.password,
decoration: InputDecoration(
hintText: 'sensor password',
contentPadding: const EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(32.0)
)
),
onChanged: (value){
configuration.loginInformation.password = value;
},
);
final loginButton = Padding(
padding: const EdgeInsets.symmetric(vertical: 16.0),
child: Material(
borderRadius: BorderRadius.circular(30.0),
shadowColor: Colors.lightBlueAccent.shade100,
elevation: 5.0,
child: MaterialButton(
minWidth: 200.0,
height: 42.0,
onPressed: (){
login();
//Navigator.pop(context); // Go back to previous widget
//Return to previous widget if successfully logged in. Store x-auth-token.
//Display login error if login not possible.
},
color: Colors.lightBlueAccent,
child: const Text('Log In', style: TextStyle(color: Colors.white)),
),
),
);
final forgotLabel = TextButton(
onPressed: () { },
child: const Text('Forgot password?',
style: TextStyle(color: Colors.black54),
),
);
return Scaffold(
backgroundColor: Colors.white,
body: Center(
child: ListView(
shrinkWrap: true,
padding: const EdgeInsets.only(left: 24.0, right: 24.0),
children: <Widget>[
logo,
const SizedBox(height: 48.0),
email,
const SizedBox(height: 8.0),
password,
const SizedBox(height: 24.0),
loginButton,
forgotLabel //TODO: launch https://data.awi.de/auth/
],
)
)
);
}
}
\ No newline at end of file
......@@ -6,7 +6,6 @@ import 'addevent.dart';
import 'viewevents.dart';
import 'overview.dart';
import 'configuration.dart';
import 'login.dart';
void main() {
......@@ -33,7 +32,6 @@ void main() {
'/second': (context) => const AddEvent(),
'/third': (context) => const ViewEvents(),
'/forth': (context) => const Configuration(),
'/fifth': (context) => const LoginPage(),
},
));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment