Skip to content
Snippets Groups Projects
Commit 25bcf7e3 authored by Mélissa Aïdli's avatar Mélissa Aïdli
Browse files

Autorisation inscription sorties comptes validés + Infos comptes visibles après inscrip

parent 40226839
Branches
No related tags found
2 merge requests!75Authorize valid profile,!76Authorize valid profile
Showing
with 613 additions and 13 deletions
import { Injectable } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import {ActivatedRoute,Router} from '@angular/router'
import {PersonalData} from '../core'
import * as moment from 'moment'
import {User} from 'app/core'
@Injectable({
providedIn: 'root',
})
@Component({
selector: 'app-my-data',
templateUrl: './my-data.component.html',
......@@ -11,10 +18,13 @@ import {User} from 'app/core'
})
export class MyDataComponent implements OnInit{
personalData: PersonalData;
validatedAccount : String;
dateNow: Date;
currentYear: String;
private personalData: PersonalData;
public validatedAccount : String;
public dateNow: Date;
public currentYear: String;
public validState: boolean;
public grade = {
"troisieme": "Troisième",
......@@ -25,6 +35,16 @@ export class MyDataComponent implements OnInit {
}
public getValidState() : boolean {
if (this.validatedAccount=="Validé"){
return true
}
else {
return false
}
}
//Styles validated account label depending on the status of the account
public styleValidatedAccount = ()=> {
if(this.validatedAccount==="Données personnelles non remplies"){
......@@ -68,13 +88,16 @@ export class MyDataComponent implements OnInit {
}
if(this.personalData.registration.validated){
this.validatedAccount= "Validé"
this.validatedAccount= "Validé";
}else if(this.personalData.year===this.currentYear){
this.validatedAccount="En cours de validation"
this.validatedAccount="En cours de validation";
}else{
this.validatedAccount="Données personnelles non remplies"
this.validatedAccount="Données personnelles non remplies";
}
}
}
......@@ -32,11 +32,15 @@
<!-- Show register button if user does not participate -->
<div *ngIf="visit.registrationsOpen && !participant" class="text-center">
<button id="participate-btn" type="button" name="button" class="btn-success" (click)="registerFormActive = true">Je m'inscris</button>
<button id="participate-btn" type="button" name="button" class="btn-primary" [disabled]="!isValid" (click)="registerFormActive = true">
Je m'inscris</button>
</div>
<div *ngIf="participant && !visit.passed">
<div class="text-muted-sm">{{errorMessageRegistration}}</div>
<div *ngIf="participant && !visit.passed">
<!-- And a shy-ish unregister link -->
<p class="text-muted-sm">
Tu as un empêchement et souhaites
......
......@@ -23,6 +23,8 @@
margin-top: 1em;
}
img#illustration {
display: block;
margin: 1em auto;
......
......@@ -3,6 +3,11 @@ import { Observable, Subject } from 'rxjs';
import { ActivatedRoute } from '@angular/router';
import { AuthService, Geocoder } from 'app/core';
import { Visit, Participant } from '../shared';
import {MyDataComponent} from 'app/members/account/my-data/my-data.component';
@Component({
selector: 'app-visit-detail',
......@@ -19,18 +24,27 @@ export class VisitDetailComponent implements OnInit {
formLoading: boolean = false;
leaveFormActive = false;
geocoder: Geocoder;
errorMessageRegistration= "";
isValid : boolean;
constructor(
private route: ActivatedRoute,
private auth: AuthService,
) { }
private dataC: MyDataComponent,
) {this.isValid=dataC.getValidState()}
ngOnInit() {
this.visit = this.route.snapshot.data['visit'];
this.geocoder = this.route.snapshot.data['geocoder'];
this.userId = this.auth.getUserSnapshot().id;
this.getParticipant();
this.getAcceptedParticipants();
if (!this.isValid)
{
this.errorMessageRegistration="Tu dois valider ton compte pour pouvoir t'inscrire aux sorties."
}
}
getParticipant() {
......@@ -52,3 +66,4 @@ export class VisitDetailComponent implements OnInit {
}
}
......@@ -127,7 +127,7 @@ export class StudentSignupComponent implements OnInit {
tap(() => this.loading = false),
tap(() => {
setTimeout(()=>{
this.router.navigate(['./membres'])
this.router.navigate(['./membres/compte/donnees'])
},3000)})
......
src/favicon.ico

5.3 KiB | W: | H:

src/favicon.ico

63.9 KiB | W: | H:

src/favicon.ico
src/favicon.ico
src/favicon.ico
src/favicon.ico
  • 2-up
  • Swipe
  • Onion skin
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { LoginComponent } from './login/login.component';
import { ResetComponent } from './reset/reset.component';
import { ResetConfirmComponent} from './reset-confirm/reset-confirm.component';
import { UiGalleryComponent } from './shared';
import { InternalErrorComponent, NotFoundComponent, AuthGuard, MapsAPIResolver } from './core';
const routes: Routes = [
{
path: '',
loadChildren: './showcase-site/showcase-site.module#ShowcaseSiteModule',
},
{
path: 'membres',
canActivate: [AuthGuard],
loadChildren: './members/members.module#MembersModule',
},
{
path: 'connexion',
component: LoginComponent,
},
{
path: 'inscription',
loadChildren: './signup/signup.module#SignupModule',
},
{
path: 'reinitialiser_mdp',
component: ResetComponent,
},
{
path: 'rest-auth/password/reset/confirm/:uid/:token',
component: ResetConfirmComponent,
},
{
path: '500',
component: InternalErrorComponent,
data: { title: 'Erreur interne' },
},
{
path: '**',
component: NotFoundComponent,
data: { title: 'Page introuvable' },
},
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
#progress {
position: fixed;
top: 0;
left: 0;
width: 100vw;
}
\ No newline at end of file
<mat-progress-bar id="progress" mode="indeterminate" color="primary" *ngIf="loading"></mat-progress-bar>
<router-outlet></router-outlet>
import { Component, OnInit, OnDestroy } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { Observable, Subscription } from 'rxjs';
import { filter, map, mergeMap } from 'rxjs/operators';
import { LoaderService } from './core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit, OnDestroy {
loading = false;
sub = new Subscription();
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private titleService: Title,
private loaderService: LoaderService,
) { }
ngOnInit() {
this.sub.add(
this.title$().subscribe(title => this.titleService.setTitle(title))
);
this.sub.add(
this.loaderService.loading().subscribe(loading => {
this.loading = loading;
})
);
}
private title$(): Observable<string> {
return this.router.events.pipe(
// When a navigation finishes
filter(event => event instanceof NavigationEnd),
// Get the activated route object instead of the actual event
map(() => this.activatedRoute),
// Traverse the child route path to get the last activated route
map(route => {
while (route.firstChild) route = route.firstChild;
return route;
}),
// Retrieve the route's data object
filter(route => route.outlet == 'primary'),
mergeMap(route => route.data),
// Retrieve the route title
map(data => data['title']),
map(title => 'OSER' + (title ? ' | ' + title : ''))
);
}
ngOnDestroy() {
this.sub.unsubscribe();
}
}
import localeFR from '@angular/common/locales/fr';
import { LOCALE_ID } from '@angular/core';
import { registerLocaleData } from '@angular/common';
// Modules
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { MatProgressBarModule } from '@angular/material';
import { MomentModule } from 'ngx-moment';
import {
MatFormFieldModule,
MatInputModule,
MatOptionModule,
MatSelectModule,
MatButtonModule,
MatRadioModule,
MatDatepickerModule,
MatNativeDateModule,
MatIconModule,
MatSnackBarModule,
} from '@angular/material';
// App modules
import { CoreModule } from './core';
import { SharedModule } from './shared';
import { AppRoutingModule } from './app-routing.module';
// Components
import { AppComponent } from './app.component';
import { LoginComponent } from './login/login.component';
// Services
import { MessageService } from './core';
import { ResetComponent } from './reset/reset.component';
import { ResetConfirmComponent } from './reset-confirm/reset-confirm.component';
registerLocaleData(localeFR);
@NgModule({
declarations: [
AppComponent,
LoginComponent,
ResetComponent,
ResetConfirmComponent,
],
imports: [
BrowserModule,
BrowserAnimationsModule,
FormsModule,
ReactiveFormsModule,
HttpModule,
MomentModule,
MatProgressBarModule,
CoreModule,
SharedModule,
HttpClientModule,
AppRoutingModule,
MatFormFieldModule,
MatInputModule,
MatOptionModule,
MatSelectModule,
MatRadioModule,
MatButtonModule,
MatNativeDateModule,
MatDatepickerModule,
MatIconModule,
MatSnackBarModule,
],
providers: [
MessageService,
{ provide: LOCALE_ID, useValue: 'fr' },
],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Injectable } from '@angular/core';
import { IAdapter } from './interfaces';
export interface Country {
name: string;
code: string;
}
export class AddressSchema {
line1: string;
line2: string;
postCode: string;
city: string;
country: Country;
}
export class Address extends AddressSchema {
constructor(args: AddressSchema) {
super();
Object.assign(this, args);
}
toString(): string {
return [this.line1, this.line2, this.postCode, this.city, this.country.name]
.filter(el => el)
.join(', ');
}
}
@Injectable({
providedIn: 'root'
})
export class AddressAdapter implements IAdapter<Address> {
adapt(data: any): Address {
return new Address({
line1: data.line1,
line2: data.line2,
postCode: data.post_code,
city: data.city,
country: {
name: data.country.name,
code: data.country.code,
},
});
}
encode(obj: Address): any {
return {
line1: obj.line1,
line2: obj.line2,
post_code: obj.postCode,
city: obj.city,
country: obj.country,
}
}
}
import { IAdapter } from './interfaces';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { environment } from 'environments/environment';
export class ShowcaseApiService {
apiUrl = environment.showcaseApiUrl;
}
export class ApiService {
apiUrl = environment.apiUrl;
}
export abstract class ModelApiService<T> extends ApiService {
abstract baseUrl: string;
public http: HttpClient;
list(): Observable<T[]> {
const adapter = this.getAdapter('list');
return this.http.get(this.baseUrl).pipe(
map((data: any[]) => data.map(item => adapter.adapt(item))),
)
}
retrieve(id: any): Observable<T> {
const adapter = this.getAdapter('retrieve');
const url = this.baseUrl + `${id}/`;
return this.http.get(url).pipe(
map((data: any) => adapter.adapt(data)),
)
}
abstract getAdapter(action: string): IAdapter<T>;
}
import { User } from './models';
export class UserAdapter {
adapt(item: any): User {
return new User({
id: item.id,
firstName: item.first_name,
lastName: item.last_name,
email: item.email,
phoneNumber: item.phone_number,
})
}
}
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from './auth.service';
import { ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
@Injectable({
providedIn: 'root',
})
export class AuthGuard implements CanActivate {
constructor(private auth: AuthService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.auth.isLoggedIn) {
return true;
}
this.auth.redirectUrl = state.url;
this.auth.fromGuard = true;
this.auth.redirectLogin();
return false;
}
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Router } from '@angular/router';
import { Observable, BehaviorSubject } from 'rxjs';
import { tap, map } from 'rxjs/operators';
import { environment } from 'environments/environment';
import { User } from './models';
import { ObjectStoredItem, SimpleStoredItem } from '../storage';
import { UserAdapter } from './adapters';
class StoredUser extends ObjectStoredItem<User> { key = 'oser-cs-user-info'; }
class StoredToken extends SimpleStoredItem { key = 'oser-cs-user-token'; }
@Injectable({
providedIn: 'root',
})
export class AuthService {
private loginUrl = environment.apiUrl + 'auth/get-token/';
private resetUrl = environment.apiUrl + 'rest-auth/password/reset/';
private resetConfirmUrl = environment.apiUrl + 'rest-auth/password/reset/confirm/';
fromGuard: boolean;
redirectUrl: string;
fromUnauthorized: boolean;
private userAdapter = new UserAdapter();
private user = new StoredUser();
private token = new StoredToken();
private user$: BehaviorSubject<User>;
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): Observable<boolean> {
return this.http.post<any>(this.loginUrl, { username: username, password: password }).pipe(
tap(data => this.token.set(data.token)),
map(data => this.userAdapter.adapt(data.user)),
tap((user: User) => this.user.set(user)),
tap((user: User) => this.user$.next(user)),
map(() => true),
);
}
reset(email: string): Observable<boolean> {
console.log("reset function of auth service");
return this.http.post<any>(this.resetUrl, { email }).pipe(
map(() => true),
);
}
resetConfirm(uid: string, token: string, new_password1: string, new_password2: string): Observable<boolean> {
console.log("reset confirm function");
return this.http.post<any>(this.resetConfirmUrl, { uid, token, new_password1, new_password2 }).pipe(
map(() => true),
);
}
redirectLogin() {
this.router.navigate(['/connexion']);
}
getUserSnapshot(): User {
return this.user.get();
}
getUser(): Observable<User> {
return this.user$.asObservable();
}
getToken(): string {
return this.token.get();
}
// Headers for use in authenticated calls to the backend API.
getAuthorizationHeaders(): HttpHeaders {
return new HttpHeaders({ Authorization: 'Token ' + this.getToken() });
}
get isLoggedIn(): boolean {
if (this.user.get()) {
return true;
}
return false;
}
logout() {
this.user.destroy();
this.token.destroy();
this.user$.next(null);
}
}
export * from './auth.service';
export * from './auth-guard.service';
export * from './models';
export * from './adapters';
export * from './token.interceptor';
export interface UserInfo {
id: number;
email?: string;
firstName?: string;
lastName?: string;
phoneNumber?: string;
}
export class User {
id: number;
email: string;
firstName: string;
lastName: string;
phoneNumber: string;
constructor(opts: UserInfo) {
this.id = opts.id;
this.email = opts.email;
this.firstName = opts.firstName;
this.lastName = opts.lastName;
this.phoneNumber = opts.phoneNumber;
}
get fullName(): string {
return [this.firstName, this.lastName].filter(x => !!x).join(' ');
}
}
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpErrorResponse } from '@angular/common/http';
import { Location } from '@angular/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { AuthService } from './auth.service';
import { ErrorService } from '../error.service';
@Injectable({
providedIn: 'root',
})
export class TokenInterceptor implements HttpInterceptor {
constructor(
private auth: AuthService,
private location: Location,
private errorService: ErrorService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = this.attachToken(request);
return next.handle(request).pipe(
tap(
(event: HttpEvent<any>) => { },
(error: any) => this.onError(error),
),
);
}
onError(error: any) {
console.error(error);
if (error instanceof HttpErrorResponse) {
if (error.status === 401) {
this.auth.redirectUrl = this.location.path();
this.auth.fromUnauthorized = true;
this.auth.logout(); // forget credentials as they may be corrupt
this.auth.redirectLogin();
}
}
}
attachToken(request: HttpRequest<any>): HttpRequest<any> {
const token = this.auth.getToken();
if (token) {
request = request.clone({ headers: this.auth.getAuthorizationHeaders() });
}
return request
}
}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { AgmCoreModule } from '@agm/core';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MarkdownModule, MarkdownComponent, MarkdownPipe } from 'ngx-markdown';
import { TokenInterceptor } from './auth';
import { LoaderService } from './loader.service';
import { MessageModule } from './messages';
import { FuzzyPipe, LineBreaksPipe } from './pipes';
import { NotFoundComponent } from './not-found';
import { InternalErrorComponent } from './internal-error';
import { ErrorPageComponent } from './error-page';
@NgModule({
imports: [
CommonModule,
RouterModule,
MessageModule,
MarkdownModule.forRoot(),
AgmCoreModule.forRoot({
apiKey: 'AIzaSyDXPxwZpx9EiwarLAZ3yzUANK9D4q0X9cI',
}),
],
declarations: [
FuzzyPipe,
LineBreaksPipe,
InternalErrorComponent,
NotFoundComponent,
ErrorPageComponent,
],
providers: [
LoaderService,
{ provide: HTTP_INTERCEPTORS, useClass: TokenInterceptor, multi: true },
],
exports: [
MessageModule,
FuzzyPipe,
LineBreaksPipe,
MarkdownComponent,
MarkdownPipe,
]
})
export class CoreModule { }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment