implemented account registration
This commit is contained in:
parent
b61bd9c366
commit
baf204bc29
@ -6,6 +6,7 @@ import ru.dragonestia.picker.api.model.account.ResponseAccount;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public interface AccountRepository {
|
||||
|
||||
@ -13,7 +14,7 @@ public interface AccountRepository {
|
||||
|
||||
@NotNull List<ResponseAccount> allAccounts();
|
||||
|
||||
void createAccount(@NotNull String accountId, @NotNull String password);
|
||||
void createAccount(@NotNull String accountId, @NotNull String password, @NotNull Set<String> permissions);
|
||||
|
||||
void removeAccount(@NotNull IAccount account);
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import ru.dragonestia.picker.api.repository.response.AllAccountsResponse;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
public class AccountRepositoryImpl implements AccountRepository {
|
||||
|
||||
@ -40,10 +41,11 @@ public class AccountRepositoryImpl implements AccountRepository {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createAccount(@NotNull String accountId, @NotNull String password) {
|
||||
public void createAccount(@NotNull String accountId, @NotNull String password, @NotNull Set<String> permissions) {
|
||||
rest.query("/accounts", HttpMethod.POST, params -> {
|
||||
params.put("username", accountId);
|
||||
params.put("password", password);
|
||||
params.put("permissions", String.join(",", permissions));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package ru.dragonestia.picker.cp.component;
|
||||
|
||||
import com.vaadin.flow.component.AbstractField;
|
||||
import com.vaadin.flow.component.Unit;
|
||||
import com.vaadin.flow.component.button.Button;
|
||||
import com.vaadin.flow.component.button.ButtonVariant;
|
||||
@ -20,10 +21,8 @@ import ru.dragonestia.picker.api.model.account.ResponseAccount;
|
||||
import ru.dragonestia.picker.api.repository.AccountRepository;
|
||||
import ru.dragonestia.picker.cp.model.Permission;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class AccountList extends VerticalLayout implements RefreshableTable {
|
||||
|
||||
@ -100,13 +99,7 @@ public class AccountList extends VerticalLayout implements RefreshableTable {
|
||||
|
||||
@Override
|
||||
public void refresh() {
|
||||
var list = new ArrayList<ResponseAccount>();
|
||||
for (int i = 0; i < 5; i++) {
|
||||
var acc = new ResponseAccount("test" + i, "", Set.of(), false);
|
||||
list.add(acc);
|
||||
}
|
||||
|
||||
cachedAccounts = list; // TODO: accountRepository.getAllAccounts();
|
||||
cachedAccounts = accountRepository.allAccounts();
|
||||
applySearch(searchField.getValue());
|
||||
}
|
||||
|
||||
@ -167,8 +160,33 @@ public class AccountList extends VerticalLayout implements RefreshableTable {
|
||||
dialog.open();
|
||||
}
|
||||
|
||||
private void validateAndRegister(Dialog dialog, TextField username, PasswordField passwordField, PasswordField confirm, List<PermissionCheckBox> permissionCheckBoxes) {
|
||||
// TODO: validate and send request
|
||||
private void validateAndRegister(Dialog dialog, TextField usernameField, PasswordField passwordField, PasswordField confirmPasswordField, List<PermissionCheckBox> permissionCheckBoxes) {
|
||||
var username = usernameField.getValue().trim();
|
||||
var password = passwordField.getValue();
|
||||
var confirmPassword = confirmPasswordField.getValue();
|
||||
|
||||
if (username.length() < 3 || username.length() > 32) {
|
||||
Notifications.error("Invalid username length. Valid is 3-32");
|
||||
return;
|
||||
}
|
||||
|
||||
if (password.length() < 5 || password.length() > 32) {
|
||||
Notifications.error("Invalid username length. Valid is 5-32");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!password.equals(confirmPassword)) {
|
||||
Notifications.error("Passwords are not equals");
|
||||
return;
|
||||
}
|
||||
|
||||
var permissions = permissionCheckBoxes.stream()
|
||||
.filter(AbstractField::getValue)
|
||||
.map(PermissionCheckBox::getOption)
|
||||
.map(Enum::name)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
accountRepository.createAccount(username, password, permissions);
|
||||
|
||||
dialog.close();
|
||||
refresh();
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
package ru.dragonestia.picker.controller;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
@ -16,6 +17,7 @@ import ru.dragonestia.picker.service.AccountService;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
@Log4j2
|
||||
@RestController
|
||||
@RequestMapping("/accounts")
|
||||
@RequiredArgsConstructor
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user