Merge pull request #32 from lumijiez/front-v2
Fixed user registration, now doesn't crash when no expenses/incomes
This commit was merged in pull request #32.
This commit is contained in:
@@ -19,6 +19,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -90,6 +91,8 @@ public class ExpenseController {
|
|||||||
|
|
||||||
if (!expenses.isEmpty()) {
|
if (!expenses.isEmpty()) {
|
||||||
return ResponseEntity.ok(expenses);
|
return ResponseEntity.ok(expenses);
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.ok(Collections.emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
|||||||
import org.springframework.validation.BindingResult;
|
import org.springframework.validation.BindingResult;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@@ -87,6 +88,8 @@ public class IncomeController {
|
|||||||
|
|
||||||
if (!incomes.isEmpty()) {
|
if (!incomes.isEmpty()) {
|
||||||
return ResponseEntity.ok(incomes);
|
return ResponseEntity.ok(incomes);
|
||||||
|
} else {
|
||||||
|
return ResponseEntity.ok(Collections.emptyList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,36 +1,80 @@
|
|||||||
<script>
|
<script>
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
import * as EmailValidator from 'email-validator';
|
import * as EmailValidator from 'email-validator';
|
||||||
|
import {onMount} from "svelte";
|
||||||
|
import {getCookie, setCookie} from "svelte-cookie";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
let isErrorVisible = false;
|
let isErrorVisible = false;
|
||||||
let username, email, password;
|
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
let username, email, password, name, surname;
|
||||||
let message = ""
|
let message = ""
|
||||||
|
|
||||||
function submitForm(event) {
|
onMount(async () => {
|
||||||
|
|
||||||
|
const access_token = getCookie('access_token');
|
||||||
|
const refresh_token = getCookie('refresh_token');
|
||||||
|
|
||||||
|
if (access_token && refresh_token) {
|
||||||
|
window.location.href = '/dashboard';
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
async function submitForm(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log("Tried to submit!");
|
|
||||||
console.log("Valid? ", (validateEmail() && validateUsername() && validatePassword() ? "Yes" : "No"));
|
try {
|
||||||
|
const data = {
|
||||||
|
firstname: name,
|
||||||
|
lastname: surname,
|
||||||
|
username: username,
|
||||||
|
email: email,
|
||||||
|
password: password,
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(data)
|
||||||
|
|
||||||
|
const response = await axios.post('http://localhost:8081/api/v1/auth/register', data);
|
||||||
|
|
||||||
|
const { access_token, refresh_token } = response.data;
|
||||||
|
|
||||||
|
setCookie('access_token', access_token);
|
||||||
|
setCookie('refresh_token', refresh_token);
|
||||||
|
|
||||||
|
window.location.href = '/dashboard'
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Login failed:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function validateEmail() {
|
// function submitForm(event) {
|
||||||
let valid = EmailValidator.validate(username);
|
// event.preventDefault();
|
||||||
isErrorVisible = valid ? false : true;
|
// // console.log("Tried to submit!");
|
||||||
message = isErrorVisible ? "Invalid e-mail!" : "";
|
// // console.log("Valid? ", (validateEmail() && validateUsername() && validatePassword() ? "Yes" : "No"));
|
||||||
return valid;
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
function validatePassword() {
|
// function validateEmail() {
|
||||||
let valid = password.value != '';
|
// let valid = EmailValidator.validate(username);
|
||||||
isErrorVisible = valid ? false : true;
|
// isErrorVisible = valid ? false : true;
|
||||||
message = isErrorVisible ? "Invalid password!" : "";
|
// message = isErrorVisible ? "Invalid e-mail!" : "";
|
||||||
return valid;
|
// return valid;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
function validateUsername() {
|
// function validatePassword() {
|
||||||
let valid = username.value != '';
|
// let valid = password.value != '';
|
||||||
isErrorVisible = valid ? false : true;
|
// isErrorVisible = valid ? false : true;
|
||||||
message = isErrorVisible ? "Invalid password!" : "";
|
// message = isErrorVisible ? "Invalid password!" : "";
|
||||||
return valid;
|
// return valid;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// function validateUsername() {
|
||||||
|
// let valid = username.value != '';
|
||||||
|
// isErrorVisible = valid ? false : true;
|
||||||
|
// message = isErrorVisible ? "Invalid password!" : "";
|
||||||
|
// return valid;
|
||||||
|
// }
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -45,11 +89,17 @@
|
|||||||
<input id="usernameInput" type="text" name="username" placeholder="Username" autocomplete="off" on:input={
|
<input id="usernameInput" type="text" name="username" placeholder="Username" autocomplete="off" on:input={
|
||||||
event => {username = event.target.value}
|
event => {username = event.target.value}
|
||||||
}>
|
}>
|
||||||
|
<input id="nameInput" type="text" name="name" placeholder="Name" autocomplete="off" on:input={
|
||||||
|
event => {name = event.target.value}
|
||||||
|
}>
|
||||||
|
<input id="surnameInput" type="text" name="surname" placeholder="Surname" autocomplete="off" on:input={
|
||||||
|
event => {surname = event.target.value}
|
||||||
|
}>
|
||||||
<input id="emailInput" type="text" name="email" placeholder="Email" autocomplete="off" on:input={
|
<input id="emailInput" type="text" name="email" placeholder="Email" autocomplete="off" on:input={
|
||||||
event => {email = event.target.value}
|
event => {email = event.target.value}
|
||||||
}>
|
}>
|
||||||
<input id="passwordInput" type="password" name="password" placeholder="Password" autocomplete="off" on:input={
|
<input id="passwordInput" type="password" name="password" placeholder="Password" autocomplete="off" on:input={
|
||||||
event => {password = event.target.password}
|
event => {password = event.target.value}
|
||||||
}>
|
}>
|
||||||
<a href="/auth/recovery" class="recoveryPass">Forgot your password?</a>
|
<a href="/auth/recovery" class="recoveryPass">Forgot your password?</a>
|
||||||
<input type="submit" value="Sign up" class="submitButton">
|
<input type="submit" value="Sign up" class="submitButton">
|
||||||
@@ -75,7 +125,7 @@
|
|||||||
border-top: 10px solid #79a6fe;
|
border-top: 10px solid #79a6fe;
|
||||||
border-bottom: 10px solid #8BD17C;
|
border-bottom: 10px solid #8BD17C;
|
||||||
width: 400px;
|
width: 400px;
|
||||||
height: 600px;
|
height: 750px;
|
||||||
box-shadow: 1px 1px 108.8px 19.2px rgb(25, 31, 53);
|
box-shadow: 1px 1px 108.8px 19.2px rgb(25, 31, 53);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user