Commit d36e99f3 authored by Mauritz, Falk Marius's avatar Mauritz, Falk Marius
Browse files

Auth in Client

todo
parent 8256a487
Pipeline #6305 passed with stage
in 3 minutes and 51 seconds
......@@ -32,25 +32,11 @@ class LoginComponent implements OnInit, OnActivate {
//
Future<void> login() async {
users = await _userService.getAll();
for (User u in users) {
if ((username == u.username || username == u.email) && password ==u.password) {
loggedIn = true;
AppComponent.showButtons = true;
await _router.navigate('/dashboard');
break;
} else {
loginFailure = true;
}
}
/*
if (username.contains("@")) {
user = await _userService.getLoginEmail(password, username);
} else {
user = await _userService.getLoginNickname(password, username);
}*/
await _userService.login(username,password);
}
// Weiterleitung zum Registrierungsformular
Future<void> register() async {
await _router.navigate('/register');
......
import 'dart:async';
import 'dart:convert';
import 'dart:html';
import 'package:demo/src/view/main_component.dart';
import 'package:http/http.dart';
import 'package:demo/src/model/person.dart';
......@@ -26,24 +27,40 @@ class UserService {
final response = await _http.post(_userUrl,
headers: _headers, body: json.encode(user.toJson()));
return User.fromJson(
_extractData(response) as Map<String, dynamic>);
_extractData(response as Response) as Map<String, dynamic>);
} catch (e) {
throw _handleError(e);
}
}
Future<List<User>> getAll() async {
final Response response = await _http.get('$_userUrl');
final Response response = await _http.get('$_userUrl') as Response;
return (_extractData(response) as List)
.map((value) => User.fromJson(value as Map<String, dynamic>))
.toList();
}
Future<User> get(String contactCode) async {
final Response response = await _http.get('$_userUrl/$contactCode');
final Response response = await _http.get('$_userUrl/$contactCode') as Response;
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}
Future login(username, password) async {
var response =
await _http.post(_userUrl, body: {'username': username, 'password': password}) as Response;
Map<String,dynamic> mappedResponse = json.decode(response.body) as Map<String,dynamic>;
window.localStorage.addAll({"token": mappedResponse["key"]as String});
}
Future check_authentification () async {
String _headers_key = "Authorization";
String _headers_value = "Token "+window.localStorage["token"];
var response = await _http.get("http://127.0.0.1:8000/auth/user/", headers: {_headers_key: _headers_value})as Response;
Map<String,dynamic> jsonMap = json.decode(response.body) as Map<String,dynamic>;
print(response.statusCode);
}
/*Future<User> getLoginEmail(String password, String email) async {
final Response response = await _http.get('$_userUrl/$password/$email');
return User.fromJson(_extractData(response) as Map<String, dynamic>);
......
Supports Markdown
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