회원가입
This commit is contained in:
@@ -22,8 +22,18 @@ function currentUser(token) {
|
||||
});
|
||||
}
|
||||
|
||||
function register(data) {
|
||||
const { email, name, password } = data;
|
||||
return axios({
|
||||
method: 'post',
|
||||
url: '/api/auth/register',
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export default {
|
||||
login,
|
||||
currentUser
|
||||
currentUser,
|
||||
register
|
||||
}
|
||||
@@ -13,7 +13,6 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import axios from "axios";
|
||||
import authApi from "../../api/authApi";
|
||||
|
||||
export default {
|
||||
|
||||
39
src/front/src/pages/auth/Register.vue
Normal file
39
src/front/src/pages/auth/Register.vue
Normal file
@@ -0,0 +1,39 @@
|
||||
<template>
|
||||
<div>
|
||||
<form @submit="register">
|
||||
<input type="email" v-model="email" placeholder="Email">
|
||||
<input type="text" v-model="name" placeholder="Name">
|
||||
<input type="password" v-model="password" placeholder="Password">
|
||||
</form>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import authApi from "../../api/authApi";
|
||||
export default {
|
||||
name: "Register",
|
||||
data() {
|
||||
return {
|
||||
email: '',
|
||||
name: '',
|
||||
password: ''
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
register: async function(evt) {
|
||||
evt.preventDefault();
|
||||
const { email, name, password } = this;
|
||||
try {
|
||||
const result = await authApi.register({email, name, password});
|
||||
console.log(result.data);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -1,8 +1,11 @@
|
||||
package com.example.vue.domain.auth;
|
||||
|
||||
import com.example.vue.domain.user.UserResponseDto;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@@ -19,7 +22,7 @@ public class AuthController {
|
||||
}
|
||||
|
||||
@PostMapping(value = "/register")
|
||||
public void register() {
|
||||
|
||||
public UserResponseDto register(@RequestBody @Valid RegisterRequestDto registerRequestDto) {
|
||||
return authService.register(registerRequestDto);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,12 @@ package com.example.vue.domain.auth;
|
||||
|
||||
import com.example.vue.domain.user.User;
|
||||
import com.example.vue.domain.user.UserRepository;
|
||||
import com.example.vue.domain.user.UserResponseDto;
|
||||
import com.example.vue.util.JwtUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import sun.jvm.hotspot.asm.Register;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -35,4 +37,10 @@ public class AuthService {
|
||||
String token = jwtUtil.createToken(user.getId(), user.getName(), "USER");
|
||||
return new LoginResponseDto(token);
|
||||
}
|
||||
|
||||
public UserResponseDto register(RegisterRequestDto registerRequestDto) {
|
||||
registerRequestDto.setPassword(bCryptPasswordEncoder.encode(registerRequestDto.getPassword()));
|
||||
User user = userRepository.save(new User(registerRequestDto));
|
||||
return new UserResponseDto(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.vue.domain.auth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Data
|
||||
public class RegisterRequestDto {
|
||||
|
||||
@NotNull
|
||||
private String email;
|
||||
|
||||
@NotNull
|
||||
private String name;
|
||||
|
||||
@NotNull
|
||||
private String password;
|
||||
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.example.vue.domain.user;
|
||||
|
||||
import com.example.vue.domain.auth.RegisterRequestDto;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -46,4 +47,10 @@ public class User {
|
||||
this.role = claims.get("role").toString();
|
||||
}
|
||||
|
||||
public User(RegisterRequestDto registerRequestDto) {
|
||||
this.password = registerRequestDto.getPassword();
|
||||
this.email = registerRequestDto.getEmail();
|
||||
this.name = registerRequestDto.getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user