Commit c08a79b9 authored by HellLab's avatar HellLab
Browse files

Merge remote-tracking branch 'origin/AqueductBranch' into AqueductBranch

# Conflicts:
#	frontend/lib/src/model/appointment.dart
#	frontend/lib/src/view/services/person_service.dart
parents 58e3b9e8 b4f74daf
......@@ -31,13 +31,17 @@ SQL zum erstellen einer Datenbank,
// entfernt alle aktuellen verbindungen zur db
select pg_terminate_backend(pid) from pg_stat_activity where datname='calendar';
// löscht die Database
DROP DATABASE calendar
DROP DATABASE calendar;
----------------------------------------------
CREATE DATABASE calendar;
CREATE USER cal_user WITH createdb;
ALTER USER cal_user WITH password 'password';
CREATE DATABASE calendar;
GRANT all ON database calendar TO cal_user;
----------------------------------------------
aqueduct auth add-client --id com.calendar.app
// dockercompose
......
......@@ -5,7 +5,7 @@ COPY frontend/pubspec.yaml /root/build-here/
RUN pub get
COPY frontend/ /root/build-here/
RUN pub get
RUN pub run build_runner build --output web:build
RUN pub run build_runner build --output web:build --release
FROM nginx
EXPOSE 80
RUN sed -i -e 's, location / {, location /calendar {,g' /etc/nginx/conf.d/default.conf; \
......
......@@ -10,4 +10,4 @@ targets:
compiler: dart2js
dart2js_args:
- --minify
- -Dhost=https://projects.mylab.th-luebeck.de:443/calendar/mm
- -Dhost=http://localhost:8888
\ No newline at end of file
......@@ -17,6 +17,7 @@ class Appointment {
appointment['location'] as String,
appointment['note'] as String);
List<String> contactCodes = [];
int id;
String name;
int year;
......@@ -27,8 +28,8 @@ class Appointment {
String location = "";
String note = "";
Map<String,dynamic> toJson() => {
'id' :id,
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'year': year,
'month': month,
......
abstract class Person {
Person(this.id, this.contactCode, this.nickname, this.surname, this.name,
Person(this.id, this.contactCode, this.username, this.surname, this.name,
this.email);
Person.zero();
int id;
String nickname;
String username;
String surname;
String name;
String email;
......@@ -12,7 +12,7 @@ abstract class Person {
bool equals(Person person) {
return this.email == person.email &&
this.nickname == person.nickname &&
this.username == person.username &&
this.name == person.name &&
this.surname == person.surname &&
this.contactCode == person.contactCode &&
......@@ -20,19 +20,22 @@ abstract class Person {
}
}
/// Hier ist der User
class User extends Person {
User(int id, String contactCode, String nickname, String surname, String name,
User(int id, String contactCode, String username, String surname, String name,
String email, String password, String mobileNo)
: password = password,
mobileNo = mobileNo,
super(id, contactCode, nickname, surname, name, email);
super(id, contactCode, username, surname, name, email);
User.zero() : super.zero();
factory User.fromJson(Map<String, dynamic> user) => User(
user['id'] as int,
user['contactCode'] as String,
user['nickname'] as String,
user['username'] as String,
user['surname'] as String,
user['name'] as String,
user['email'] as String,
......@@ -46,26 +49,10 @@ class User extends Person {
String password;
String mobileNo;
// Adds a single contact, no duplicate by contactcode
void addContact(Contact con) {
if (_contactlist.any((ele) => ele.contactCode != con.contactCode)) {
_contactlist.add(con);
}
}
// adds all Contacts, no duplicates by contactcode
void addContacts(List<Contact> list) => list.forEach(addContact);
// removes contact from list
void rmvContact(Contact con) => _contactlist.remove(con);
// removes multiple Contacts
void rmvAllContacts(List<Contact> list) => list.forEach(rmvContact);
Map<String, dynamic> toJson() => {
'id': id,
'contactCode': contactCode,
'nickname': nickname,
'username': username,
'surname': surname,
'name': name,
'email': email,
......@@ -76,18 +63,18 @@ class User extends Person {
Map<String, Contact> getMyContacts() {}
}
int _toInt(id) => id is int ? id : int.parse(id as String);
/// Hier ist der Kontakt
class Contact extends Person {
Contact(int id, String nickname, String surname, String name, String email,
Contact(int id, String username, String surname, String name, String email,
String contactCode, String note)
: super(id, contactCode, nickname, surname, name, email) {
: super(id, contactCode, username, surname, name, email) {
this.note = note;
}
factory Contact.fromJson(Map<String, dynamic> contact) => Contact(
contact['id'] as int,
contact['nickname'] as String,
contact['username'] as String,
contact['surname'] as String,
contact['name'] as String,
contact['email'] as String,
......@@ -98,7 +85,7 @@ class Contact extends Person {
Map<String, dynamic> toJson() => {
'id': id,
'nickname': nickname,
'username': username,
'surname': surname,
'name': name,
'email': email,
......
......@@ -15,11 +15,11 @@ td:hover{
}
h4{
text-align: center;
cursor: hand;
cursor: pointer;
}
table tr {
height: 5em;
height: 10vh;
}
table{
......
......@@ -37,6 +37,6 @@
</tr>
</table>
<h4 (click)="next()">Next -&gt;&gt;</h4>
<h4 (click)="previous()">&lt;&lt;- Previous</h4>
<h4 (click)="next()">Next &#8594;</h4>
<h4 (click)="previous()">&#8592; Previous</h4>
</div>
\ No newline at end of file
<div *ngIf="contact != null">
<h3>{{contact.nickname}}</h3>
<h3>{{contact.username}}</h3>
<table>
<tr>
......
......@@ -12,7 +12,7 @@
<td><b>Delete</b></td>
</tr>
<tr *ngFor="let contact of contacts" id="contact">
<tr (click)="gotoDetail(contact)">{{contact.nickname}}</tr>
<tr (click)="gotoDetail(contact)">{{contact.username}}</tr>
<td (click)="gotoDetail(contact)">{{contact.surname}}</td>
<td (click)="gotoDetail(contact)">{{contact.name}}</td>
<td (click)="gotoDetail(contact)">{{contact.email}}</td>
......
......@@ -6,7 +6,7 @@
<div>
<div *ngFor="let contact of contacts | async"
(click)="contact.delete()" class="search-result" >
{{contact.nickname}}
{{contact.username}}
</div>
</div>
</div>
......@@ -27,7 +27,7 @@ class DashboardComponent implements OnInit, OnActivate {
@override
void onActivate(RouterState previous, RouterState current) async {
if (!LoginComponent.loggedIn) {
_router.navigate('/login');
await _router.navigate('/login');
}
else{
joke = await _dashboardService.getJoke();
......
......@@ -28,7 +28,7 @@ class DayviewComponent implements OnActivate {
@override
void onActivate(_, RouterState current) async {
if (!LoginComponent.loggedIn) {
_router.navigate('/login');
await _router.navigate('/login');
} else {
this.day = Day(
getYear(current.parameters),
......
......@@ -2,6 +2,7 @@ import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart';
import 'package:angular_router/angular_router.dart';
import 'package:demo/src/view/services/person_service.dart';
import 'package:demo/src/view/services/register_service.dart';
import '../../model/person.dart';
import '../main_component.dart';
......@@ -12,42 +13,28 @@ import '../main_component.dart';
styleUrls: ['login_component.css'],
directives: [coreDirectives, routerDirectives, formDirectives],
)
class LoginComponent implements OnInit, OnActivate {
LoginComponent(this._router, this._userService);
LoginComponent(this._router, this._userService, this._registerService);
final UserService _userService;
final RegisterService _registerService;
final Router _router;
bool loginFailure = false;
static bool loggedIn = false;
String nickname;
String username;
String password;
List<User> users;
//User user;
//
//
Future<void> login() async {
users = await _userService.getAll();
for (User u in users) {
if ((nickname == u.nickname || nickname == u.email) && password ==u.password) {
loggedIn = true;
AppComponent.showButtons = true;
await _router.navigate('/dashboard');
break;
} else {
loginFailure = true;
}
}
/*
if (nickname.contains("@")) {
user = await _userService.getLoginEmail(password, nickname);
} else {
user = await _userService.getLoginNickname(password, nickname);
}*/
await _registerService.login(username, password);
loggedIn = true;
AppComponent.showButtons = true;
await _router.navigate('/dashboard');
}
// Weiterleitung zum Registrierungsformular
......@@ -77,4 +64,4 @@ class LoginComponent implements OnInit, OnActivate {
_router.navigate('/calendar');
}
}
}
\ No newline at end of file
}
......@@ -2,10 +2,10 @@
<h3>Login</h3>
<form class="form">
<div class="form-group">
<label for="nickname">Nickname/Email&nbsp;</label>
<input type="text" class="form-control" id="nickname" placeholder="Nickname"
[(ngModel)]="nickname"
ngControl="nickname">
<label for="username">Username/Email&nbsp;</label>
<input type="text" class="form-control" id="username" placeholder="Username"
[(ngModel)]="username"
ngControl="username">
</div>
<div class="form-group">
<label for="password">Password&nbsp;</label>
......@@ -13,7 +13,7 @@
[(ngModel)]="password"
ngControl="password">
<div [hidden]="!loginFailure" class="loginFailure">
Nickname/Email oder Passwort falsch
Username/Email oder Passwort falsch
</div>
</div>
<button type="submit" class="btn btn-success" (click)="login()">Login</button>
......
......@@ -20,7 +20,7 @@ class RegisterComponent implements OnInit, OnActivate {
final Router _router;
final UserService _registerService;
User user = User.zero();
String passwordWh = "";
String passwordWh ="";
Future<void> register() async {
......@@ -45,8 +45,4 @@ class RegisterComponent implements OnInit, OnActivate {
_router.navigate('/calendar');
}
}
}
\ No newline at end of file
......@@ -2,13 +2,13 @@
<h3>Register</h3>
<form #registerForm="ngForm">
<div class="form-group">
<label for="nickname">Nickname&nbsp;*</label>
<input type="text" class="form-control" id="nickname" required placeholder="Nickname"
#nickname="ngForm"
[class.is-valid]="nickname.valid"
[class.is-invalid]="!nickname.valid"
[(ngModel)]="user.nickname"
ngControl="nickname">
<label for="username">Username&nbsp;*</label>
<input type="text" class="form-control" id="username" required placeholder="Username"
#username="ngForm"
[class.is-valid]="username.valid"
[class.is-invalid]="!username.valid"
[(ngModel)]="user.username"
ngControl="username">
</div>
<div class="form-group">
<label for="surname">Surname&nbsp;*</label>
......
......@@ -10,6 +10,7 @@ import 'package:demo/src/view/services/appointment_service.dart';
import 'package:demo/src/view/services/contact_service.dart';
import 'package:demo/src/view/services/dashboard_service.dart';
import 'package:demo/src/view/services/person_service.dart';
import 'package:demo/src/view/services/register_service.dart';
import 'components/login_component.dart';
......@@ -23,6 +24,7 @@ import 'components/login_component.dart';
ClassProvider(UserService),
ClassProvider(ContactService),
ClassProvider(DashboardService),
ClassProvider(RegisterService),
],
exports: [RoutePaths, Routes],
)
......
......@@ -55,6 +55,7 @@ class Routes {
static final RouteDefinition login = RouteDefinition(
routePath: RoutePaths.login,
component: login_template.LoginComponentNgFactory as ComponentFactory,
useAsDefault: true,
);
static final RouteDefinition contacts = RouteDefinition(
routePath: RoutePaths.contacts,
......@@ -79,7 +80,7 @@ class Routes {
login,
RouteDefinition.redirect(
path: '',
redirectTo: RoutePaths.dashboard.toUrl(),
redirectTo: RoutePaths.login.toUrl(),
),
];
}
......@@ -12,10 +12,17 @@ class AppointmentService {
// request to middlemand
AppointmentService(this._http);
static final _headers = {'Content-Type': 'application/json'};
static const _appointmentUrl = host + '/appointments'; // URL to web API
final Client _http;
static const _type = MapEntry('Content-Type', 'application/json');
// getter for the Authorization
Map<String,String> get _headers => Map.fromEntries(
[MapEntry("Authorization", "$_tokenType $_tokenAuth"), _type]);
String get _tokenType => window.localStorage["token_type"];
String get _tokenAuth => window.localStorage["access_token"];
///Liest die Daten aus einer Response
dynamic _extractData(Response resp) => json.decode(resp.body);
......@@ -27,43 +34,43 @@ class AppointmentService {
///Updatet einen bereits existierenden Termin
///Erstellt einen neuen Termin mit gegebenen Namen
Future<Appointment> update(Appointment appointment) async {
final response = await _http.put(_appointmentUrl,
headers: _headers, body: json.encode(appointment.toJson()));
return Appointment.fromJson(
_extractData(response as Response) as Map<String, dynamic>);
// Add security Header
final Response response = await _http.put(_appointmentUrl,
headers: _headers, body: json.encode(appointment.toJson())) as Response;
return Appointment.fromJson(
_extractData(response as Response) as Map<String, dynamic>);
}
///Löscht den Termin mit gegebener id
Future<void> delete(int id) async {
try {
final url = '$_appointmentUrl/$id';
await _http.delete(url, headers: _headers);
} catch (e) {
throw _handleError(e);
}
// Add security Header
final url = '$_appointmentUrl/$id';
await _http.delete(url, headers: _headers);
}
Future<Appointment> get(int id) async {
final Response response =
await _http.get('$_appointmentUrl/$id') as Response;
await _http.get('$_appointmentUrl/$id',headers: _headers) as Response;
return Appointment.fromJson(_extractData(response) as Map<String, dynamic>);
}
Future<List<Appointment>> getByDate(int year, int month, [int day]) async {
final Response response = (day != null)
? await _http.get('$_appointmentUrl/lookup/$year/$month/$day')
? await _http.get('$_appointmentUrl/lookup/$year/$month/$day',headers: _headers)
as Response
: await _http.get('$_appointmentUrl/lookup/$year/$month') as Response;
: await _http.get('$_appointmentUrl/lookup/$year/$month',headers: _headers) as Response;
return (_extractData(response) as List)
.map((value) => Appointment.fromJson(value as Map<String, dynamic>))
.toList();
}
Future<List<Appointment>> getAll() async {
final Response response = await _http.get('$_appointmentUrl') as Response;
return (_extractData(response) as List)
.map((value) => Appointment.fromJson(value as Map<String, dynamic>))
.toList();
final Response response =
await _http.get("$_appointmentUrl", headers: _headers) as Response;
print(response.statusCode.toString());
return (_extractData(response) as List)
.map((value) => Appointment.fromJson(value as Map<String, dynamic>))
.toList();
}
///Gibt den Termin mit der gegebenen id zurück
......@@ -78,7 +85,7 @@ class AppointmentService {
Future<List<Appointment>> search(String term) async {
try {
final response = await _http.get('$_appointmentUrl');
final response = await _http.get('$_appointmentUrl',headers: _headers);
final List<Appointment> appointments =
(_extractData(response as Response) as List)
.map((json) => Appointment.fromJson(json as Map<String, dynamic>))
......
import 'dart:async';
import 'dart:convert';
import 'dart:html';
import 'package:demo/src/model/person.dart';
import 'package:demo/src/view/main_component.dart';
import 'package:http/http.dart';
......@@ -9,7 +10,13 @@ class ContactService {
// request to middlemand
ContactService(this._http);
static final _headers = {'Content-Type': 'application/json'};
// getter for the Authorization
Map<String, String> get _headers => Map.fromEntries(
[MapEntry("Authorization", "$_tokenType $_tokenAuth"), _type]);
String get _tokenType => window.localStorage["token_type"];
String get _tokenAuth => window.localStorage["access_token"];
static const _type = MapEntry('Content-Type', 'application/json');
static const _userUrl = host + '/user'; // URL to web API
static const _contactUrl = host + '/contacts'; // URL to web API
final Client _http;
......@@ -27,7 +34,7 @@ class ContactService {
final url = '$_contactUrl/${contact.contactCode}';
final response =
await _http.put(url, headers: _headers, body: json.encode(contact));
return Contact.fromJson(_extractData(response) as Map<String, dynamic>);
return Contact.fromJson(_extractData(response as Response) as Map<String, dynamic>);
} catch (e) {
throw _handleError(e);
}
......@@ -35,7 +42,7 @@ class ContactService {
///gibt eine Liste von allen Terminen zurück
Future<List<Contact>> getAll() async {
final Response response = await _http.get('$_contactUrl');
final Response response = (await _http.get('$_contactUrl')) as Response;
return (_extractData(response) as List)
.map((value) => Contact.fromJson(value as Map<String, dynamic>))
.toList();
......@@ -43,7 +50,7 @@ class ContactService {
///Gibt den Termin mit der gegebenen id zurück
Future<Contact> get(String contactCode) async {
final Response response = await _http.get('$_contactUrl/$contactCode');
final Response response = (await _http.get('$_contactUrl/$contactCode')) as Response;
return Contact.fromJson(_extractData(response) as Map<String, dynamic>);
}
......@@ -52,12 +59,13 @@ class ContactService {
try {
final response = await _http.post(_contactUrl,
headers: _headers, body: json.encode(contact));
return Contact.fromJson(_extractData(response) as Map<String, dynamic>);
return Contact.fromJson(_extractData(response as Response) as Map<String, dynamic>);
} catch (e) {
throw _handleError(e);
}
}
Future<void> delete(String contactCode) async {
try {
final url = '$_contactUrl/$contactCode';
......@@ -69,24 +77,22 @@ class ContactService {
///Erstellt einen Kontakt und gibt ihn zurück
Future<Contact> find(String contactCode) async {
Contact contact;
final Response response = await _http.get('$_userUrl/$contactCode');
if (response.statusCode.toString() == "404") {
return contact;
}
final User user = User.fromJson(_extractData(response) as Map<String, dynamic>);
return Contact(user.id, user.nickname, user.surname, user.name, user.email, user.contactCode, "");
final Response response = (await _http.get('$_userUrl/$contactCode')) as Response;
final User user =
User.fromJson(_extractData(response) as Map<String, dynamic>);
return Contact(user.id, user.username, user.surname, user.name, user.email,
user.contactCode, "");
}
Future<List<Contact>> search(String term) async {
try {
final response = await _http.get('$_contactUrl');
final List<Contact> contacts =
(_extractData(response) as List)
(_extractData(response as Response) as List)
.map((json) => Contact.fromJson(json as Map<String, dynamic>))
.toList();
contacts.retainWhere(
(h) => h.nickname.toLowerCase().contains(term.toLowerCase()));
(h) => h.username.toLowerCase().contains(term.toLowerCase()));
return contacts;
} catch (e) {
throw _handleError(e);
......
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