Commit ddb07221 authored by Wosiek, Oliver's avatar Wosiek, Oliver
Browse files

AccountDetails bearbeiten (funktioniert im

frontend, middleman kann das noch nicht)
parent c696c02e
Pipeline #7646 passed with stage
in 4 minutes and 7 seconds
......@@ -8,6 +8,7 @@ import 'package:demo/src/view/routes/route_paths.dart';
import 'package:demo/src/view/services/person_service.dart';
import 'package:demo/src/view/components/login_component.dart';
import '../main_component.dart';
@Component(
......@@ -26,6 +27,14 @@ class AccountComponent implements OnActivate {
bool deleteControl = false;
final Router _router;
final UserService _userService;
bool editSurname = false;
bool editName = false;
bool editEmail = false;
bool editMobileNo = false;
bool editPassword = false;
bool deleteAccount = false;
String newPassword = "";
String passwordWh = "";
/// Folgender Code wird immer bei der Aktivierung der Klasse aufgerufen
@override
......@@ -33,30 +42,65 @@ class AccountComponent implements OnActivate {
if (!LoginComponent.loggedIn) {
await _router.navigate('/login');
} else {
final cc = getNumber(current.parameters);
print(current.parameters);
if (cc != null) {
user = await _userService.get(cc);
final id = 4;
if (id != null) {
user = await _userService.getById(id);
}
}
}
/// Methode zum speichern der Änderungen, die man am User vorgenommen hat
Future<void> save() async {
editSurname = false;
editName = false;
editEmail = false;
editMobileNo = false;
await _userService.update(user);
}
///Methode zum löschen von Terminen
/// Methode zum Speichern des neuen Passworts
Future<void> savePassword() async {
editPassword = false;
user.password = newPassword;
await _userService.update(user);
}
///Methode zum Löschen des Accounts
Future<void> delete() async {
if (deleteControl==true) {
await _userService.delete(user.username);
goBack();
await _userService.deleteUser(user.username);
LoginComponent.loggedIn = false;
AppComponent.showButtons = false;
await _router.navigate('/login');
} else {
deleteControl = true;
}
}
///Methode, die die übergeordnete Ansicht anzeigt
void goBack() => _location.back();
void surnameEdit() {
editSurname = true;
}
void nameEdit() {
editName = true;
}
void emailEdit() {
editEmail = true;
}
void mobileNoEdit() {
editMobileNo = true;
}
void passwordEdit() {
editPassword = true;
}
void accountDelete() {
deleteAccount = true;
}
}
\ No newline at end of file
<h3>Accountdetails</h3>
<div *ngIf="user != null">
<h3>{{user.username}}</h3>
<table class="table">
<tr>
<th>Username</th>
<td>{{user.username}}</td>
</tr>
<tr [hidden]="editSurname">
<th>Surname</th>
<td>{{user.surname}}</td>
<td><button (click)="surnameEdit()" class="btn">Edit</button></td>
</tr>
<tr [hidden]="!editSurname" id="editSurname">
<div class="form-group">
<label for="surname">Surname&nbsp;*</label>
<input type="text" class="form-control" id="surname" required
placeholder="Max"
[(ngModel)]="user.surname"
#name="ngForm">
</div>
<button type="button" class="btn btn-success" (click)="save()">Save</button>
</tr>
<tr [hidden]="editName">
<th>Name</th>
<td>{{user.name}}</td>
<td><button (click)="nameEdit()" class="btn">Edit</button></td>
</tr>
<tr [hidden]="!editName" id="editName">
<div class="form-group">
<label for="name">Name&nbsp;*</label>
<input type="text" class="form-control" id="name" required
placeholder="Mustermann"
[(ngModel)]="user.name"
#name="ngForm">
</div>
<button type="button" class="btn btn-success" (click)="save()">Save</button>
</tr>
<tr [hidden]="editEmail">
<th>Email</th>
<td>{{user.email}}</td>
<td><button (click)="emailEdit()" class="btn">Edit</button></td>
</tr>
<tr [hidden]="!editEmail" id="editEmail">
<div class="form-group">
<label for="email">Email&nbsp;*</label>
<input type="email" class="form-control" id="email" required
placeholder="max@mustermann.de"
[(ngModel)]="user.email"
#name="ngForm">
</div>
<button type="button" class="btn btn-success" (click)="save()">Save</button>
</tr>
<tr [hidden]="editMobileNo">
<th>Mobile Number</th>
<td>{{user.mobileNo}}</td>
<td><button (click)="mobileNoEdit()" class="btn">Edit</button></td>
</tr>
<tr [hidden]="!editMobileNo" id="editMobileNo">
<div class="form-group">
<label for="mobileNo">Mobile Number&nbsp;*</label>
<input type="text" class="form-control" id="mobileNo" required
placeholder="0152 123456"
[(ngModel)]="user.mobileNo"
#name="ngForm">
</div>
<button type="button" class="btn btn-success" (click)="save()">Save</button>
</tr>
<tr [hidden]="editPassword">
<th>Password</th>
<td></td>
<td><button (click)="passwordEdit()" class="btn">Edit</button></td>
</tr>
<tr [hidden]="!editPassword" id="editPassword">
<div class="form-group">
<label for="password">Current Password&nbsp;*</label>
<input type="password" class="form-control" id="password" required
[(ngModel)]="user.password"
#name="ngForm">
</div>
<div class="form-group">
<label for="newPassword">New Password&nbsp;*</label>
<input type="password" class="form-control" id="newPassword" required
pattern="(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{8,}"
[(ngModel)]="newPassword"
#name="ngForm">
</div>
<div class="form-group">
<label for="passwordWh">Repeat New Password&nbsp;*</label>
<input type="password" class="form-control" id="passwordWh" required
pattern="{{newPassword}}"
[(ngModel)]="passwordWh"
#name="ngForm">
</div>
<button type="button" class="btn btn-success" (click)="savePassword()">Save</button>
</tr>
<tr [hidden]="deleteAccount">
<th>Delete Account</th>
<td></td>
<td><button (click)="accountDelete()" class="btn">Edit</button></td>
</tr>
<tr [hidden]="!deleteAccount" id="deleteAccount">
<div class="form-group">
<label for="password">Password&nbsp;*</label>
<input type="password" class="form-control" id="passwordDelete" required
[(ngModel)]="user.password"
#name="ngForm">
</div>
<div class="form-group">
<label for="passwordWh">Repeat Password&nbsp;*</label>
<input type="password" class="form-control" id="passwordWhDelete" required
pattern="{{user.password}}"
[(ngModel)]="passwordWh"
#name="ngForm">
</div>
<button type="button" class="btn btn-danger" (click)="delete()">Delete</button>
<div [hidden]="!deleteControl" id="delete">
If you really want to delete your account click "Delete" again.
</div>
</tr>
</table>
<button (click)="goBack()" class="btn">GoBack</button>
</div>
\ No newline at end of file
......@@ -55,6 +55,13 @@ class UserService {
await _http.delete(url, headers: _headers);
}
///Löscht den User mit gegebenem contactCode
Future<void> deleteUser(String username) async {
// Add security Header
final url = '$_userUrl/look/$username';
await _http.delete(url, headers: _headers);
}
Future<List<User>> getAll() async {
final Response response = await _http.get('$_userUrl') as Response;
return (_extractData(response) as List)
......@@ -67,4 +74,16 @@ class UserService {
await _http.get('$_userUrl/$contactCode') as Response;
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}
Future<User> getById(int id) async {
final Response response =
await _http.get('$_userUrl/lookup/$id') as Response;
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}
Future<User> getByUsername(String username) async {
final Response response =
await _http.get('$_userUrl/look/$username') as Response;
return User.fromJson(_extractData(response) as Map<String, dynamic>);
}
}
......@@ -72,6 +72,12 @@ class CalenderChannel extends ApplicationChannel {
router
.route('/user/[:number]')
.link(() => UserController(context));
router
.route('/user/lookup/[:id]')
.link(() => UserController(context));
router
.route('/user/look/[:username]')
.link(() => UserController(context));
router
.route('/contacts/[:number]')
.link(() => ContactController(context));
......
......@@ -24,4 +24,15 @@ class RegisterController extends ResourceController {
user.hashedPassword = authServer.hashPassword(user.password, user.salt);
return Response.ok(await Query(context, values: user).insert());
}
@Operation.get('number')
Future<Response> getUserById(@Bind.path('number') String id) async {
final userQuery = Query<User>(context)
..where((con) => con.id).equalTo(id as int);
final user = await userQuery.fetchOne();
if (user == null) {
return Response.notFound();
}
return Response.ok(user);
}
}
......@@ -31,6 +31,28 @@ class UserController extends ResourceController {
return Response.ok(user);
}
@Operation.get('username')
Future<Response> getUserByUsername(@Bind.path('username') String username) async {
final userQuery = Query<User>(context)
..where((user) => user.username).equalTo(username);
final user = await userQuery.fetchOne();
if (user == null) {
return Response.notFound();
}
return Response.ok(user);
}
@Operation.get('id')
Future<Response> getUserID(@Bind.path('id') int id) async {
final userQuery = Query<User>(context)
..where((user) => user.id).equalTo(id);
final user = await userQuery.fetchOne();
if (user == null) {
return Response.notFound();
}
return Response.ok(user);
}
@Operation.post()
Future<Response> newUser() async {
final Map<String, dynamic> body = await request.body.decode();
......@@ -52,6 +74,17 @@ class UserController extends ResourceController {
return Response.ok(updatedUser);
}
@Operation.put()
Future<Response> updateUserNew(@Bind.body() User user) async {
final Map<String, dynamic> body = await request.body.decode();
print(body.toString());
final query = Query<User>(context)
..values.read(body,ignore: ["id"])
..where((user) => user.id).equalTo(body["id"] as int);
final updatedUser = await query.updateOne();
return Response.ok(updatedUser);
}
@Operation.delete("number")
Future<Response> deleteUser(@Bind.path('number') String con) async {
final query = Query<User>(context)
......@@ -59,4 +92,12 @@ class UserController extends ResourceController {
int userdelete = await query.delete();
return Response.ok(userdelete);
}
@Operation.delete("username")
Future<Response> deleteByUsername(@Bind.path('username') String username) async {
final query = Query<User>(context)
..where((app) => app.username).equalTo(username);
int userdelete = await query.delete();
return Response.ok(userdelete);
}
}
\ 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