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, ...@@ -31,13 +31,17 @@ SQL zum erstellen einer Datenbank,
// entfernt alle aktuellen verbindungen zur db // entfernt alle aktuellen verbindungen zur db
select pg_terminate_backend(pid) from pg_stat_activity where datname='calendar'; select pg_terminate_backend(pid) from pg_stat_activity where datname='calendar';
// löscht die Database // löscht die Database
DROP DATABASE calendar DROP DATABASE calendar;
---------------------------------------------- ----------------------------------------------
CREATE DATABASE calendar;
CREATE USER cal_user WITH createdb; CREATE USER cal_user WITH createdb;
ALTER USER cal_user WITH password 'password'; ALTER USER cal_user WITH password 'password';
CREATE DATABASE calendar;
GRANT all ON database calendar TO cal_user; GRANT all ON database calendar TO cal_user;
---------------------------------------------- ----------------------------------------------
aqueduct auth add-client --id com.calendar.app
// dockercompose // dockercompose
......
...@@ -5,7 +5,7 @@ COPY frontend/pubspec.yaml /root/build-here/ ...@@ -5,7 +5,7 @@ COPY frontend/pubspec.yaml /root/build-here/
RUN pub get RUN pub get
COPY frontend/ /root/build-here/ COPY frontend/ /root/build-here/
RUN pub get RUN pub get
RUN pub run build_runner build --output web:build RUN pub run build_runner build --output web:build --release
FROM nginx FROM nginx
EXPOSE 80 EXPOSE 80
RUN sed -i -e 's, location / {, location /calendar {,g' /etc/nginx/conf.d/default.conf; \ RUN sed -i -e 's, location / {, location /calendar {,g' /etc/nginx/conf.d/default.conf; \
......
...@@ -10,4 +10,4 @@ targets: ...@@ -10,4 +10,4 @@ targets:
compiler: dart2js compiler: dart2js
dart2js_args: dart2js_args:
- --minify - --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 { ...@@ -17,6 +17,7 @@ class Appointment {
appointment['location'] as String, appointment['location'] as String,
appointment['note'] as String); appointment['note'] as String);
List<String> contactCodes = [];
int id; int id;
String name; String name;
int year; int year;
...@@ -27,8 +28,8 @@ class Appointment { ...@@ -27,8 +28,8 @@ class Appointment {
String location = ""; String location = "";
String note = ""; String note = "";
Map<String,dynamic> toJson() => { Map<String, dynamic> toJson() => {
'id' :id, 'id': id,
'name': name, 'name': name,
'year': year, 'year': year,
'month': month, 'month': month,
......
abstract class Person { 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); this.email);
Person.zero(); Person.zero();
int id; int id;
String nickname; String username;
String surname; String surname;
String name; String name;
String email; String email;
...@@ -12,7 +12,7 @@ abstract class Person { ...@@ -12,7 +12,7 @@ abstract class Person {
bool equals(Person person) { bool equals(Person person) {
return this.email == person.email && return this.email == person.email &&
this.nickname == person.nickname && this.username == person.username &&
this.name == person.name && this.name == person.name &&
this.surname == person.surname && this.surname == person.surname &&
this.contactCode == person.contactCode && this.contactCode == person.contactCode &&
...@@ -20,19 +20,22 @@ abstract class Person { ...@@ -20,19 +20,22 @@ abstract class Person {
} }
} }
/// Hier ist der User
class User extends Person { 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) String email, String password, String mobileNo)
: password = password, : password = password,
mobileNo = mobileNo, mobileNo = mobileNo,
super(id, contactCode, nickname, surname, name, email); super(id, contactCode, username, surname, name, email);
User.zero() : super.zero(); User.zero() : super.zero();
factory User.fromJson(Map<String, dynamic> user) => User( factory User.fromJson(Map<String, dynamic> user) => User(
user['id'] as int, user['id'] as int,
user['contactCode'] as String, user['contactCode'] as String,
user['nickname'] as String, user['username'] as String,
user['surname'] as String, user['surname'] as String,
user['name'] as String, user['name'] as String,
user['email'] as String, user['email'] as String,
...@@ -46,26 +49,10 @@ class User extends Person { ...@@ -46,26 +49,10 @@ class User extends Person {
String password; String password;
String mobileNo; 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() => { Map<String, dynamic> toJson() => {
'id': id,
'contactCode': contactCode, 'contactCode': contactCode,
'nickname': nickname, 'username': username,
'surname': surname, 'surname': surname,
'name': name, 'name': name,
'email': email, 'email': email,
...@@ -76,18 +63,18 @@ class User extends Person { ...@@ -76,18 +63,18 @@ class User extends Person {
Map<String, Contact> getMyContacts() {} Map<String, Contact> getMyContacts() {}
} }
int _toInt(id) => id is int ? id : int.parse(id as String);
/// Hier ist der Kontakt
class Contact extends Person { 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) String contactCode, String note)
: super(id, contactCode, nickname, surname, name, email) { : super(id, contactCode, username, surname, name, email) {
this.note = note; this.note = note;
} }
factory Contact.fromJson(Map<String, dynamic> contact) => Contact( factory Contact.fromJson(Map<String, dynamic> contact) => Contact(
contact['id'] as int, contact['id'] as int,
contact['nickname'] as String, contact['username'] as String,
contact['surname'] as String, contact['surname'] as String,
contact['name'] as String, contact['name'] as String,
contact['email'] as String, contact['email'] as String,
...@@ -98,7 +85,7 @@ class Contact extends Person { ...@@ -98,7 +85,7 @@ class Contact extends Person {
Map<String, dynamic> toJson() => { Map<String, dynamic> toJson() => {
'id': id, 'id': id,
'nickname': nickname, 'username': username,
'surname': surname, 'surname': surname,
'name': name, 'name': name,
'email': email, 'email': email,
......
...@@ -15,11 +15,11 @@ td:hover{ ...@@ -15,11 +15,11 @@ td:hover{
} }
h4{ h4{
text-align: center; text-align: center;
cursor: hand; cursor: pointer;
} }
table tr { table tr {
height: 5em; height: 10vh;
} }
table{ table{
......
...@@ -37,6 +37,6 @@ ...@@ -37,6 +37,6 @@
</tr> </tr>
</table> </table>
<h4 (click)="next()">Next -&gt;&gt;</h4> <h4 (click)="next()">Next &#8594;</h4>
<h4 (click)="previous()">&lt;&lt;- Previous</h4> <h4 (click)="previous()">&#8592; Previous</h4>
</div> </div>
\ No newline at end of file
<div *ngIf="contact != null"> <div *ngIf="contact != null">
<h3>{{contact.nickname}}</h3> <h3>{{contact.username}}</h3>
<table> <table>
<tr> <tr>
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
<td><b>Delete</b></td> <td><b>Delete</b></td>
</tr> </tr>
<tr *ngFor="let contact of contacts" id="contact"> <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.surname}}</td>
<td (click)="gotoDetail(contact)">{{contact.name}}</td> <td (click)="gotoDetail(contact)">{{contact.name}}</td>
<td (click)="gotoDetail(contact)">{{contact.email}}</td> <td (click)="gotoDetail(contact)">{{contact.email}}</td>
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<div> <div>
<div *ngFor="let contact of contacts | async" <div *ngFor="let contact of contacts | async"
(click)="contact.delete()" class="search-result" > (click)="contact.delete()" class="search-result" >
{{contact.nickname}} {{contact.username}}
</div> </div>
</div> </div>
</div> </div>
...@@ -27,7 +27,7 @@ class DashboardComponent implements OnInit, OnActivate { ...@@ -27,7 +27,7 @@ class DashboardComponent implements OnInit, OnActivate {
@override @override
void onActivate(RouterState previous, RouterState current) async { void onActivate(RouterState previous, RouterState current) async {
if (!LoginComponent.loggedIn) { if (!LoginComponent.loggedIn) {
_router.navigate('/login'); await _router.navigate('/login');
} }
else{ else{
joke = await _dashboardService.getJoke(); joke = await _dashboardService.getJoke();
......
...@@ -28,7 +28,7 @@ class DayviewComponent implements OnActivate { ...@@ -28,7 +28,7 @@ class DayviewComponent implements OnActivate {
@override @override
void onActivate(_, RouterState current) async { void onActivate(_, RouterState current) async {
if (!LoginComponent.loggedIn) { if (!LoginComponent.loggedIn) {
_router.navigate('/login'); await _router.navigate('/login');
} else { } else {
this.day = Day( this.day = Day(
getYear(current.parameters), getYear(current.parameters),
......
...@@ -2,6 +2,7 @@ import 'package:angular/angular.dart'; ...@@ -2,6 +2,7 @@ import 'package:angular/angular.dart';
import 'package:angular_forms/angular_forms.dart'; import 'package:angular_forms/angular_forms.dart';
import 'package:angular_router/angular_router.dart'; import 'package:angular_router/angular_router.dart';
import 'package:demo/src/view/services/person_service.dart'; import 'package:demo/src/view/services/person_service.dart';
import 'package:demo/src/view/services/register_service.dart';
import '../../model/person.dart'; import '../../model/person.dart';
import '../main_component.dart'; import '../main_component.dart';
...@@ -12,42 +13,28 @@ import '../main_component.dart'; ...@@ -12,42 +13,28 @@ import '../main_component.dart';
styleUrls: ['login_component.css'], styleUrls: ['login_component.css'],
directives: [coreDirectives, routerDirectives, formDirectives], directives: [coreDirectives, routerDirectives, formDirectives],
) )
class LoginComponent implements OnInit, OnActivate { class LoginComponent implements OnInit, OnActivate {
LoginComponent(this._router, this._userService, this._registerService);
LoginComponent(this._router, this._userService);
final UserService _userService; final UserService _userService;
final RegisterService _registerService;
final Router _router; final Router _router;
bool loginFailure = false; bool loginFailure = false;
static bool loggedIn = false; static bool loggedIn = false;
String nickname; String username;
String password; String password;
List<User> users; List<User> users;
//User user; //User user;
// //
Future<void> login() async { Future<void> login() async {
users = await _userService.getAll(); await _registerService.login(username, password);
for (User u in users) { loggedIn = true;
if ((nickname == u.nickname || nickname == u.email) && password ==u.password) { AppComponent.showButtons = true;
loggedIn = true; await _router.navigate('/dashboard');
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);
}*/
} }
// Weiterleitung zum Registrierungsformular // Weiterleitung zum Registrierungsformular
...@@ -77,4 +64,4 @@ class LoginComponent implements OnInit, OnActivate { ...@@ -77,4 +64,4 @@ class LoginComponent implements OnInit, OnActivate {
_router.navigate('/calendar'); _router.navigate('/calendar');
} }
} }
} }
\ No newline at end of file
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
<h3>Login</h3> <h3>Login</h3>
<form class="form"> <form class="form">
<div class="form-group"> <div class="form-group">
<label for="nickname">Nickname/Email&nbsp;</label> <label for="username">Username/Email&nbsp;</label>
<input type="text" class="form-control" id="nickname" placeholder="Nickname" <input type="text" class="form-control" id="username" placeholder="Username"
[(ngModel)]="nickname" [(ngModel)]="username"
ngControl="nickname"> ngControl="username">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="password">Password&nbsp;</label> <label for="password">Password&nbsp;</label>
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
[(ngModel)]="password" [(ngModel)]="password"
ngControl="password"> ngControl="password">
<div [hidden]="!loginFailure" class="loginFailure"> <div [hidden]="!loginFailure" class="loginFailure">
Nickname/Email oder Passwort falsch Username/Email oder Passwort falsch
</div> </div>
</div> </div>
<button type="submit" class="btn btn-success" (click)="login()">Login</button> <button type="submit" class="btn btn-success" (click)="login()">Login</button>
......
...@@ -20,7 +20,7 @@ class RegisterComponent implements OnInit, OnActivate { ...@@ -20,7 +20,7 @@ class RegisterComponent implements OnInit, OnActivate {
final Router _router; final Router _router;
final UserService _registerService; final UserService _registerService;
User user = User.zero(); User user = User.zero();
String passwordWh = ""; String passwordWh ="";
Future<void> register() async { Future<void> register() async {
...@@ -45,8 +45,4 @@ class RegisterComponent implements OnInit, OnActivate { ...@@ -45,8 +45,4 @@ class RegisterComponent implements OnInit, OnActivate {
_router.navigate('/calendar'); _router.navigate('/calendar');
} }
} }
} }
\ No newline at end of file
...@@ -2,13 +2,13 @@ ...@@ -2,13 +2,13 @@
<h3>Register</h3> <h3>Register</h3>
<form #registerForm="ngForm"> <form #registerForm="ngForm">
<div class="form-group"> <div class="form-group">
<label for="nickname">Nickname&nbsp;*</label> <label for="username">Username&nbsp;*</label>
<input type="text" class="form-control" id="nickname" required placeholder="Nickname" <input type="text" class="form-control" id="username" required placeholder="Username"
#nickname="ngForm" #username="ngForm"
[class.is-valid]="nickname.valid" [class.is-valid]="username.valid"
[class.is-invalid]="!nickname.valid" [class.is-invalid]="!username.valid"
[(ngModel)]="user.nickname" [(ngModel)]="user.username"
ngControl="nickname"> ngControl="username">
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="surname">Surname&nbsp;*</label> <label for="surname">Surname&nbsp;*</label>
......
...@@ -10,6 +10,7 @@ import 'package:demo/src/view/services/appointment_service.dart'; ...@@ -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/contact_service.dart';
import 'package:demo/src/view/services/dashboard_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/person_service.dart';
import 'package:demo/src/view/services/register_service.dart';
import 'components/login_component.dart'; import 'components/login_component.dart';
...@@ -23,6 +24,7 @@ import 'components/login_component.dart'; ...@@ -23,6 +24,7 @@ import 'components/login_component.dart';
ClassProvider(UserService), ClassProvider(UserService),
ClassProvider(ContactService), ClassProvider(ContactService),
ClassProvider(DashboardService), ClassProvider(DashboardService),
ClassProvider(RegisterService),
], ],
exports: [RoutePaths, Routes], exports: [RoutePaths, Routes],
) )
......
...@@ -55,6 +55,7 @@ class Routes { ...@@ -55,6 +55,7 @@ class Routes {
static final RouteDefinition login = RouteDefinition( static final RouteDefinition login = RouteDefinition(
routePath: RoutePaths.login, routePath: RoutePaths.login,
component: login_template.LoginComponentNgFactory as ComponentFactory, component: login_template.LoginComponentNgFactory as ComponentFactory,
useAsDefault: true,
); );
static final RouteDefinition contacts = RouteDefinition( static final RouteDefinition contacts = RouteDefinition(
routePath: RoutePaths.contacts, routePath: RoutePaths.contacts,
...@@ -79,7 +80,7 @@ class Routes { ...@@ -79,7 +80,7 @@ class Routes {
login, login,
RouteDefinition.redirect( RouteDefinition.redirect(
path: '', path: '',
redirectTo: RoutePaths.dashboard.toUrl(), redirectTo: RoutePaths.login.toUrl(),
), ),
]; ];
} }
...@@ -12,10 +12,17 @@ class AppointmentService { ...@@ -12,10 +12,17 @@ class AppointmentService {
// request to middlemand // request to middlemand
AppointmentService(this._http); AppointmentService(this._http);
static final _headers = {'Content-Type': 'application/json'};
static const _appointmentUrl = host + '/appointments'; // URL to web API static const _appointmentUrl = host + '/appointments'; // URL to web API
final Client _http; 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 ///Liest die Daten aus einer Response
dynamic _extractData(Response resp) => json.decode(resp.body); dynamic _extractData(Response resp) => json.decode(resp.body);
...@@ -27,43 +34,43 @@ class AppointmentService { ...@@ -27,43 +34,43 @@ class AppointmentService {
///Updatet einen bereits existierenden Termin ///Updatet einen bereits existierenden Termin
///Erstellt einen neuen Termin mit gegebenen Namen ///Erstellt einen neuen Termin mit gegebenen Namen
Future<Appointment> update(Appointment appointment) async { Future<Appointment> update(Appointment appointment) async {
final response = await _http.put(_appointmentUrl, // Add security Header