This commit is contained in:
geek 2018-06-01 19:16:04 +09:00
parent 8ae4d26843
commit c0135aa1f6
2 changed files with 34 additions and 6 deletions

View File

@ -1,18 +1,26 @@
import { Component, OnInit, Output, EventEmitter, Input } from '@angular/core';
import { FormGroup, FormBuilder, Validators, AbstractControl } from '@angular/forms';
import { Member } from '@overflow/commons-typescript/model/member';
import { Store, select } from '@ngrx/store';
import { Observable, of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
import { MemberService } from '../service/member.service';
import {DomainMember} from '@overflow/commons-typescript/model/domain';
import * as AuthStore from '../../shared/auth/store/auth';
@Component({
selector: 'of-member-signin',
templateUrl: './member-signin.component.html',
})
export class MemberSigninComponent implements OnInit {
@Input() member: Member;
@Input() signinError: string;
domainMember$: Observable<DomainMember>;
pending$: Observable<boolean>;
error$: Observable<any>;
@Input() returnURL;
@Output() resetPassword = new EventEmitter();
@Output() signup = new EventEmitter();
@Output() signin = new EventEmitter<{ email: string, password: string }>();
// @Output() signin = new EventEmitter<{ email: string, password: string }>();
errorMessage: string | null;
@ -22,7 +30,9 @@ export class MemberSigninComponent implements OnInit {
signinForm: FormGroup;
constructor(
private store: Store<any>,
private formBuilder: FormBuilder,
private memberService: MemberService,
) {
}
@ -52,7 +62,25 @@ export class MemberSigninComponent implements OnInit {
signinFormSubmit() {
const formValue = Object.assign({}, this.signinForm.value);
this.signin.emit(formValue);
this.memberService.signin(formValue.email, formValue.password)
.pipe(
tap(() => {
this.pending$ = of(true);
}),
map((r: any) => {
this.domainMember$ = r.domainMember;
r.returnURL = this.returnURL;
this.store.dispatch(new AuthStore.SigninSuccess(r));
}),
catchError(err => {
this.error$ = of(err);
return of();
}),
tap(() => {
this.pending$ = of(false);
}),
).take(1).subscribe();
}
onResetPassword() {

View File

@ -1,6 +1,6 @@
<div class="ui-g">
<div class="ui-g-12 ui-md-9 ui-lg-7">
<of-member-signin-container (signup)="onSignup()" (resetPassword)="onResetPassword()"></of-member-signin-container>
<of-member-signin (signup)="onSignup()" (resetPassword)="onResetPassword()" [returnURL]="returnURL" ></of-member-signin>
</div>
<div class="ui-g-12 ui-md-3 ui-lg-5 login-descript">
<table class="login-table">