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
개발이 좋아서/Angular가 좋아서

[Front] - 로그인 및 회원가입(signin, signup)

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

[Front] - 로그인 및 회원가입(signin, signup)

2022. 10. 25. 14:40

1) signin

signin.component.html

<!-- // signin.component.html -->
<div class="wrapper">
  <mat-card>
    <mat-card-title>로그인</mat-card-title>
    <mat-card-content>
      <form [formGroup]="signInForm" (ngSubmit)="submit()">
        <p>
          <mat-form-field>
            <input type="text" matInput placeholder="Id" formControlName="email">
          </mat-form-field>
        </p>
        <p>
          <mat-form-field>
            <input type="password" matInput placeholder="Password" formControlName="pwd">
          </mat-form-field>
        </p>
        <div class="button">
          <button type="submit" mat-stroked-button [disabled]="!signInForm.valid">Login</button>
          <button mat-raised-button color="primary" routerLink="/signup">SignUp</button>
        </div>
      </form>
    </mat-card-content>
  </mat-card>
</div>

signin.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-signin',
  templateUrl: './signin.component.html',
  styleUrls: ['./signin.component.css']
})
export class SigninComponent implements OnInit {

  signInForm: FormGroup;

  constructor(private signService: SignService) {
    this.signInForm = new FormGroup({
      email: new FormControl('', [Validators.required, Validators.email]),
      pwd: new FormControl('', [Validators.required])
    });
   }
   get email() {
    return this.signInForm.get('email');
   }
   get pwd() {
    return this.signInForm.get('pwd');
   }
   submit() {
    if (this.signInForm.valid) {
      this.signService.signIn(this.signInForm.value.email, this.signInForm.value.pwd)
        .then(response => {
          console.log('hohohoho'+response);
        })
        .catch(response => {
          console.log(response);
          alert('로그인에 실패하였습니다 - ' + response.error.msg);
        });
    }
   }

  ngOnInit(): void {
  }

}

2) signup

signup.component.html

<div class="wrapper">
    <mat-card>
        <mat-card-title>회원가입</mat-card-title>
        <form [formGroup]="signUpForm" (ngSubmit)="submit()">
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="Email" formControlName="email">
            </mat-form-field>
          </p>
          <p>
            <mat-form-field>
              <input type="password" matInput placeholder="pwd" formControlName="pwd">
            </mat-form-field>
          </p>
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="name" formControlName="name">
            </mat-form-field>
          </p>
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="phoneNum" formControlName="phoneNum">
            </mat-form-field>
          </p>
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="nickname" formControlName="nickname">
            </mat-form-field>
          </p>
          <p>
            <mat-form-field>
              <input type="text" matInput placeholder="birthdate" formControlName="birthdate">
            </mat-form-field>
          </p>
          <!-- 성별 부분?? -->
          <p>
            gender*  
            남성<input type="radio" formControlName="sex" ng-model="people" value="false"><label></label>
            여성<input type="radio" formControlName="sex" ng-model="people" value="true"><label></label>
          </p>
          <div class="button">
              <button type="submit" mat-raised-button [disabled]="!signUpForm.valid" color="primary">가입</button>
          </div>
        </form>
      </mat-card>
</div>

signup.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-signup',
  templateUrl: './signup.component.html',
  styleUrls: ['./signup.component.css']
})
export class SignupComponent implements OnInit {

  signUpForm: FormGroup;

  constructor(private signService: SignService) {
    this.signUpForm = new FormGroup({
      email: new FormControl('', [Validators.required, Validators.email]),
      pwd: new FormControl('', [Validators.required]),
      name: new FormControl('', [Validators.required]),
      phoneNum: new FormControl('', [Validators.required]),
      nickname: new FormControl('', [Validators.required]),
      birthdate: new FormControl('', [Validators.required]),
      sex: new FormControl('', [Validators.required])
    })
   }

   get f() { return this.signUpForm.controls};

   submit() {
    if (this.signUpForm.valid) {
      this.signService.signUp(this.signUpForm.value.email, this.signUpForm.value.pwd, this.signUpForm.value.name, this.signUpForm.value.phoneNum, this.signUpForm.value.nickname, this.signUpForm.value.birthdate, this.signUpForm.value.sex)
        .then( response => {

        })
        .catch(()=>{alert('실패')});
    }
   }

  ngOnInit(): void {
  }

}

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

[Front] - 로그인 및 회원가입(service/rest-api)  (0) 2022.10.25
[Front] - 로그인 및 회원가입(modules/material, model/common)  (0) 2022.10.25
[Front] - 로그인 및 회원가입(home, info, logout)  (1) 2022.10.25
Angular - 로그인 UI 구현(service, guard)  (0) 2022.09.30
Angular - 회원가입 UI 구현  (0) 2022.09.30

    티스토리툴바

    개인정보

    • 티스토리 홈
    • 포럼
    • 로그인

    단축키

    내 블로그

    내 블로그 - 관리자 홈 전환
    Q
    Q
    새 글 쓰기
    W
    W

    블로그 게시글

    글 수정 (권한 있는 경우)
    E
    E
    댓글 영역으로 이동
    C
    C

    모든 영역

    이 페이지의 URL 복사
    S
    S
    맨 위로 이동
    T
    T
    티스토리 홈 이동
    H
    H
    단축키 안내
    Shift + /
    ⇧ + /

    * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.