Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • arsnova/arsnova-lite
1 result
Show changes
Commits on Source (20)
Showing
with 235 additions and 40 deletions
......@@ -8,6 +8,7 @@ import { CreateCommentComponent } from './create-comment/create-comment.componen
import { ParticipantHomeScreenComponent } from './participant-home-screen/participant-home-screen.component';
import { AuthenticationGuard } from './authentication.guard';
import { UserRole } from './user-roles.enum';
import { ParticipantRoomComponent } from './participant-room/participant-room.component';
const routes: Routes = [
{ path: '', redirectTo: '/home', pathMatch: 'full' },
......@@ -34,6 +35,12 @@ const routes: Routes = [
canActivate: [AuthenticationGuard],
data: { roles: [UserRole.PARTICIPANT] }
},
{
path: 'participant/room/:roomId',
component: ParticipantRoomComponent,
canActivate: [AuthenticationGuard],
data: { roles: [UserRole.PARTICIPANT] }
},
{ path: '**', component: PageNotFoundComponent }
];
......
......@@ -64,6 +64,7 @@ import { CreatorHomeScreenComponent } from './creator-home-screen/creator-home-s
import { CreateCommentComponent } from './create-comment/create-comment.component';
import { CommentService } from './comment.service';
import { ParticipantHomeScreenComponent } from './participant-home-screen/participant-home-screen.component';
import { ParticipantRoomComponent } from './participant-room/participant-room.component';
import { DataStoreService } from './data-store.service';
@NgModule({
......@@ -85,7 +86,8 @@ import { DataStoreService } from './data-store.service';
CreateCommentComponent,
ParticipantHomeScreenComponent,
CommentComponent,
ContentAnswersComponent
ContentAnswersComponent,
ParticipantRoomComponent
],
entryComponents: [
RegisterComponent,
......
<form (ngSubmit)="login(userName.value, userPassword.value)" fxLayout="column" fxLayoutAlign="space-around"
<form (ngSubmit)="login(userEmail.value, userPassword.value)" fxLayout="column" fxLayoutAlign="space-around"
fxLayoutGap="10px">
<mat-form-field class="input-block">
<input matInput #userName placeholder="Username" [formControl]="usernameFormControl" [errorStateMatcher]="matcher"
<input matInput #userEmail placeholder="E-mail" [formControl]="usernameFormControl" [errorStateMatcher]="matcher"
name="username"/>
<mat-error *ngIf="usernameFormControl.hasError('required')">Username is <strong>required</strong>.</mat-error>
<mat-error *ngIf="usernameFormControl.hasError('email') && !usernameFormControl.hasError('required')">Please enter a <strong>valid</strong> e-mail address.
</mat-error>
<mat-error *ngIf="usernameFormControl.hasError('required')">E-mail is <strong>required</strong>.</mat-error>
</mat-form-field>
<mat-form-field class="input-block">
......@@ -12,6 +14,8 @@
<mat-error *ngIf="passwordFormControl.hasError('required')">Password is <strong>required</strong>.</mat-error>
</mat-form-field>
<button mat-raised-button color="primary" (click)="login(userName.value, userPassword.value)">Login</button>
<button mat-raised-button *ngIf="role === UserRole.PARTICIPANT" (click)="login('anonymus', 'nothing')">Login as guest</button>
<button mat-raised-button color="primary" type="submit">Login</button>
<button mat-raised-button *ngIf="role === UserRole.PARTICIPANT" (click)="guestLogin()">Login as
guest
</button>
</form>
......@@ -24,7 +24,7 @@ export class LoginComponent implements OnInit {
@Input() public role: UserRole;
usernameFormControl = new FormControl('', [Validators.required]);
usernameFormControl = new FormControl('', [Validators.required, Validators.email]);
passwordFormControl = new FormControl('', [Validators.required]);
matcher = new LoginErrorStateMatcher();
......@@ -41,13 +41,18 @@ export class LoginComponent implements OnInit {
username = username.trim();
password = password.trim();
if (username !== '' && password !== '') {
if (!this.usernameFormControl.hasError('required') && !this.usernameFormControl.hasError('email') &&
!this.passwordFormControl.hasError('required')) {
this.authenticationService.login(username, password, this.role).subscribe(loginSuccessful => this.checkLogin(loginSuccessful));
} else {
this.notificationService.show('Login failed!');
this.notificationService.show('Please fit the requirements shown above.');
}
}
guestLogin(): void {
this.authenticationService.login('guest', 'guest', this.role).subscribe(loginSuccessful => this.checkLogin(loginSuccessful));
}
private checkLogin(loginSuccessful: boolean) {
if (loginSuccessful) {
this.notificationService.show('Login successful!');
......@@ -57,7 +62,7 @@ export class LoginComponent implements OnInit {
this.router.navigate(['participant']);
}
} else {
this.notificationService.show('Login failed!');
this.notificationService.show('Username or password incorrect.');
}
}
......
<div fxLayout="column" fxLayoutAlign="start" fxLayoutGap="20px" fxFill>
<div fxLayout="row" fxLayoutAlign="center">
<mat-card>
<mat-card-header>
<mat-card-title><h3 class="subheading-2">{{ roomName }}</h3></mat-card-title>
<mat-card-subtitle>{{ roomId }}</mat-card-subtitle>
</mat-card-header>
<mat-divider></mat-divider>
<mat-card-content>
<p>
{{ roomDescription }}
</p>
</mat-card-content>
<mat-divider></mat-divider>
<mat-card-actions>
<button mat-icon-button color="primary" matTooltip="Ask something" routerLink="/room/{{roomId}}/create-comment">
<mat-icon>question_answer</mat-icon>
</button>
<button mat-icon-button color="primary" matTooltip="Give feedback">
<mat-icon>feedback</mat-icon>
</button>
<button mat-button color="primary" matTooltip="Join question round">
Questions
</button>
<button mat-button color="primary" matTooltip="See room comments">
Comments
</button>
<button mat-button color="primary" matTooltip="Start personal question round">
Learn
</button>
</mat-card-actions>
</mat-card>
</div>
</div>
mat-card {
max-width: 800px;
}
mat-card-content>:first-child {
margin-top: 16px;
}
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { ParticipantRoomComponent } from './participant-room.component';
describe('ParticipantRoomComponent', () => {
let component: ParticipantRoomComponent;
let fixture: ComponentFixture<ParticipantRoomComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ParticipantRoomComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ParticipantRoomComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-participant-room',
templateUrl: './participant-room.component.html',
styleUrls: ['./participant-room.component.scss']
})
export class ParticipantRoomComponent implements OnInit {
roomId = '12 34 56 78';
roomName = 'Test Room';
roomDescription = 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore ' +
'magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea ' +
'takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod ' +
'tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea ' +
'rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.';
constructor() {
}
ngOnInit() {
}
}
<form>
<form (ngSubmit)="resetPassword(email.value)" fxLayout="column" fxLayoutAlign="space-around"
fxLayoutGap="10px">
<mat-form-field class="input-block">
<input matInput placeholder="E-Mail" />
<input matInput #email placeholder="E-Mail" [formControl]="usernameFormControl" [errorStateMatcher]="matcher"
name="email"/>
<mat-error *ngIf="usernameFormControl.hasError('required')">Email address is <strong>required</strong>.</mat-error>
<mat-error *ngIf="usernameFormControl.hasError('email') && !usernameFormControl.hasError('required')">Email is not <strong>valid</strong>.</mat-error>
</mat-form-field>
<button mat-raised-button color="primary">Submit</button>
<button mat-raised-button color="primary" type="submit">Reset password</button>
</form>
import { Component, OnInit } from '@angular/core';
import { Component, Inject, OnInit } from '@angular/core';
import { FormControl, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { AuthenticationService } from '../authentication.service';
import { NotificationService } from '../notification.service';
import { RegisterComponent } from '../register/register.component';
export class PasswordResetErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return (control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
@Component({
selector: 'app-password-reset',
......@@ -7,9 +19,35 @@ import { Component, OnInit } from '@angular/core';
})
export class PasswordResetComponent implements OnInit {
constructor() { }
usernameFormControl = new FormControl('', [Validators.required, Validators.email]);
matcher = new PasswordResetErrorStateMatcher();
constructor(public authenticationService: AuthenticationService,
public notificationService: NotificationService,
public dialogRef: MatDialogRef<RegisterComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
ngOnInit() {
}
resetPassword(username: string): void {
username = username.trim();
if (!this.usernameFormControl.hasError('required') && !this.usernameFormControl.hasError('email')) {
this.authenticationService.resetPassword(username).subscribe(result => {
if (result) {
this.notificationService.show('Password was reset. Please check your mail!');
this.dialogRef.close();
} else {
this.notificationService.show('Could not reset your password. Is your email address correct?');
}
});
} else {
this.notificationService.show('Please fit the requirements shown above.');
}
}
}
<form>
<form (ngSubmit)="register(userName.value, userPassword1.value, userPassword2.value)" fxLayout="column"
fxLayoutAlign="space-around" fxLayoutGap="10px">
<mat-form-field class="input-block">
<input matInput #email maxlength="256" placeholder="E-mail">
<mat-hint align="start"><strong></strong></mat-hint>
<input matInput #userName placeholder="E-mail" [formControl]="usernameFormControl" [errorStateMatcher]="matcher">
<mat-error *ngIf="usernameFormControl.hasError('email') && !usernameFormControl.hasError('required')">Please enter a
<strong>valid</strong> email address.
</mat-error>
<mat-error *ngIf="usernameFormControl.hasError('required')">Email address is <strong>required</strong>.</mat-error>
</mat-form-field>
<mat-form-field class="input-block">
<input matInput type="password" #passwd maxlength="256" placeholder="Password">
<mat-hint align="start"><strong></strong></mat-hint>
<mat-hint align="end">{{passwd.value.length}} / 256</mat-hint>
<input matInput type="password" #userPassword1 placeholder="Password" [formControl]="password1FormControl"
[errorStateMatcher]="matcher">
<mat-error *ngIf="password1FormControl.hasError('required')">Password is <strong>required</strong>.</mat-error>
</mat-form-field>
<mat-form-field class="input-block">
<input matInput type="password" #passwd2 maxlength="256" placeholder="Verify password">
<mat-hint align="start"><strong></strong></mat-hint>
<mat-hint align="end">{{passwd2.value.length}} / 256</mat-hint>
<input matInput type="password" #userPassword2 placeholder="Verify password" [formControl]="password2FormControl"
[errorStateMatcher]="matcher">
<mat-error *ngIf="password2FormControl.hasError('required')">Password is <strong>required</strong>.</mat-error>
<mat-error *ngIf="password2FormControl.hasError('passwordIsEqual') && !password2FormControl.hasError('required')">
Passwords do <strong>not</strong> match.
</mat-error>
</mat-form-field>
<div *ngIf="passwd.value === passwd2.value && passwd.value.length !== 0">
<mat-icon>check_circle</mat-icon>
</div>
<div *ngIf="passwd.value !== passwd2.value && passwd.value.length !== 0">
<mat-icon>clear</mat-icon>
</div>
<button mat-raised-button color="primary" (click)="save(email.value, passwd.value, passwd2.value)">Register</button>
<button mat-raised-button color="primary" type="submit">Register</button>
</form>
import { Component, Inject, OnInit } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { ErrorStateMatcher, MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
import { FormControl, FormGroupDirective, NgForm, Validators } from '@angular/forms';
import { AuthenticationService } from '../authentication.service';
import { NotificationService } from '../notification.service';
import { Router } from '@angular/router';
export class RegisterErrorStateMatcher implements ErrorStateMatcher {
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
const isSubmitted = form && form.submitted;
return (control && control.invalid && (control.dirty || control.touched || isSubmitted));
}
}
function validatePassword(password1: FormControl) {
return (formControl: FormControl) => {
const password1Value = password1.value;
const password2Value = formControl.value;
if (password1Value !== password2Value) {
return {
passwordIsEqual: {
isEqual: false
}
};
} else {
return null;
}
};
}
@Component({
selector: 'app-register',
......@@ -7,9 +35,16 @@ import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
styleUrls: ['./register.component.scss']
})
export class RegisterComponent implements OnInit {
check = 0;
constructor(public dialogRef: MatDialogRef<RegisterComponent>,
usernameFormControl = new FormControl('', [Validators.required, Validators.email]);
password1FormControl = new FormControl('', [Validators.required]);
password2FormControl = new FormControl('', [Validators.required, validatePassword(this.password1FormControl)]);
matcher = new RegisterErrorStateMatcher();
constructor(public authenticationService: AuthenticationService,
public notificationService: NotificationService,
public dialogRef: MatDialogRef<RegisterComponent>,
@Inject(MAT_DIALOG_DATA) public data: any) {
}
......@@ -20,12 +55,20 @@ export class RegisterComponent implements OnInit {
ngOnInit() {
}
save(email: string, password1: string, password2: string): void {
// console.log(email, password1, password2);
if (password1 === password2) {
console.log(true);
register(username: string, password1: string, password2: string): void {
if (!this.usernameFormControl.hasError('required') && !this.usernameFormControl.hasError('email') &&
!this.password1FormControl.hasError('required') &&
!this.password2FormControl.hasError('required') && !this.password2FormControl.hasError('passwordIsEqual')) {
this.authenticationService.register(username, password1).subscribe(result => {
if (result) {
this.notificationService.show('Successfully registered. Please check your mail!');
this.dialogRef.close();
} else {
this.notificationService.show('Oops! Something went wrong on our side...');
}
});
} else {
console.log(false);
this.notificationService.show('Please fit the requirements shown above.');
}
}
}
<mat-list>
<mat-list-item *ngFor="let room of rooms">
<button mat-button routerLink="/room/{{room.id}}">
<button mat-button routerLink="room/{{room.id}}">
{{room.name}}
</button>
</mat-list-item>
......