zoaseo
To Infinity And Beyond
zoaseo
전체 방문자
오늘
어제
  • 분류 전체보기 (763)
    • 개발이 좋아서 (381)
      • SAP가 좋아서 (3)
      • Java가 좋아서 (42)
      • Spring이 좋아서 (50)
      • JPA가 좋아서 (0)
      • QueryDSL이 좋아서 (26)
      • Docker가 좋아서 (7)
      • Redis가 좋아서 (7)
      • AWS가 좋아서 (5)
      • CI/CD가 좋아서 (6)
      • Troubleshooting이 좋아서 (4)
      • Kotlin이 좋아서 (7)
      • SQL이 좋아서 (6)
      • HTTP가 좋아서 (21)
      • JavaScript가 좋아서 (30)
      • TypeScript가 좋아서 (6)
      • Vue가 좋아서 (21)
      • Flutter가 좋아서 (61)
      • React가 좋아서 (20)
      • Redux(React)가 좋아서 (2)
      • Angular가 좋아서 (22)
      • HTML이 좋아서 (9)
      • CSS가 좋아서 (15)
      • PHP가 좋아서 (9)
      • Illustrator가 좋아서 (2)
    • 노력이 좋아서 (169)
    • 결과물이 좋아서 (14)
    • 코딩연습이 좋아서 (168)
      • 이론이 좋아서 (62)
      • SQL이 좋아서 (90)
    • 유용한 사이트가 좋아서 (28)
    • Github (2)

인기 글

티스토리

hELLO · Designed By 정상우.
zoaseo

To Infinity And Beyond

개발이 좋아서/Angular가 좋아서

[Front] - 로그인 및 회원가입(home, info, logout)

2022. 10. 25. 14:35

1) home

home.component.ts

2) info

info.component.html

<div class="wrapper">
    <mat-card>
      <mat-card-title>회원정보 조회</mat-card-title>
      <mat-card-content>
        <form [formGroup]="searchForm" (ngSubmit)="submit()">
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="email" formControlName="email">
            </mat-form-field>
          </p>
          <div>
            <mat-card-title>조회결과</mat-card-title>
            <table>
              <tr>
                <td>id:  </td>
                <td>{{member.id}}</td>
              </tr>
              <tr>
                <td>email:  </td>
                <td>{{member.email}}</td>
              </tr>
              <tr>
                <td>name:  </td>
                <td>{{member.name}}</td>
              </tr>
              <tr>
                <td>nickname:  </td>
                <td>{{member.nickname}}</td>
              </tr>
              <tr>
                <td>phoneNum:  </td>
                <td>{{member.phoneNum}}</td>
              </tr>
              <tr>
                <td>regDate:  </td>
                <td>{{member.regDate}}</td>
              </tr>
              <tr>
                <td>sex:  </td>
                <td>
                  {{member.sex ? '여성':'남성' }}
                </td>
              </tr>
            </table>
          </div>
          <div class="button">
            <button mat-raised-button color="primary" [disabled]="!searchForm.valid">조회</button>
          </div>
        </form>
      </mat-card-content>
    </mat-card>
    <mat-card>
      <mat-card-title>로그인 로그 조회</mat-card-title>
      <mat-card-content>
        <p>형식에 맞게 입력해주세요!!!</p>
        <p>ex) 2022-10-07 18:30:00</p>
        <form [formGroup]="searchForm2" (ngSubmit)="submit2()">
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="firstDateTime" formControlName="firstDateTime">
            </mat-form-field>
            <mat-form-field>
              <input type="text" matInput placeholder="endDateTime" formControlName="endDateTime">
            </mat-form-field>
            <mat-form-field>
              <input type="text" matInput placeholder="memberEmail" formControlName="memberEmail">
            </mat-form-field>
          </p>
          <div>
            <mat-card-title>조회결과</mat-card-title>
            <div *ngFor="let log of loginlog">
              {{log}}
            </div>
          </div>
          <div class="button">
            <button mat-raised-button color="primary" [disabled]="!searchForm2.valid">조회</button>
          </div>
        </form>
      </mat-card-content>
    </mat-card>
  </div>

info.component.ts

import { Component, OnInit } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
import { SignService } from 'src/app/service/rest-api/sign.service';

@Component({
  selector: 'app-info',
  templateUrl: './info.component.html',
  styleUrls: ['./info.component.css']
})
export class InfoComponent implements OnInit {

  member = {
    id: '',
    email: '',
    name: '',
    nickname: '',
    phoneNum: '',
    regDate: '',
  };
  memberDefault = {
    id: '',
    email: '',
    name: '',
    nickname: '',
    phoneNum: '',
    regDate: '',
  };

  loginlog: Array<string> = [];

  searchForm: FormGroup;
  searchForm2: FormGroup;

  constructor(protected signService: SignService) {
    this.searchForm = new FormGroup({
      email: new FormControl('', [Validators.required, Validators.email]),
    });
    this.searchForm2 = new FormGroup({
      firstDateTime: new FormControl('', [Validators.required, Validators.pattern(/\d{4}-\d{2}-\d{2}\s\d{2}\:\d{2}\:\d{2}/)]),
      endDateTime: new FormControl('', [Validators.required, Validators.pattern(/\d{4}-\d{2}-\d{2}\s\d{2}\:\d{2}\:\d{2}/)]),
      memberEmail: new FormControl('', [Validators.required, Validators.email]),
    });
    
   }

  submit() {
    if(this.searchForm.valid) {
      //회원정보조회
      this.signService.search(this.searchForm.value.email).subscribe((res)=>{
      
        if(res.body.statusCode == 200) {
          console.log(res);
          alert("조회완료되었습니다");
          this.member.id = res.body.data.id;
          this.member.email = res.body.data.email;
          this.member.name = res.body.data.name;
          this.member.nickname = res.body.data.nickname;
          this.member.phoneNum = res.body.data.phoneNum;
          this.member.regDate = res.body.data.regDate;
        } else if(res.body.statusCode == 400) {
          alert("회원정보가 없습니다");
          this.member = this.memberDefault;
        } else if(res.body.statusCode == 401) {
          sessionStorage.removeItem('x-auth-token');
          alert('세션이 만료되었습니다. 다시 로그인하세요');

        }
    

      }, (err)=> {
        alert('회원정보가 없습니다');
      })
    }
  }
  submit2() {
    if(this.searchForm2.valid) {
      this.signService.searchLog(this.searchForm2.value.firstDateTime, this.searchForm2.value.endDateTime, this.searchForm2.value.memberEmail).subscribe((res)=>{
        var code = res.body.statusCode;
        var obj = res.body.data;
        if(code == 400 && obj == null) {
          alert('가입이 되지 않은 이메일입니다');
          this.loginlog = [];
        } else if(code == 200 && obj.length == 0) {
          alert('입력한 기간내의 로그인 기록이 없습니다');
          this.loginlog = [];
        }  else if(code == 401) {
            sessionStorage.clear();
            alert('세션이 만료되었습니다. 다시 로그인하세요');
          }
        
        else {
          this.loginlog = [];
          alert('조회가 완료되었습니다');
          obj.forEach((e: any) => {
            this.loginlog.push(e.loginDateTime);
          });
        } 
      })
    }
  }

  ngOnInit(): void {
  }

}

3) logout

logout.component.ts

import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  selector: 'app-logout',
  template: '',
})
export class LogoutComponent implements OnInit {

  constructor(private route: Router) {
    alert('로그아웃되었습니다');
    sessionStorage.removeItem('x-auth-token');
    this.route.navigate(['/']);
  }

  ngOnInit(): void {
  }

}

 

'개발이 좋아서 > Angular가 좋아서' 카테고리의 다른 글

[Front] - 로그인 및 회원가입(modules/material, model/common)  (0) 2022.10.25
[Front] - 로그인 및 회원가입(signin, signup)  (0) 2022.10.25
Angular - 로그인 UI 구현(service, guard)  (0) 2022.09.30
Angular - 회원가입 UI 구현  (0) 2022.09.30
Angular - 튜토리얼13_가드(인터셉터)  (0) 2022.09.29

    티스토리툴바