]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/signup/signup.component.ts
Refractor notification service
[github/Chocobozzz/PeerTube.git] / client / src / app / signup / signup.component.ts
index 47f9bc6f4c5e778d8d6e02ffe0c21acc7f0ee428..13941ec79542e978de2e9bb05a63ea0b2b3aeec8 100644 (file)
@@ -1,9 +1,7 @@
 import { Component, OnInit } from '@angular/core'
-import { Router } from '@angular/router'
-import { NotificationsService } from 'angular2-notifications'
+import { AuthService, Notifier, RedirectService, ServerService } from '@app/core'
 import { UserCreate } from '../../../../shared'
 import { FormReactive, UserService, UserValidatorsService } from '../shared'
-import { RedirectService } from '@app/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
 
@@ -13,14 +11,17 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val
   styleUrls: [ './signup.component.scss' ]
 })
 export class SignupComponent extends FormReactive implements OnInit {
+  info: string = null
   error: string = null
+  signupDone = false
 
   constructor (
     protected formValidatorService: FormValidatorService,
+    private authService: AuthService,
     private userValidatorsService: UserValidatorsService,
-    private router: Router,
-    private notificationsService: NotificationsService,
+    private notifier: Notifier,
     private userService: UserService,
+    private serverService: ServerService,
     private redirectService: RedirectService,
     private i18n: I18n
   ) {
@@ -31,6 +32,10 @@ export class SignupComponent extends FormReactive implements OnInit {
     return window.location.host
   }
 
+  get requiresEmailVerification () {
+    return this.serverService.getConfig().signup.requiresEmailVerification
+  }
+
   ngOnInit () {
     this.buildForm({
       username: this.userValidatorsService.USER_USERNAME,
@@ -47,11 +52,24 @@ export class SignupComponent extends FormReactive implements OnInit {
 
     this.userService.signup(userCreate).subscribe(
       () => {
-        this.notificationsService.success(
-          this.i18n('Success'),
-          this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
-        )
-        this.redirectService.redirectToHomepage()
+        this.signupDone = true
+
+        if (this.requiresEmailVerification) {
+          this.info = this.i18n('Welcome! Now please check your emails to verify your account and complete signup.')
+          return
+        }
+
+        // Auto login
+        this.authService.login(userCreate.username, userCreate.password)
+            .subscribe(
+              () => {
+                this.notifier.success(this.i18n('You are now logged in as {{username}}!', { username: userCreate.username }))
+
+                this.redirectService.redirectToHomepage()
+              },
+
+              err => this.error = err.message
+            )
       },
 
       err => this.error = err.message