Commit e6c3d026 authored by Marius Mauritz's avatar Marius Mauritz
Browse files

appointment typefix

parent a41fd1d2
Pipeline #6276 passed with stage
in 3 minutes and 30 seconds
......@@ -31,7 +31,7 @@ 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 USER cal_user WITH createdb;
ALTER USER cal_user WITH password 'password';
......
......@@ -21,7 +21,15 @@ class RegisterComponent implements OnInit, OnActivate {
final Router _router;
final UserService _registerService;
User user = User.zero();
User user = User.fromJson({
'id': null,
'contactCode': null,
'username': "username",
'surname': "surname",
'name': "name",
'email': "email@mail.de",
'password': "mockAdmin1"
});
Future<void> register() async {
......
......@@ -18,4 +18,3 @@ dependencies:
build_web_compilers: ^1.0.0
pedantic: ^1.0.0
analyzer: ^0.34.3
test: ^1.0.0
\ No newline at end of file
import 'package:test/test.dart';
import 'package:demo/src/model/day.dart';
import 'package:demo/src/model/month.dart';
import 'package:demo/src/model/appointment.dart';
import 'package:demo/src/model/person.dart';
void main() {
Day day;
Day day2;
///Tests for day.dart
test("Day.isValid(), checks for a valid day", () {
day = Day(2010, 11, 11);
expect(day.isValid(), true);
});
test("Day.toString(), Gives The weekday + DD/MM//YYYY", () {
day = Day(DateTime.now().year, DateTime.now().month, DateTime.now().day);
expect(
day.toString(),
day.weekday() +
": " +
DateTime.now().month.toString() +
"/" +
DateTime.now().day.toString() +
"/" +
DateTime.now().year.toString());
});
test("Day.weekday(), Gives The weekday As String", () {
day = Day(DateTime.now().year, DateTime.now().month, DateTime.now().day);
day2 = Day(day.year, day.month, day.day + 7);
if (day.day != day2.day) {
expect(day.weekday(), day2.weekday());
} else
return false;
});
///Tests for month.dart
Month month;
test("Month.prevM() und Month.nextM(), Gives the previous and next month",
() {
month = Month(2019, 6);
expect(month.prevM()[1], 5);
expect(month.nextM()[1], 7);
});
///Tests for appointment.dart
Appointment appo =
Appointment(1, "Abifaier", 2019, 6, 4, "2", "4", "Lübeck", "hi");
Appointment json = Appointment.zero();
test("Appointment appointment.fromJson", () {
expect(appo.equals(Appointment.fromJson(appo.toJson())), true);
});
///Tests for person.dart
User user = User(1,'CC123', 'Hellbender', 'Schindler', 'Laurenz',
'Hallo@myWebmail.com', 'dasisteinschlechtesPasswort', '016331742');
Contact contact = Contact(2,'Xanta', 'Waage', 'Daniel',
'DanielHateinemail@mail.de', 'CC124', 'Ist ein feiner.');
test("User.toJson == user.FromJson", () {
expect(user.equals(User.fromJson(user.toJson())), true);
});
test("Contact.toJson == Contact.FromJson", () {
expect(contact.equals(Contact.fromJson(contact.toJson())), true);
});
}
database:
host: postgresql
port: 5432
username: dart
password: dart
databaseName: dart_test
\ No newline at end of file
host: $CAL_DB_HOST
port: $CAL_DB_PORT
username: $CAL_DB_USER
password: $CAL_DB_PASS
databaseName: $CAL_DB_NAME
\ No newline at end of file
host: localhost
port: 5432
username: cal_user
password: password
databaseName: calendar
\ No newline at end of file
host: $CAL_DB_HOST
port: $CAL_DB_PORT
username: $CAL_DB_USER
password: $CAL_DB_PASS
databaseName: $CAL_DB_NAME
\ No newline at end of file
......@@ -72,9 +72,12 @@ class CalenderChannel extends ApplicationChannel {
router
.route('/user/[:number]')
.link(() => UserController(context));
/*
router
.route('/contacts/[:number]')
.link(() => ContactController(context));
*/
return router;
}
}
......
import 'dart:async';
/*
import 'dart:async';
import 'package:aqueduct/aqueduct.dart';
import 'package:middleman/model/person.dart';
......@@ -60,3 +61,4 @@ class ContactController extends ResourceController {
return Response.ok(contactdelete);
}
}
*/
\ No newline at end of file
......@@ -13,18 +13,15 @@ class RegisterController extends ResourceController {
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) {
if (user.username == null || user.password == null ){
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return Response.badRequest(
body: {"error": "username and password required."});
}
user
..salt = AuthUtility.generateRandomSalt()
..hashedPassword = authServer.hashPassword(user.password, user.salt);
print("passiert#######################");
user.salt = AuthUtility.generateRandomSalt();
user.hashedPassword = authServer.hashPassword(user.password, user.salt);
return Response.ok(await Query(context, values: user).insert());
}
......
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,ManagedAuthResourceOwner<_User> {
@Serialize(input: true, output: false)
String password;
}
class Contact extends ManagedObject<_Contact> implements _Contact {}
class _User extends ResourceOwnerTableDefinition {
abstract class _Person {
@primaryKey
int id;
@Column(unique: true, nullable: true)
String contactCode;
@Column(unique: true)
String username;
@Column(unique: false)
String surname;
@Column(unique: false)
String name;
@Column(unique: true)
String email;
}
class _Contact extends _Person{
@Column(unique: false,nullable: true)
String note;
}
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;
......
......@@ -128,3 +128,140 @@
}));
}
__
@override
Future seed() async {
final _appointments = [
{
"id": 1,
"name": "eins",
"year": 2019,
"month": 7,
"day": 22,
"time": "12:00",
"duration": "04:00",
"location": "Technischehochschule Lübeck",
"note": ""
},
{
"id": 2,
"name": "zwei",
"year": 2019,
"month": 5,
"day": 22,
"time": "12:00",
"duration": "04:00",
"location": "Technischehochschule Lübeck",
"note": ""
},
{
"id": 3,
"name": "drei",
"year": 2019,
"month": 5,
"day": 24,
"time": "12:00",
"duration": "04:00",
"location": "Technischehochschule Lübeck",
"note": ""
},
{
"id": 4,
"name": "vier",
"year": 2019,
"month": 5,
"day": 21,
"time": "12:00",
"duration": "04:00",
"location": "Technischehochschule Lübeck",
"note": ""
},
{
"id": 5,
"name": "fünf",
"year": 2019,
"month": 7,
"day": 22,
"time": "12:00",
"duration": "04:00",
"location": "Technischehochschule Lübeck",
"note": ""
},
];
final _contacts = [
{
"username": "marius",
"surname": "Marius",
"name": "Mauritz",
"email": "hallo@hallo.gmx.de",
"contactCode": "ContactCode1",
"note": "Datenbank experte"
},
{
"username": "lauri",
"surname": "Laurenz",
"name": "Schindler",
"email": "hello@world.gmx.de",
"contactCode": "ContactCode2",
"note": "voll der pro"
}
];
final _users = [
{
"password": "dude2",
"salt": "salt",
"username": "dude2",
"surname": "drei",
"name": "vier",
"email": "hello@hello.gmx.de",
"contactCode": "12345",
"hashedPassword": "Calendar123",
"mobileNo": ""
}];
_appointments.forEach((Map<String, dynamic> map) async =>
await database.store.execute(
"INSERT INTO _Appointment (name,time,year,month,day,duration,location,note) VALUES (@name,@time,@year,@month,@day,@duration,@location,@note)",
substitutionValues: {
"name": map['name'],
"time": map['time'],
"year": map['year'],
"month": map['month'],
"day": map['day'],
"duration": map['duration'],
"location": map['location'],
"note": map['note']
}));
_contacts.forEach((Map<String, String> map) async =>
await database.store.execute(
"INSERT INTO _Contact (username,surname,name,email,contactCode,note) VALUES (@username,@surname,@name,@email,@contactCode,@note)",
substitutionValues: {
"username": map['username'],
"surname": map['surname'],
"name": map['name'],
"email": map['email'],
"contactCode": map['contactCode'],
"note": map['note']
}));
_users.forEach((Map<String, String> map) async =>
await database.store.execute(
"INSERT INTO _User (username,surname,name,email,contactCode,hashedPassword,mobileNo,salt) VALUES (@username,@surname,@name,@email,@contactCode,@hashedPassword,@mobileNo,@salt)",
substitutionValues: {
"username": map['username'],
"surname": map['surname'],
"name": map['name'],
"email": map['email'],
"contactCode": map['contactCode'],
"hashedPassword": map['hashedPassword'],
"mobileNo": map['mobileNo'],
"salt": map['salt'],
"password": map['password'],
}));
}
......@@ -9,6 +9,3 @@ environment:
dependencies:
aqueduct: ^3.0.0
dev_dependencies:
test: ^1.0.0
aqueduct_test: ^1.0.0
import 'harness/app.dart';
main() async {
final harness = Harness()..install();
test("GET /heroes returns 200 {'key': 'value'}", () async {
expectResponse(await harness.agent.get("/heroes"), 200, body: {"key": "value"});
});
/*
test("Day.isValid(), checks for a valid day", () {
day = Day(2010,11,11);
expect(day.isValid(), true);
});
*/
}
import 'package:middleman/middleman.dart';
import 'package:aqueduct_test/aqueduct_test.dart';
import 'package:test_api/test_api.dart';
export 'package:aqueduct_test/aqueduct_test.dart';
export 'package:test/test.dart';
export 'package:aqueduct/aqueduct.dart';
class Harness extends TestHarness<CalenderChannel> with TestHarnessORMMixin {
@override
ManagedContext get context => channel.context;
final harness = Harness()
..install();
void main() {
test("GET/heroes returns200 {'key': 'value'}", () async {
expectResponse(await harness.agent.get("/heroes"), 200, body: {"key": "value"});
});
}}
\ No newline at end of file
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