Skip to content
Snippets Groups Projects
Unverified Commit 5020ebc5 authored by Florimond Manca's avatar Florimond Manca Committed by GitHub
Browse files

Merge pull request #26 from oser-cs/release/first-users

Release first-users version to production
parents d03c9fd2 32df7db1
Branches
No related tags found
2 merge requests!30Dev pages projet,!32Modify inscription page
Showing
with 1743 additions and 3281 deletions
This diff is collapsed.
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router'; import { RouterModule, Routes } from '@angular/router';
import { SignupPageComponent } from './signup-page/signup-page.component'; import { LoginComponent } from './login/login.component';
import { LoginComponent, UiGalleryComponent } from './shared'; import { UiGalleryComponent } from './shared';
import { InternalErrorComponent, NotFoundComponent, AuthGuard, MapsAPIResolver } from './core'; import { InternalErrorComponent, NotFoundComponent, AuthGuard, MapsAPIResolver } from './core';
const routes: Routes = [ const routes: Routes = [
{ {
path: '', path: '',
loadChildren: './showcase-site/showcase-site.module#ShowcaseSiteModule', loadChildren: './showcase-site/showcase-site.module#ShowcaseSiteModule',
}, },
{ {
path: 'sorties', path: 'membres',
canActivate: [AuthGuard], canActivate: [AuthGuard],
loadChildren: './visits/visits.module#VisitsModule', loadChildren: './members/members.module#MembersModule',
}, },
{ {
path: 'projets', path: 'connexion',
canActivate: [AuthGuard], component: LoginComponent,
loadChildren: './projects/projects.module#ProjectsModule',
}, },
{ {
path: 'login', component: LoginComponent path: 'inscription',
}, loadChildren: './signup/signup.module#SignupModule',
{
path: 'signup', component: SignupPageComponent
}, },
{ {
path: '500', path: '500',
...@@ -35,6 +33,7 @@ const routes: Routes = [ ...@@ -35,6 +33,7 @@ const routes: Routes = [
component: NotFoundComponent, component: NotFoundComponent,
data: { title: 'Page introuvable' }, data: { title: 'Page introuvable' },
}, },
]; ];
@NgModule({ @NgModule({
......
#progress {
position: fixed;
top: 0;
left: 0;
width: 100vw;
}
<app-splash *ngIf="!active"></app-splash> <mat-progress-bar id="progress" mode="indeterminate" color="primary" *ngIf="loading"></mat-progress-bar>
<router-outlet></router-outlet> <router-outlet></router-outlet>
import { Component, OnInit, OnDestroy } from '@angular/core'; import { Component, OnInit, OnDestroy } from '@angular/core';
import { Title } from '@angular/platform-browser'; import { Title } from '@angular/platform-browser';
import { Router, ActivatedRoute, NavigationStart, NavigationEnd } from '@angular/router'; import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
import { filter, map, mergeMap } from 'rxjs/operators'; import { filter, map, mergeMap } from 'rxjs/operators';
import { LoaderService } from './core'; import { LoaderService } from './core';
...@@ -12,7 +12,7 @@ import { LoaderService } from './core'; ...@@ -12,7 +12,7 @@ import { LoaderService } from './core';
}) })
export class AppComponent implements OnInit, OnDestroy { export class AppComponent implements OnInit, OnDestroy {
active = false; loading = false;
sub = new Subscription(); sub = new Subscription();
constructor( constructor(
...@@ -28,18 +28,11 @@ export class AppComponent implements OnInit, OnDestroy { ...@@ -28,18 +28,11 @@ export class AppComponent implements OnInit, OnDestroy {
); );
this.sub.add( this.sub.add(
this.loaderService.loading().subscribe(loading => { this.loaderService.loading().subscribe(loading => {
this.active = !loading; this.loading = loading;
}) })
); );
} }
private active$(): Observable<boolean> {
return this.router.events.pipe(
filter(event => event instanceof NavigationStart || event instanceof NavigationEnd),
map(event => event instanceof NavigationEnd),
);
}
private title$(): Observable<string> { private title$(): Observable<string> {
return this.router.events.pipe( return this.router.events.pipe(
// When a navigation finishes // When a navigation finishes
......
...@@ -6,11 +6,22 @@ import { registerLocaleData } from '@angular/common'; ...@@ -6,11 +6,22 @@ import { registerLocaleData } from '@angular/common';
import { BrowserModule } from '@angular/platform-browser'; import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core'; import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms'; import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http'; import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http'; import { HttpClientModule } from '@angular/common/http';
import { MatProgressBarModule } from '@angular/material'; import { MatProgressBarModule } from '@angular/material';
import { MomentModule } from 'ngx-moment'; import { MomentModule } from 'ngx-moment';
import {
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatButtonModule,
MatRadioModule,
MatDatepickerModule,
MatNativeDateModule,
MatIconModule,
MatSnackBarModule,
} from '@angular/material';
// App modules // App modules
import { CoreModule } from './core'; import { CoreModule } from './core';
...@@ -19,25 +30,23 @@ import { AppRoutingModule } from './app-routing.module'; ...@@ -19,25 +30,23 @@ import { AppRoutingModule } from './app-routing.module';
// Components // Components
import { AppComponent } from './app.component'; import { AppComponent } from './app.component';
import { SignupPageComponent } from './signup-page/signup-page.component'; import { LoginComponent } from './login/login.component';
// Services // Services
import { StudentService } from './signup-page/student.service';
import { MessageService } from './core'; import { MessageService } from './core';
import { SplashComponent } from './splash/splash.component';
registerLocaleData(localeFR); registerLocaleData(localeFR);
@NgModule({ @NgModule({
declarations: [ declarations: [
AppComponent, AppComponent,
SignupPageComponent, LoginComponent,
SplashComponent,
], ],
imports: [ imports: [
BrowserModule, BrowserModule,
BrowserAnimationsModule, BrowserAnimationsModule,
FormsModule, FormsModule,
ReactiveFormsModule,
HttpModule, HttpModule,
MomentModule, MomentModule,
MatProgressBarModule, MatProgressBarModule,
...@@ -45,9 +54,17 @@ registerLocaleData(localeFR); ...@@ -45,9 +54,17 @@ registerLocaleData(localeFR);
SharedModule, SharedModule,
HttpClientModule, HttpClientModule,
AppRoutingModule, AppRoutingModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatRadioModule,
MatButtonModule,
MatNativeDateModule,
MatDatepickerModule,
MatIconModule,
MatSnackBarModule,
], ],
providers: [ providers: [
StudentService,
MessageService, MessageService,
{ provide: LOCALE_ID, useValue: 'fr' }, { provide: LOCALE_ID, useValue: 'fr' },
], ],
......
import { Injectable } from '@angular/core';
import { IAdapter } from './interfaces'; import { IAdapter } from './interfaces';
export interface Country { export interface Country {
...@@ -29,7 +30,9 @@ export class Address extends AddressSchema { ...@@ -29,7 +30,9 @@ export class Address extends AddressSchema {
} }
} }
@Injectable({
providedIn: 'root'
})
export class AddressAdapter implements IAdapter<Address> { export class AddressAdapter implements IAdapter<Address> {
adapt(data: any): Address { adapt(data: any): Address {
return new Address({ return new Address({
...@@ -43,4 +46,14 @@ export class AddressAdapter implements IAdapter<Address> { ...@@ -43,4 +46,14 @@ export class AddressAdapter implements IAdapter<Address> {
}, },
}); });
} }
encode(obj: Address): any {
return {
line1: obj.line1,
line2: obj.line2,
post_code: obj.postCode,
city: obj.city,
country: obj.country,
}
}
} }
...@@ -4,17 +4,14 @@ import { Observable } from 'rxjs'; ...@@ -4,17 +4,14 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { environment } from 'environments/environment'; import { environment } from 'environments/environment';
export class ShowcaseApiService { export class ShowcaseApiService {
apiUrl = environment.showcaseApiUrl; apiUrl = environment.showcaseApiUrl;
} }
export class ApiService { export class ApiService {
apiUrl = environment.apiUrl; apiUrl = environment.apiUrl;
} }
export abstract class ModelApiService<T> extends ApiService { export abstract class ModelApiService<T> extends ApiService {
abstract baseUrl: string; abstract baseUrl: string;
......
...@@ -8,9 +8,7 @@ export class UserAdapter { ...@@ -8,9 +8,7 @@ export class UserAdapter {
firstName: item.first_name, firstName: item.first_name,
lastName: item.last_name, lastName: item.last_name,
email: item.email, email: item.email,
gender: item.gender,
phoneNumber: item.phone_number, phoneNumber: item.phone_number,
dateOfBirth: item.date_of_birth ? new Date(item.date_of_birth) : null,
}) })
} }
} }
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http'; import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Observable } from 'rxjs'; import { Observable, BehaviorSubject } from 'rxjs';
import { tap, map } from 'rxjs/operators'; import { tap, map } from 'rxjs/operators';
import { environment } from 'environments/environment'; import { environment } from 'environments/environment';
import { User } from './models'; import { User } from './models';
...@@ -27,26 +27,36 @@ export class AuthService { ...@@ -27,26 +27,36 @@ export class AuthService {
private userAdapter = new UserAdapter(); private userAdapter = new UserAdapter();
private user = new StoredUser(); private user = new StoredUser();
private token = new StoredToken(); private token = new StoredToken();
private user$: BehaviorSubject<User>;
constructor(private http: HttpClient, private router: Router) {} constructor(private http: HttpClient, private router: Router) {
const userData = this.getUserSnapshot();
const initialUser = userData ? new User(userData) : null;
this.user$ = new BehaviorSubject(initialUser);
}
login(username: string, password: string) { login(username: string, password: string) {
return this.http.post<any>(this.loginUrl, { username: username, password: password }).pipe( return this.http.post<any>(this.loginUrl, { username: username, password: password }).pipe(
tap(data => this.token.set(data.token)), tap(data => this.token.set(data.token)),
map(data => this.userAdapter.adapt(data.user)), map(data => this.userAdapter.adapt(data.user)),
tap((user: User) => this.user.set(user)), tap((user: User) => this.user.set(user)),
tap((user: User) => this.user$.next(user)),
map(() => true), map(() => true),
); );
} }
redirectLogin() { redirectLogin() {
this.router.navigate(['/login']); this.router.navigate(['/connexion']);
} }
getUser(): User { getUserSnapshot(): User {
return this.user.get(); return this.user.get();
} }
getUser(): Observable<User> {
return this.user$.asObservable();
}
getToken(): string { getToken(): string {
return this.token.get(); return this.token.get();
} }
...@@ -66,5 +76,6 @@ export class AuthService { ...@@ -66,5 +76,6 @@ export class AuthService {
logout() { logout() {
this.user.destroy(); this.user.destroy();
this.token.destroy(); this.token.destroy();
this.user$.next(null);
} }
} }
...@@ -3,9 +3,7 @@ export interface UserInfo { ...@@ -3,9 +3,7 @@ export interface UserInfo {
email?: string; email?: string;
firstName?: string; firstName?: string;
lastName?: string; lastName?: string;
gender?: string;
phoneNumber?: string; phoneNumber?: string;
dateOfBirth?: Date;
} }
export class User { export class User {
...@@ -13,21 +11,17 @@ export class User { ...@@ -13,21 +11,17 @@ export class User {
email: string; email: string;
firstName: string; firstName: string;
lastName: string; lastName: string;
gender: string;
phoneNumber: string; phoneNumber: string;
dateOfBirth: Date;
constructor(opts: UserInfo) { constructor(opts: UserInfo) {
this.id = opts.id; this.id = opts.id;
this.email = opts.email; this.email = opts.email;
this.firstName = opts.firstName; this.firstName = opts.firstName;
this.lastName = opts.lastName; this.lastName = opts.lastName;
this.gender = opts.gender;
this.phoneNumber = opts.phoneNumber; this.phoneNumber = opts.phoneNumber;
this.dateOfBirth = opts.dateOfBirth;
} }
get fullName(): string { get fullName(): string {
return [this.firstName, this.lastName].filter(x => x).join(' '); return [this.firstName, this.lastName].filter(x => !!x).join(' ');
} }
} }
...@@ -36,12 +36,6 @@ export class TokenInterceptor implements HttpInterceptor { ...@@ -36,12 +36,6 @@ export class TokenInterceptor implements HttpInterceptor {
this.auth.fromUnauthorized = true; this.auth.fromUnauthorized = true;
this.auth.logout(); // forget credentials as they may be corrupt this.auth.logout(); // forget credentials as they may be corrupt
this.auth.redirectLogin(); this.auth.redirectLogin();
// } else if (error.status === 0) {
// // Status 0 is a CORS error
// // Generally means that backend server is down
// // this.errorService.panic();
// } else if (error.status === 404) {
// this.errorService.notFound();
} }
} }
} }
......
...@@ -6,7 +6,6 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http'; ...@@ -6,7 +6,6 @@ import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MarkdownModule, MarkdownComponent, MarkdownPipe } from 'ngx-markdown'; import { MarkdownModule, MarkdownComponent, MarkdownPipe } from 'ngx-markdown';
import { TokenInterceptor } from './auth'; import { TokenInterceptor } from './auth';
import { LoaderService } from './loader.service'; import { LoaderService } from './loader.service';
import { LoaderInterceptor } from './loader.interceptor';
import { MessageModule } from './messages'; import { MessageModule } from './messages';
import { FuzzyPipe, LineBreaksPipe } from './pipes'; import { FuzzyPipe, LineBreaksPipe } from './pipes';
import { NotFoundComponent } from './not-found'; import { NotFoundComponent } from './not-found';
...@@ -33,7 +32,6 @@ import { ErrorPageComponent } from './error-page'; ...@@ -33,7 +32,6 @@ import { ErrorPageComponent } from './error-page';
providers: [ providers: [
LoaderService, LoaderService,
{ provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true }, { provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true },
], ],
exports: [ exports: [
MessageModule, MessageModule,
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { map, tap, catchError } from 'rxjs/operators'; import { map, catchError } from 'rxjs/operators';
import { environment } from 'environments/environment'; import { environment } from 'environments/environment';
import { ActivatedRouteSnapshot, RouterStateSnapshot, Resolve } from '@angular/router'; import { ActivatedRouteSnapshot, RouterStateSnapshot, Resolve } from '@angular/router';
......
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { MapsAPILoader } from '@agm/core'; import { MapsAPILoader } from '@agm/core';
import { Resolve } from '@angular/router'; import { Resolve } from '@angular/router';
import { Observable, BehaviorSubject, from } from 'rxjs'; import { Observable, from } from 'rxjs';
import { filter, map, mergeMap } from 'rxjs/operators'; import { map } from 'rxjs/operators';
declare const google: any; declare const google: any;
......
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest } from '@angular/common/http';
import { Observable, timer } from 'rxjs';
import { tap } from 'rxjs/operators';
import { LoaderService } from './loader.service';
@Injectable()
export class LoaderInterceptor implements HttpInterceptor {
constructor(private loaderService: LoaderService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.loaderService.loading$.next(true);
return next.handle(request).pipe(
tap(() => this.loaderService.loading$.next(false)),
);
}
}
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { Router, NavigationStart, NavigationEnd, NavigationCancel } from '@angular/router';
import { Observable, BehaviorSubject } from 'rxjs'; import { Observable, BehaviorSubject } from 'rxjs';
import { debounceTime, distinctUntilChanged } from 'rxjs/operators'; import { map, debounceTime, tap, filter } from 'rxjs/operators';
@Injectable() @Injectable()
export class LoaderService { export class LoaderService {
public loading$: BehaviorSubject<boolean> = new BehaviorSubject(false); constructor(private router: Router) {}
public loading(): Observable<boolean> { public loading(): Observable<boolean> {
return this.loading$.asObservable().pipe( return this.router.events.pipe(
// Prevent having multiple false's or multiple true's filter(e => e instanceof NavigationStart || e instanceof NavigationEnd || e instanceof NavigationCancel),
distinctUntilChanged(), debounceTime(100), // don't mark fast navigation changes as navigating
map((e) => e instanceof NavigationStart),
); );
} }
......
...@@ -11,7 +11,6 @@ interface Retrievable<T> { ...@@ -11,7 +11,6 @@ interface Retrievable<T> {
retrieve: (id: any) => Observable<T>; retrieve: (id: any) => Observable<T>;
} }
export abstract class ObjectListResolver<T> implements Resolve<T[]> { export abstract class ObjectListResolver<T> implements Resolve<T[]> {
public service: Listable<T>; public service: Listable<T>;
...@@ -23,7 +22,6 @@ export abstract class ObjectListResolver<T> implements Resolve<T[]> { ...@@ -23,7 +22,6 @@ export abstract class ObjectListResolver<T> implements Resolve<T[]> {
} }
} }
export abstract class ObjectResolver<T> implements Resolve<T> { export abstract class ObjectResolver<T> implements Resolve<T> {
public service: Retrievable<T>; public service: Retrievable<T>;
......
...@@ -3,8 +3,6 @@ import { Observable, of } from 'rxjs'; ...@@ -3,8 +3,6 @@ import { Observable, of } from 'rxjs';
import { map, tap, catchError } from 'rxjs/operators'; import { map, tap, catchError } from 'rxjs/operators';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Resolve } from '@angular/router'; import { Resolve } from '@angular/router';
import { environment } from 'environments/environment';
@Injectable() @Injectable()
export abstract class SimpleListResolver<T> implements Resolve<T[]> { export abstract class SimpleListResolver<T> implements Resolve<T[]> {
......
<app-form-page>
<h1>Connexion</h1>
<form [formGroup]="formGroup" (ngSubmit)="login()">
<!-- Email field -->
<mat-form-field class="block">
<input matInput type="email" formControlName="email" required placeholder="Adresse email" autofocus>
</mat-form-field>
<!-- Password field -->
<mat-form-field class="block">
<input matInput type="password" formControlName="password" required placeholder="Mot de passe">
</mat-form-field>
<!-- Submit -->
<div class="text-center">
<button mat-raised-button color="primary" [disabled]="!formGroup.valid || loading" id="login-btn">
Se connecter <i *ngIf="loading" class="fa fa-spinner fa-pulse"></i>
</button>
</div>
</form>
<messages></messages>
<p class="text-center">
Ou crée ton
<a routerLink="/inscription">compte tutoré</a>
</p>
</app-form-page>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment