]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Auto login user on signup
authorChocobozzz <me@florianbigard.com>
Fri, 16 Nov 2018 16:06:19 +0000 (17:06 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 16 Nov 2018 16:06:19 +0000 (17:06 +0100)
client/src/app/signup/signup.component.ts

index 607d648937b164ea1b254c8e7cfac2b63e29455e..3341d4e0943a6f4d65cceffc146898060a3344fc 100644 (file)
@@ -2,7 +2,7 @@ import { Component, OnInit } from '@angular/core'
 import { NotificationsService } from 'angular2-notifications'
 import { UserCreate } from '../../../../shared'
 import { FormReactive, UserService, UserValidatorsService } from '../shared'
-import { RedirectService, ServerService } from '@app/core'
+import { AuthService, RedirectService, ServerService } from '@app/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service'
 
@@ -18,6 +18,7 @@ export class SignupComponent extends FormReactive implements OnInit {
 
   constructor (
     protected formValidatorService: FormValidatorService,
+    private authService: AuthService,
     private userValidatorsService: UserValidatorsService,
     private notificationsService: NotificationsService,
     private userService: UserService,
@@ -59,11 +60,20 @@ export class SignupComponent extends FormReactive implements OnInit {
           return
         }
 
-        this.notificationsService.success(
-          this.i18n('Success'),
-          this.i18n('Registration for {{username}} complete.', { username: userCreate.username })
-        )
-        this.redirectService.redirectToHomepage()
+        // Auto login
+        this.authService.login(userCreate.username, userCreate.password)
+            .subscribe(
+              () => {
+                this.notificationsService.success(
+                  this.i18n('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