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'
constructor (
protected formValidatorService: FormValidatorService,
+ private authService: AuthService,
private userValidatorsService: UserValidatorsService,
private notificationsService: NotificationsService,
private userService: UserService,
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