CP #2 SignUp WIP + Updated Swagger model fom Backend

This commit is contained in:
ThomasFransolet 2019-08-06 00:12:23 +02:00
parent b858915d2c
commit 61f2d867e4
15 changed files with 411 additions and 34 deletions

View File

@ -5,6 +5,7 @@ import { ApiConfiguration, ApiConfigurationInterface } from './api-configuration
import { AzureService } from './services/azure.service';
import { BooksService } from './services/books.service';
import { DeviceService } from './services/device.service';
import { FacebookService } from './services/facebook.service';
import { GoogleService } from './services/google.service';
import { IOTService } from './services/iot.service';
@ -29,6 +30,7 @@ import { ValuesService } from './services/values.service';
ApiConfiguration,
AzureService,
BooksService,
DeviceService,
FacebookService,
GoogleService,
IOTService,

View File

@ -1,9 +1,12 @@
export { AzureADAuthModel } from './models/azure-adauth-model';
export { Book } from './models/book';
export { Device } from './models/device';
export { FacebookAuthModel } from './models/facebook-auth-model';
export { GoogleAuthModel } from './models/google-auth-model';
export { SmartPrinterMessage } from './models/smart-printer-message';
export { SmartGardenMessage } from './models/smart-garden-message';
export { UserInfo } from './models/user-info';
export { ScreenConfiguration } from './models/screen-configuration';
export { Widget } from './models/widget';
export { User } from './models/user';
export { TwitterAuthModel } from './models/twitter-auth-model';
export { UserInfo } from './models/user-info';

View File

@ -0,0 +1,10 @@
/* tslint:disable */
export interface Device {
id?: string;
name?: string;
type?: string;
location?: string;
locationExplanation?: string;
height?: number;
width?: number;
}

View File

@ -0,0 +1,10 @@
/* tslint:disable */
import { Widget } from './widget';
export interface ScreenConfiguration {
id?: string;
name?: string;
type?: string;
widgets?: Array<Widget>;
height?: number;
width?: number;
}

View File

@ -1,11 +1,21 @@
/* tslint:disable */
import { ScreenConfiguration } from './screen-configuration';
import { Device } from './device';
export interface UserInfo {
address?: string;
id?: string;
role?: string;
username?: string;
email?: string;
password?: string;
firstName?: string;
lastName?: string;
token?: string;
birthday?: string;
role?: string;
city?: string;
state?: string;
language?: string;
timeZone?: string;
postalCode?: number;
screenConfigurationIds?: Array<ScreenConfiguration>;
deviceIds?: Array<Device>;
}

View File

@ -0,0 +1,16 @@
/* tslint:disable */
export interface Widget {
font?: string;
id?: string;
displayName?: string;
type?: string;
activated?: boolean;
form?: string;
name?: string;
color?: string;
size?: string;
width?: number;
height?: number;
positionX?: number;
positionY?: number;
}

View File

@ -1,5 +1,6 @@
export { AzureService } from './services/azure.service';
export { BooksService } from './services/books.service';
export { DeviceService } from './services/device.service';
export { FacebookService } from './services/facebook.service';
export { GoogleService } from './services/google.service';
export { IOTService } from './services/iot.service';

View File

@ -0,0 +1,254 @@
/* tslint:disable */
import { Injectable } from '@angular/core';
import { HttpClient, HttpRequest, HttpResponse, HttpHeaders } from '@angular/common/http';
import { BaseService as __BaseService } from '../base-service';
import { ApiConfiguration as __Configuration } from '../api-configuration';
import { StrictHttpResponse as __StrictHttpResponse } from '../strict-http-response';
import { Observable as __Observable } from 'rxjs';
import { map as __map, filter as __filter } from 'rxjs/operators';
import { Device } from '../models/device';
@Injectable({
providedIn: 'root',
})
class DeviceService extends __BaseService {
static readonly GetAllDevicesPath = '/api/device';
static readonly CreateDevicePath = '/api/device';
static readonly GetDeviceInfoPath = '/api/device/{idDevice}';
static readonly UpdateDevicePath = '/api/device/{idDevice}';
static readonly DeleteDevicePath = '/api/device/{idDevice}';
constructor(
config: __Configuration,
http: HttpClient
) {
super(config, http);
}
/**
* @return Success
*/
GetAllDevicesResponse(): __Observable<__StrictHttpResponse<Array<Device>>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
let req = new HttpRequest<any>(
'GET',
this.rootUrl + `/api/device`,
__body,
{
headers: __headers,
params: __params,
responseType: 'json'
});
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<Array<Device>>;
})
);
}
/**
* @return Success
*/
GetAllDevices(): __Observable<Array<Device>> {
return this.GetAllDevicesResponse().pipe(
__map(_r => _r.body as Array<Device>)
);
}
/**
* @param params The `DeviceService.CreateDeviceParams` containing the following parameters:
*
* - `idDevice`:
*
* - `device`:
*/
CreateDeviceResponse(params: DeviceService.CreateDeviceParams): __Observable<__StrictHttpResponse<null>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
if (params.idDevice != null) __params = __params.set('idDevice', params.idDevice.toString());
__body = params.device;
let req = new HttpRequest<any>(
'POST',
this.rootUrl + `/api/device`,
__body,
{
headers: __headers,
params: __params,
responseType: 'json'
});
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<null>;
})
);
}
/**
* @param params The `DeviceService.CreateDeviceParams` containing the following parameters:
*
* - `idDevice`:
*
* - `device`:
*/
CreateDevice(params: DeviceService.CreateDeviceParams): __Observable<null> {
return this.CreateDeviceResponse(params).pipe(
__map(_r => _r.body as null)
);
}
/**
* @param idDevice Id of the device you want to get information
* @return Success
*/
GetDeviceInfoResponse(idDevice: string): __Observable<__StrictHttpResponse<Device>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
let req = new HttpRequest<any>(
'GET',
this.rootUrl + `/api/device/${idDevice}`,
__body,
{
headers: __headers,
params: __params,
responseType: 'json'
});
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<Device>;
})
);
}
/**
* @param idDevice Id of the device you want to get information
* @return Success
*/
GetDeviceInfo(idDevice: string): __Observable<Device> {
return this.GetDeviceInfoResponse(idDevice).pipe(
__map(_r => _r.body as Device)
);
}
/**
* @param params The `DeviceService.UpdateDeviceParams` containing the following parameters:
*
* - `idDevice`:
*
* - `device`:
*/
UpdateDeviceResponse(params: DeviceService.UpdateDeviceParams): __Observable<__StrictHttpResponse<null>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
__body = params.device;
let req = new HttpRequest<any>(
'PUT',
this.rootUrl + `/api/device/${params.idDevice}`,
__body,
{
headers: __headers,
params: __params,
responseType: 'json'
});
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<null>;
})
);
}
/**
* @param params The `DeviceService.UpdateDeviceParams` containing the following parameters:
*
* - `idDevice`:
*
* - `device`:
*/
UpdateDevice(params: DeviceService.UpdateDeviceParams): __Observable<null> {
return this.UpdateDeviceResponse(params).pipe(
__map(_r => _r.body as null)
);
}
/**
* @param params The `DeviceService.DeleteDeviceParams` containing the following parameters:
*
* - `idDevice`:
*
* - `deviceId`:
*/
DeleteDeviceResponse(params: DeviceService.DeleteDeviceParams): __Observable<__StrictHttpResponse<null>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
__body = params.deviceId;
let req = new HttpRequest<any>(
'DELETE',
this.rootUrl + `/api/device/${params.idDevice}`,
__body,
{
headers: __headers,
params: __params,
responseType: 'json'
});
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<null>;
})
);
}
/**
* @param params The `DeviceService.DeleteDeviceParams` containing the following parameters:
*
* - `idDevice`:
*
* - `deviceId`:
*/
DeleteDevice(params: DeviceService.DeleteDeviceParams): __Observable<null> {
return this.DeleteDeviceResponse(params).pipe(
__map(_r => _r.body as null)
);
}
}
module DeviceService {
/**
* Parameters for CreateDevice
*/
export interface CreateDeviceParams {
idDevice?: number;
device?: Device;
}
/**
* Parameters for UpdateDevice
*/
export interface UpdateDeviceParams {
idDevice: number;
device?: Device;
}
/**
* Parameters for DeleteDevice
*/
export interface DeleteDeviceParams {
idDevice: number;
deviceId?: string;
}
}
export { DeviceService }

View File

@ -7,6 +7,7 @@ import { StrictHttpResponse as __StrictHttpResponse } from '../strict-http-respo
import { Observable as __Observable } from 'rxjs';
import { map as __map, filter as __filter } from 'rxjs/operators';
import { UserInfo } from '../models/user-info';
import { User } from '../models/user';
@Injectable({
providedIn: 'root',
@ -25,16 +26,18 @@ class TokenService extends __BaseService {
/**
* @param params The `TokenService.CreateParams` containing the following parameters:
*
* - `username`:
*
* - `password`:
*
* - `email`:
*
* @return Success
*/
CreateResponse(params: TokenService.CreateParams): __Observable<__StrictHttpResponse<null>> {
CreateResponse(params: TokenService.CreateParams): __Observable<__StrictHttpResponse<UserInfo>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
if (params.username != null) __params = __params.set('username', params.username.toString());
if (params.password != null) __params = __params.set('password', params.password.toString());
if (params.email != null) __params = __params.set('email', params.email.toString());
let req = new HttpRequest<any>(
'POST',
this.rootUrl + `/api/token`,
@ -48,20 +51,22 @@ class TokenService extends __BaseService {
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<null>;
return _r as __StrictHttpResponse<UserInfo>;
})
);
}
/**
* @param params The `TokenService.CreateParams` containing the following parameters:
*
* - `username`:
*
* - `password`:
*
* - `email`:
*
* @return Success
*/
Create(params: TokenService.CreateParams): __Observable<null> {
Create(params: TokenService.CreateParams): __Observable<UserInfo> {
return this.CreateResponse(params).pipe(
__map(_r => _r.body as null)
__map(_r => _r.body as UserInfo)
);
}
@ -106,8 +111,8 @@ module TokenService {
* Parameters for Create
*/
export interface CreateParams {
username?: string;
password?: string;
email?: string;
}
}

View File

@ -13,6 +13,7 @@ import { UserInfo } from '../models/user-info';
})
class UserService extends __BaseService {
static readonly GetPath = '/api/user';
static readonly CreateUserPath = '/api/user';
static readonly Get_1Path = '/api/user/{id}';
constructor(
@ -55,6 +56,42 @@ class UserService extends __BaseService {
);
}
/**
* @param newUser undefined
* @return Success
*/
CreateUserResponse(newUser?: UserInfo): __Observable<__StrictHttpResponse<UserInfo>> {
let __params = this.newParams();
let __headers = new HttpHeaders();
let __body: any = null;
__body = newUser;
let req = new HttpRequest<any>(
'POST',
this.rootUrl + `/api/user`,
__body,
{
headers: __headers,
params: __params,
responseType: 'json'
});
return this.http.request<any>(req).pipe(
__filter(_r => _r instanceof HttpResponse),
__map((_r) => {
return _r as __StrictHttpResponse<UserInfo>;
})
);
}
/**
* @param newUser undefined
* @return Success
*/
CreateUser(newUser?: UserInfo): __Observable<UserInfo> {
return this.CreateUserResponse(newUser).pipe(
__map(_r => _r.body as UserInfo)
);
}
/**
* @param id id user
* @return Success

View File

@ -19,6 +19,6 @@ export class ErrorInterceptor implements HttpInterceptor {
const error = err.error.message || err.statusText;
return throwError(error);
}))
}));
}
}
}

View File

@ -24,16 +24,16 @@ export class AuthenticationService {
this.currentUser = this.currentUserSubject.asObservable();
}
public GetToken(username: string, password: string): Observable<any> {
return this._tokenService.Create({username: username, password: password});
public GetToken(user: UserInfo): Observable<any> {
return this._tokenService.Create(user);
}
public GetAuthStatus() {
return this.IsLoggedIn;
}
public Login(username: string, password: string) {
return this._tokenService.Create({username: username, password: password})
public Login(user: UserInfo) {
return this._tokenService.Create(user)
.pipe(map(user => {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));

View File

@ -23,7 +23,7 @@
<div class="ui-inputgroup">
<span class="ui-inputgroup-addon"><i class="fa fa-user"></i></span>
<input type="text" [(ngModel)]="Username" pInputText placeholder="Username" >
<input type="text" [(ngModel)]="Email" pInputText placeholder="Email" >
</div>
<div class="ui-inputgroup">
<span class="ui-inputgroup-addon"><i class="fa fa-lock"></i></span>
@ -43,13 +43,13 @@
<div class="ui-inputgroup">
<div>
<span class="ui-inputgroup-addon"><i class="fa fa-user"></i></span>
<input type="text" pInputText placeholder="Last name">
<input type="text" [(ngModel)]="CreateUser.lastName" pInputText placeholder="Last name">
</div>
</div>
<div class="ui-inputgroup">
<div>
<span class="ui-inputgroup-addon"><i class="fa fa-user"></i></span>
<input type="text" pInputText placeholder="First name">
<input type="text" [(ngModel)]="CreateUser.firstName" pInputText placeholder="First name">
</div>
</div>
<div class="ui-inputgroup" *ngIf="Connected">
@ -62,7 +62,7 @@
<div class="ui-inputgroup">
<div>
<span class="ui-inputgroup-addon"><i class="fas fa-at"></i></span>
<input type="email" pInputText placeholder="E-mail">
<input type="email" [(ngModel)]="CreateUser.email" pInputText placeholder="E-mail">
</div>
</div>
@ -105,18 +105,19 @@
<div class="ui-inputgroup">
<div>
<span class="ui-inputgroup-addon"><i class="fas fa-key"></i></span>
<input type="password" pInputText placeholder="Password">
<input type="password" [(ngModel)]="CreateUser.password" pInputText placeholder="Password">
</div>
</div>
<div class="ui-inputgroup">
<div>
<span class="ui-inputgroup-addon"><i class="fas fa-key"></i></span>
<input type="password" pInputText placeholder="Confirm password">
<!-- TO UPDATE TO CHECK-->
<input type="password" [(ngModel)]="CreateUser.password" pInputText placeholder="Confirm password">
</div>
</div>
<p-footer>
<button pButton type="button" label="Identify"></button>
<button pButton type="button" label="Create profile" (click)="CreateProfile()"></button>
</p-footer>
</p-dialog>

View File

@ -6,6 +6,7 @@ import { AuthenticationService } from './_services/authentication.service';
import { Router } from '@angular/router';
import { first } from 'rxjs/operators';
import { UserInfo } from './_api/models';
import { UserService } from './_api/services';
@Component({
@ -26,11 +27,14 @@ export class AppComponent implements OnInit {
public DisplayPersonalField = false;
// Login
public Username: string = null;
public Email: string = null;
public Password: string = null;
public birthday: Date;
public CreateUser: UserInfo = {};
public UserTryingToLogin: UserInfo = {};
// Label
public LabelDropDownLogout: string;
public LabelDropDownModifyUser: string;
@ -39,6 +43,7 @@ export class AppComponent implements OnInit {
private _appService: AppService,
private _translateService: TranslateService,
private _authService: AuthenticationService,
private _userService: UserService,
private _router: Router
) {}
@ -69,12 +74,10 @@ export class AppComponent implements OnInit {
this.ConnectedUser = currentUser;
this.Connected = true;
this.DisplayLoginModal = false;
this.Username = null;
this.Email = null;
this.Password = null;
this._authService.IsLoggedIn = true;
}
}
@ -93,7 +96,9 @@ export class AppComponent implements OnInit {
console.log('ERROR');
});*/
this._authService.Login(this.Username, this.Password)
this.UserTryingToLogin.email = this.Email;
this.UserTryingToLogin.password = this.Password;
this._authService.Login(this.UserTryingToLogin)
.pipe(first())
.subscribe(
data => {
@ -101,7 +106,7 @@ export class AppComponent implements OnInit {
this.ConnectedUser = data;
this.Connected = true;
this.DisplayLoginModal = false;
this.Username = null;
this.Email = null;
this.Password = null;
this._authService.IsLoggedIn = true;
this._router.navigate(['/profile/01']);
@ -116,7 +121,7 @@ export class AppComponent implements OnInit {
public Logout() {
this._authService.Logout();
this.Connected = false;
this.Username = null;
this.Email = null;
this.Password = null;
this._authService.IsLoggedIn = false;
this._router.navigate(['/home']);
@ -129,4 +134,27 @@ export class AppComponent implements OnInit {
public GoHome() {
this._router.navigate(['/home']);
}
public CreateProfile() {
// ADD FIELDS VERIFICATION
console.log('GHelfoudlkfhj');
this.CreateUser.deviceIds = [];
this._userService.CreateUser(this.CreateUser)
.subscribe(
data => {
// TO CHANGE
console.log(data);
this.ConnectedUser = data;
this.Connected = true;
this.DisplayLoginModal = false;
this.Email = null;
this.Password = null;
this._authService.IsLoggedIn = true;
// this._router.navigate(['/profile/01']);
},
error => {
console.log('ERROR');
});
}
}

File diff suppressed because one or more lines are too long