Client: support signup
This commit is contained in:
parent
c36b4ff77e
commit
a184c71b52
|
@ -13,6 +13,7 @@ import { AppState } from './app.service';
|
||||||
import { AccountModule } from './account';
|
import { AccountModule } from './account';
|
||||||
import { CoreModule } from './core';
|
import { CoreModule } from './core';
|
||||||
import { LoginModule } from './login';
|
import { LoginModule } from './login';
|
||||||
|
import { SignupModule } from './signup';
|
||||||
import { SharedModule } from './shared';
|
import { SharedModule } from './shared';
|
||||||
import { VideosModule } from './videos';
|
import { VideosModule } from './videos';
|
||||||
|
|
||||||
|
@ -49,6 +50,7 @@ const APP_PROVIDERS = [
|
||||||
AccountModule,
|
AccountModule,
|
||||||
CoreModule,
|
CoreModule,
|
||||||
LoginModule,
|
LoginModule,
|
||||||
|
SignupModule,
|
||||||
SharedModule,
|
SharedModule,
|
||||||
VideosModule,
|
VideosModule,
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,11 @@
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="!isLoggedIn && isRegistrationEnabled()" id="panel-user-register" class="panel-button">
|
||||||
|
<span class="hidden-xs glyphicon glyphicon-user"></span>
|
||||||
|
<a [routerLink]="['/signup']">Signup</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div *ngIf="isLoggedIn" id="panel-user-account" class="panel-button">
|
<div *ngIf="isLoggedIn" id="panel-user-account" class="panel-button">
|
||||||
<span class="hidden-xs glyphicon glyphicon-user"></span>
|
<span class="hidden-xs glyphicon glyphicon-user"></span>
|
||||||
<a [routerLink]="['/account']">My account</a>
|
<a [routerLink]="['/account']">My account</a>
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
import { AuthService, AuthStatus } from '../auth';
|
import { AuthService, AuthStatus } from '../auth';
|
||||||
|
import { ConfigService } from '../config';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'my-menu',
|
selector: 'my-menu',
|
||||||
|
@ -12,6 +13,7 @@ export class MenuComponent implements OnInit {
|
||||||
|
|
||||||
constructor (
|
constructor (
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
|
private configService: ConfigService,
|
||||||
private router: Router
|
private router: Router
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
@ -33,6 +35,10 @@ export class MenuComponent implements OnInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isRegistrationEnabled() {
|
||||||
|
return this.configService.getConfig().signup.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
isUserAdmin() {
|
isUserAdmin() {
|
||||||
return this.authService.isAdmin();
|
return this.authService.isAdmin();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
import { Http } from '@angular/http';
|
||||||
import 'rxjs/add/operator/catch';
|
import 'rxjs/add/operator/catch';
|
||||||
import 'rxjs/add/operator/map';
|
import 'rxjs/add/operator/map';
|
||||||
|
|
||||||
|
@ -11,6 +12,7 @@ export class UserService {
|
||||||
static BASE_USERS_URL = '/api/v1/users/';
|
static BASE_USERS_URL = '/api/v1/users/';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
private http: Http,
|
||||||
private authHttp: AuthHttp,
|
private authHttp: AuthHttp,
|
||||||
private authService: AuthService,
|
private authService: AuthService,
|
||||||
private restExtractor: RestExtractor
|
private restExtractor: RestExtractor
|
||||||
|
@ -41,4 +43,16 @@ export class UserService {
|
||||||
.map(this.restExtractor.extractDataBool)
|
.map(this.restExtractor.extractDataBool)
|
||||||
.catch((res) => this.restExtractor.handleError(res));
|
.catch((res) => this.restExtractor.handleError(res));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signup(username: string, password: string, email: string) {
|
||||||
|
const body = {
|
||||||
|
username,
|
||||||
|
email,
|
||||||
|
password
|
||||||
|
};
|
||||||
|
|
||||||
|
return this.http.post(UserService.BASE_USERS_URL + 'register', body)
|
||||||
|
.map(this.restExtractor.extractDataBool)
|
||||||
|
.catch(this.restExtractor.handleError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export * from './signup-routing.module';
|
||||||
|
export * from './signup.component';
|
||||||
|
export * from './signup.module';
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
|
||||||
|
import { SignupComponent } from './signup.component';
|
||||||
|
|
||||||
|
const signupRoutes: Routes = [
|
||||||
|
{
|
||||||
|
path: 'signup',
|
||||||
|
component: SignupComponent,
|
||||||
|
data: {
|
||||||
|
meta: {
|
||||||
|
title: 'Signup'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [ RouterModule.forChild(signupRoutes) ],
|
||||||
|
exports: [ RouterModule ]
|
||||||
|
})
|
||||||
|
export class SignupRoutingModule {}
|
|
@ -0,0 +1,40 @@
|
||||||
|
<h3>Signup</h3>
|
||||||
|
|
||||||
|
<div *ngIf="error" class="alert alert-danger">{{ error }}</div>
|
||||||
|
|
||||||
|
<form role="form" (ngSubmit)="signup()" [formGroup]="form">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="username">Username</label>
|
||||||
|
<input
|
||||||
|
type="text" class="form-control" id="username" placeholder="Username"
|
||||||
|
formControlName="username"
|
||||||
|
>
|
||||||
|
<div *ngIf="formErrors.username" class="alert alert-danger">
|
||||||
|
{{ formErrors.username }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input
|
||||||
|
type="text" class="form-control" id="email" placeholder="Email"
|
||||||
|
formControlName="email"
|
||||||
|
>
|
||||||
|
<div *ngIf="formErrors.email" class="alert alert-danger">
|
||||||
|
{{ formErrors.email }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input
|
||||||
|
type="password" class="form-control" id="password" placeholder="Password"
|
||||||
|
formControlName="password"
|
||||||
|
>
|
||||||
|
<div *ngIf="formErrors.password" class="alert alert-danger">
|
||||||
|
{{ formErrors.password }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<input type="submit" value="Signup" class="btn btn-default" [disabled]="!form.valid">
|
||||||
|
</form>
|
|
@ -0,0 +1,72 @@
|
||||||
|
import { Component, OnInit } from '@angular/core';
|
||||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
|
import { NotificationsService } from 'angular2-notifications';
|
||||||
|
|
||||||
|
import { AuthService } from '../core';
|
||||||
|
import {
|
||||||
|
FormReactive,
|
||||||
|
UserService,
|
||||||
|
USER_USERNAME,
|
||||||
|
USER_EMAIL,
|
||||||
|
USER_PASSWORD
|
||||||
|
} from '../shared';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
selector: 'my-signup',
|
||||||
|
templateUrl: './signup.component.html'
|
||||||
|
})
|
||||||
|
export class SignupComponent extends FormReactive implements OnInit {
|
||||||
|
error: string = null;
|
||||||
|
|
||||||
|
form: FormGroup;
|
||||||
|
formErrors = {
|
||||||
|
'username': '',
|
||||||
|
'email': '',
|
||||||
|
'password': ''
|
||||||
|
};
|
||||||
|
validationMessages = {
|
||||||
|
'username': USER_USERNAME.MESSAGES,
|
||||||
|
'email': USER_EMAIL.MESSAGES,
|
||||||
|
'password': USER_PASSWORD.MESSAGES,
|
||||||
|
};
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private formBuilder: FormBuilder,
|
||||||
|
private router: Router,
|
||||||
|
private notificationsService: NotificationsService,
|
||||||
|
private userService: UserService
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
buildForm() {
|
||||||
|
this.form = this.formBuilder.group({
|
||||||
|
username: [ '', USER_USERNAME.VALIDATORS ],
|
||||||
|
email: [ '', USER_EMAIL.VALIDATORS ],
|
||||||
|
password: [ '', USER_PASSWORD.VALIDATORS ],
|
||||||
|
});
|
||||||
|
|
||||||
|
this.form.valueChanges.subscribe(data => this.onValueChanged(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.buildForm();
|
||||||
|
}
|
||||||
|
|
||||||
|
signup() {
|
||||||
|
this.error = null;
|
||||||
|
|
||||||
|
const { username, password, email } = this.form.value;
|
||||||
|
|
||||||
|
this.userService.signup(username, password, email).subscribe(
|
||||||
|
() => {
|
||||||
|
this.notificationsService.success('Success', `Registration for ${username} complete.`);
|
||||||
|
this.router.navigate([ '/videos/list' ]);
|
||||||
|
},
|
||||||
|
|
||||||
|
err => this.error = err.text
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
import { NgModule } from '@angular/core';
|
||||||
|
|
||||||
|
import { SignupRoutingModule } from './signup-routing.module';
|
||||||
|
import { SignupComponent } from './signup.component';
|
||||||
|
import { SharedModule } from '../shared';
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
SignupRoutingModule,
|
||||||
|
SharedModule
|
||||||
|
],
|
||||||
|
|
||||||
|
declarations: [
|
||||||
|
SignupComponent
|
||||||
|
],
|
||||||
|
|
||||||
|
exports: [
|
||||||
|
SignupComponent
|
||||||
|
],
|
||||||
|
|
||||||
|
providers: [
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class SignupModule { }
|
Loading…
Reference in New Issue