added signup
This commit is contained in:
parent
d47e866492
commit
464d7f112b
@ -43,6 +43,9 @@ export default {
|
||||
localStorage.removeItem("token");
|
||||
localStorage.removeItem("user");
|
||||
this.getUserInfo();
|
||||
},
|
||||
toSignup() {
|
||||
this.$router.push("/signup");
|
||||
}
|
||||
},
|
||||
data() {
|
||||
@ -86,4 +89,7 @@ export default {
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
<div class="mt-3">
|
||||
<button class="btn btn-outline-secondary" @click.prevent="toSignup">Регистрация</button>
|
||||
</div>
|
||||
</template>
|
51
frontend/src/components/Signup.vue
Normal file
51
frontend/src/components/Signup.vue
Normal file
@ -0,0 +1,51 @@
|
||||
<script>
|
||||
import axios from "axios";
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
data: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
async createUser() {
|
||||
const response = await axios.post("http://localhost:8080/signup", this.toJSON(this.data));
|
||||
if (response.data !== "error") {
|
||||
this.$router.push("/login");
|
||||
} else {
|
||||
document.getElementById('error').value = "Error!";
|
||||
}
|
||||
},
|
||||
toJSON(data) {
|
||||
const jsonObj = {};
|
||||
const fields = Object.getOwnPropertyNames(data);
|
||||
for (const field of fields) {
|
||||
if (data[field] === undefined) {
|
||||
continue;
|
||||
}
|
||||
jsonObj[field] = data[field];
|
||||
}
|
||||
return jsonObj;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="mb-3">
|
||||
<input type="text" name="login" class="form-control"
|
||||
placeholder="Логин" required="true" autofocus="true" maxlength="64" v-model="data.login"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" name="password" class="form-control"
|
||||
placeholder="Пароль" required="true" minlength="6" maxlength="64" v-model="data.password"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<input type="password" name="passwordConfirm" class="form-control"
|
||||
placeholder="Пароль (подтверждение)" required="true" minlength="6" maxlength="64" v-model="data.passwordConfirm"/>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<button type="submit" class="btn btn-success button-fixed" @click.prevent="createUser">Создать</button>
|
||||
<a class="btn btn-primary button-fixed" href="/login">Назад</a>
|
||||
</div>
|
||||
<p id="error"></p>
|
||||
</template>
|
@ -6,13 +6,15 @@ import Cabinets from './components/Cabinets.vue'
|
||||
import Computers from './components/Computers.vue'
|
||||
import Monitors from './components/Monitors.vue'
|
||||
import Login from "./components/Login.vue";
|
||||
import Signup from "@/components/Signup.vue";
|
||||
|
||||
const routes = [
|
||||
{ path: '/', redirect: '/cabinets' },
|
||||
{ path: '/cabinets', component: Cabinets, meta: { label: 'Кабинеты' } },
|
||||
{ path: '/computers', component: Computers, meta: { label: 'Компьютеры' } },
|
||||
{ path: '/monitors', component: Monitors, meta: { label: 'Мониторы' } },
|
||||
{ path: '/login', component: Login}
|
||||
{ path: '/login', component: Login},
|
||||
{ path: '/signup', component: Signup}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
|
@ -2,6 +2,7 @@ package com.kalyshev.yan.configuration;
|
||||
|
||||
import com.kalyshev.yan.configuration.jwt.JwtFilter;
|
||||
import com.kalyshev.yan.user.controller.UserController;
|
||||
import com.kalyshev.yan.user.controller.UserSignupController;
|
||||
import com.kalyshev.yan.user.model.UserRole;
|
||||
import com.kalyshev.yan.user.service.UserService;
|
||||
import org.slf4j.Logger;
|
||||
@ -44,6 +45,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
.authorizeRequests()
|
||||
.antMatchers("/", SPA_URL_MASK).permitAll()
|
||||
.antMatchers(HttpMethod.POST, UserController.URL_LOGIN).permitAll()
|
||||
.antMatchers(HttpMethod.POST, UserSignupController.URL_LOGIN).permitAll()
|
||||
.anyRequest()
|
||||
.authenticated()
|
||||
.and()
|
||||
|
@ -1,24 +1,32 @@
|
||||
package com.kalyshev.yan.user.controller;
|
||||
|
||||
import com.kalyshev.yan.user.model.User;
|
||||
import com.kalyshev.yan.user.service.UserService;
|
||||
import com.kalyshev.yan.util.validation.ValidationException;
|
||||
import org.springframework.stereotype.Controller;
|
||||
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;
|
||||
|
||||
@Controller
|
||||
@RequestMapping(UserSignupController.SIGNUP_URL)
|
||||
@RestController
|
||||
public class UserSignupController {
|
||||
public static final String SIGNUP_URL = "/signup";
|
||||
public static final String URL_LOGIN = "/signup";
|
||||
private final UserService userService;
|
||||
public UserSignupController(UserService userService) {
|
||||
this.userService = userService;
|
||||
}
|
||||
@PostMapping
|
||||
public UserDto signup(@RequestBody @Valid UserSignupDto userSignupDto) {
|
||||
return new UserDto(userService.createUser(
|
||||
userSignupDto.getLogin(), userSignupDto.getPassword(), userSignupDto.getPasswordConfirm()));
|
||||
@PostMapping(URL_LOGIN)
|
||||
public String signup(@RequestBody @Valid UserSignupDto userSignupDto) {
|
||||
try {
|
||||
final User user = userService.createUser(
|
||||
userSignupDto.getLogin(), userSignupDto.getPassword(), userSignupDto.getPasswordConfirm());
|
||||
return user.getLogin();
|
||||
} catch (ValidationException e) {
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user