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

Branch please

parent 3bb92743
Pipeline #6269 passed with stage
in 5 minutes and 30 seconds
......@@ -33,9 +33,9 @@ select pg_terminate_backend(pid) from pg_stat_activity where datname='calendar';
// löscht die Database
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;
----------------------------------------------
// 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
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,11 @@ 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 +64,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 +86,7 @@ class Contact extends Person {
Map<String, dynamic> toJson() => {
'id': id,
'nickname': nickname,
'username': username,
'surname': surname,
'name': name,
'email': email,
......
......@@ -15,7 +15,7 @@ h4{
}
table tr {
height: 5em;
height: 7vw;
}
table{
......
<div *ngIf="contact != null">
<h3>{{contact.nickname}}</h3>
<h3>{{contact.username}}</h3>
<table>
<tr>
......
......@@ -25,7 +25,7 @@ class LoginComponent implements OnInit, OnActivate {
bool loginFailure = false;
static bool loggedIn = false;
String nickname;
String username;
String password;
List<User> users;
//User user;
......@@ -34,7 +34,7 @@ class LoginComponent implements OnInit, OnActivate {
Future<void> login() async {
users = await _userService.getAll();
for (User u in users) {
if ((nickname == u.nickname || nickname == u.email) && password ==u.password) {
if ((username == u.username || username == u.email) && password ==u.password) {
loggedIn = true;
AppComponent.showButtons = true;
await _router.navigate('/dashboard');
......@@ -44,10 +44,10 @@ class LoginComponent implements OnInit, OnActivate {
}
}
/*
if (nickname.contains("@")) {
user = await _userService.getLoginEmail(password, nickname);
if (username.contains("@")) {
user = await _userService.getLoginEmail(password, username);
} else {
user = await _userService.getLoginNickname(password, nickname);
user = await _userService.getLoginNickname(password, username);
}*/
}
......
......@@ -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>
......
......@@ -4,6 +4,7 @@ import 'package:angular_router/angular_router.dart';
import 'package:demo/src/view/components/login_component.dart';
import 'package:demo/src/view/components/mock_users.dart';
import 'package:demo/src/view/services/person_service.dart';
import 'package:demo/src/view/services/register_service.dart';
import '../../model/person.dart';
......
......@@ -2,13 +2,13 @@
<h3>Register</h3>
<form>
<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>
......
......@@ -71,6 +71,6 @@ class ContactService {
Future<Contact> find(String contactCode) async {
final Response response = await _http.get('$_userUrl/$contactCode');
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, "");
return Contact(user.id, user.username, user.surname,user.name, user.email, user.contactCode, "");
}
}
......@@ -49,7 +49,7 @@ class UserService {
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}
Future<User> getLoginNickname(String password, String nickname) async {
Future<User> getLoginNickname(String password, String username) async {
final Response response = await _http.get('$_userUrl/$password/$nickname');
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}*/
......
import 'dart:async';
import 'dart:convert';
import 'package:demo/src/view/main_component.dart';
import 'package:http/http.dart';
import 'package:demo/src/model/person.dart';
class RegisterService {
// request to middlemand
RegisterService(this._http);
static final _headers = {'Content-Type': 'application/json'};
static const _userUrl = host+'/register'; // URL to web API
final Client _http;
///Liest die Daten aus einer Response
dynamic _extractData(Response resp) => json.decode(resp.body);
Exception _handleError(dynamic e) {
print(e); // for demo purposes only
return Exception('Server error; cause: $e');
}
///Erstellt einen neuen User mit gegebenem Namen, Email und Passwort
Future<User> create(User user) async {
try {
final response = await _http.post(_userUrl,
headers: _headers, body: json.encode(user.toJson()));
return User.fromJson(
_extractData(response) as Map<String, dynamic>);
} catch (e) {
throw _handleError(e);
}
}
}
import 'package:aqueduct/managed_auth.dart';
import 'package:middleman/controller/appointment_controller.dart';
import 'package:middleman/controller/contact_controller.dart';
import 'package:middleman/controller/register_controller.dart';
import 'package:middleman/controller/user_controller.dart';
import 'package:middleman/model/person.dart';
import 'middleman.dart';
......@@ -10,6 +13,7 @@ import 'middleman.dart';
/// database connections. See http://aqueduct.io/docs/http/channel/.
class CalenderChannel extends ApplicationChannel {
ManagedContext context;
AuthServer authServer;
/// Initialize services in this method.
///
......@@ -19,6 +23,8 @@ class CalenderChannel extends ApplicationChannel {
/// This method is invoked prior to [entryPoint] being accessed.
@override
Future prepare() async {
logger.onRecord.listen(
(rec) => print("$rec ${rec.error ?? ""} ${rec.stackTrace ?? ""}"));
......@@ -32,6 +38,10 @@ class CalenderChannel extends ApplicationChannel {
config.database.databaseName);
context = ManagedContext(dataModel, persistentStore);
// AuthStorage
final authStorage = ManagedAuthDelegate<User>(context);
authServer = AuthServer(authStorage);
}
/// Construct the request channel.
......@@ -43,6 +53,15 @@ class CalenderChannel extends ApplicationChannel {
@override
Controller get entryPoint {
final router = Router();
// registerStuff
router
.route('/register')
.link(() => RegisterController(context, authServer));
// add this route
router
.route('/auth/token')
.link(() => AuthController(authServer));
router
.route('/appointments/[:id]')
......
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';
import 'package:middleman/model/person.dart';
class RegisterController extends ResourceController {
RegisterController(this.context, this.authServer);
final ManagedContext context;
final AuthServer authServer;
@Operation.post()
Future<Response> createUser(@Bind.body() User user) async {
print(user.toString());
// Check for required parameters before we spend time hashing
if (user.username == null ||
user.password == null ||
user.email == null ||
user.surname == null ||
user.name == null) {
return Response.badRequest(
body: {"error": "username and password required."});
}
user
..salt = AuthUtility.generateRandomSalt()
..hashedPassword = authServer.hashPassword(user.password, user.salt);
return Response.ok(await Query(context, values: user).insert());
}
}
......@@ -37,12 +37,12 @@ class UserController extends ResourceController {
return Response.ok(user);
}
@Operation.get('password', 'nickname')
@Operation.get('password', 'username')
Future<Response> getUserLoginNickname(@Bind.path('password') String password,
@Bind.path('nickname') String nickname) async {
@Bind.path('username') String username) async {
final userQuery = Query<User>(context)
..where((user) => user.password).equalTo(password)
..where((user) => user.nickname).equalTo(nickname);
..where((user) => user.hashedPassword).equalTo(password)
..where((user) => user.username).equalTo(username);
final user = await userQuery.fetchOne();
if (user == null) {
return Response.notFound();
......@@ -54,7 +54,7 @@ class UserController extends ResourceController {
Future<Response> getUserLoginEmail(@Bind.path('password') String password,
@Bind.path('email') String email) async {
final userQuery = Query<User>(context)
..where((user) => user.password).equalTo(password)
..where((user) => user.hashedPassword).equalTo(password)
..where((user) => user.email).equalTo(email);
final user = await userQuery.fetchOne();
if (user == null) {
......
import 'package:aqueduct/managed_auth.dart';
import 'package:middleman/middleman.dart';
class Person extends ManagedObject<_Person> implements _Person {}
class User extends ManagedObject<_User> implements _User {}
class User extends ManagedObject<_User> implements _User,ManagedAuthResourceOwner<_User> {
@Serialize(input: true, output: false)
String password;
}
class Contact extends ManagedObject<_Contact> implements _Contact {}
abstract class _Person {
abstract class _Person {
@primaryKey
int id;
......@@ -14,7 +18,7 @@ abstract class _Person {
String contactCode;
@Column(unique: true)
String nickname;
String username;
@Column(unique: false)
String surname;
......@@ -26,15 +30,35 @@ abstract class _Person {
String email;
}
class _Contact extends _Person {
class _Contact extends _Person{
@Column(unique: false,nullable: true)
String note;
}
class _User extends _Person {
@Column(unique: false)
String password;
class _User extends ResourceOwnerTableDefinition implements _Person {
@Column(omitByDefault: true)
String hashedPassword;
@Column(omitByDefault: true)
String salt;
ManagedSet<ManagedAuthToken> tokens;
@Column(unique: false, nullable: true)
String mobileNo;
@Column(unique: true, nullable: true)
String contactCode;
@Column(unique: false)
String surname;
@Column(unique: false)
String name;
@Column(unique: true)
String email;
}
......@@ -60,7 +60,7 @@
final _contacts = [
{
"nickname": "marius",
"username": "marius",
"surname": "Marius",
"name": "Mauritz",
"email": "hallo@hallo.gmx.de",
......@@ -68,7 +68,7 @@
"note": "Datenbank experte"
},
{
"nickname": "lauri",
"username": "lauri",
"surname": "Laurenz",
"name": "Schindler",
"email": "hello@world.gmx.de",
......@@ -79,7 +79,7 @@
final _users = [
{
"nickname": "dude2",
"username": "dude2",
"surname": "drei",
"name": "vier",
"email": "hello@hello.gmx.de",
......@@ -104,9 +104,9 @@
_contacts.forEach((Map<String, String> map) async =>
await database.store.execute(
"INSERT INTO _Contact (nickname,surname,name,email,contactCode,note) VALUES (@nickname,@surname,@name,@email,@contactCode,@note)",
"INSERT INTO _Contact (username,surname,name,email,contactCode,note) VALUES (@username,@surname,@name,@email,@contactCode,@note)",
substitutionValues: {
"nickname": map['nickname'],
"username": map['username'],
"surname": map['surname'],
"name": map['name'],
"email": map['email'],
......@@ -116,9 +116,9 @@
_users.forEach((Map<String, String> map) async =>
await database.store.execute(
"INSERT INTO _User (nickname,surname,name,email,contactCode,password,mobileNo) VALUES (@nickname,@surname,@name,@email,@contactCode,@password,@mobileNo)",
"INSERT INTO _User (username,surname,name,email,contactCode,password,mobileNo) VALUES (@username,@surname,@name,@email,@contactCode,@password,@mobileNo)",
substitutionValues: {
"nickname": map['nickname'],
"username": map['username'],
"surname": map['surname'],
"name": map['name'],
"email": map['email'],
......
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