Changeset 37307aa


Ignore:
Timestamp:
04/21/26 18:07:57 (3 months ago)
Author:
Andrej <asumanovski@…>
Branches:
master
Children:
89156c1
Parents:
c4c43f3
Message:

env file issue fix

Files:
10 added
4 edited

Legend:

Unmodified
Added
Removed
  • backend/src/main/java/com/trekr/backend/BackendApplication.java

    rc4c43f3 r37307aa  
    44import org.springframework.boot.SpringApplication;
    55import org.springframework.boot.autoconfigure.SpringBootApplication;
     6
     7import java.nio.file.Files;
     8import java.nio.file.Path;
     9import java.nio.file.Paths;
    610
    711@SpringBootApplication
     
    6064        for (String[] candidate : candidates) {
    6165            try {
     66                Path envPath = Paths.get(candidate[0], candidate[1]).normalize();
     67                if (!Files.isRegularFile(envPath)) {
     68                    continue;
     69                }
     70
    6271                Dotenv loaded = Dotenv.configure()
    63                         .directory(candidate[0])
    64                         .filename(candidate[1])
     72                        .directory(envPath.getParent().toString())
     73                        .filename(envPath.getFileName().toString())
    6574                        .ignoreIfMissing()
    6675                        .load();
    67                 if (loaded != null && !loaded.entries().isEmpty()) {
     76                if (loaded != null) {
    6877                    dotenv = loaded;
    6978                    break;
  • db-scripts/ddl.sql

    rc4c43f3 r37307aa  
    2121CREATE TABLE USERS (
    2222    user_id BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
    23     email TEXT NOT NULL,
    24     username TEXT NOT NULL,
     23    email TEXT NOT NULL UNIQUE,
     24    username TEXT NOT NULL UNIQUE,
    2525    password TEXT NOT NULL
    2626);
  • db-scripts/dml.sql

    rc4c43f3 r37307aa  
    22
    33INSERT INTO USERS (user_id, email, username, password) VALUES
    4 (1, 'dimitar@example.com', 'dimitar_arsov', '$2a$10$examplehash1'),
    5 (2, 'filip@example.com', 'filip_gavrilovski', '$2a$10$examplehash2'),
    6 (3, 'marko@example.com', 'marko_markovski', '$2a$10$examplehash3'),
     4(1, 'dimitar@example.com', 'dimitar_arsov', '1234'),
     5(2, 'filip@example.com', 'filip_gavrilovski', '1234'),
     6(3, 'marko@example.com', 'marko_markovski', '1234'),
    77(4, 'andrej.shumanovski@gmail.com', 'andrej_shumanovski', '1234'),
    88(5, 'angelovski.mario222@gmail.com', 'angelovski_mario', '1234'),
    9 (6, 'ana@example.com', 'ana_ilievska', '$2a$10$examplehash6'),
    10 (7, 'petar@example.com', 'petar_stojanov', '$2a$10$examplehash7'),
    11 (8, 'elena@example.com', 'elena_ristova', '$2a$10$examplehash8'),
    12 (9, 'stefan@example.com', 'stefan_nikolov', '$2a$10$examplehash9'),
    13 (10, 'ivana@example.com', 'ivana_karapandzova', '$2a$10$examplehash10'),
     9(6, 'ana@example.com', 'ana_ilievska', '1234'),
     10(7, 'petar@example.com', 'petar_stojanov', '1234'),
     11(8, 'elena@example.com', 'elena_ristova', '1234'),
     12(9, 'stefan@example.com', 'stefan_nikolov', '1234'),
     13(10, 'ivana@example.com', 'ivana_karapandzova', '1234'),
    1414(11, 'nikola@example.com', 'nikola_ivanov', '1234'),
    1515(12, 'marija@example.com', 'marija_petrova', '1234'),
     
    193193
    194194INSERT INTO TRAINING_SESSIONS (training_id, training_user_id, duration, calories, date, type) VALUES
    195 (1, 1, 60, 500, '2026-02-01', 'Running'),
    196 (2, 2, 45, 400, '2026-02-01', 'Cycling'),
    197 (3, 3, 30, 300, '2026-02-01', 'Swimming'),
    198 (4, 4, 50, 420, '2026-02-02', 'HIIT'),
    199 (5, 5, 40, 350, '2026-02-02', 'Strength'),
    200 (6, 6, 35, 280, '2026-02-02', 'Yoga'),
    201 (7, 7, 55, 520, '2026-02-03', 'Running'),
    202 (8, 8, 45, 390, '2026-02-03', 'Cycling'),
    203 (9, 9, 30, 260, '2026-02-03', 'Rowing'),
    204 (10, 10, 60, 480, '2026-02-04', 'Swimming'),
    205 (11, 11, 50, 430, '2026-02-05', 'Strength'),
    206 (12, 12, 40, 310, '2026-02-05', 'Yoga'),
    207 (13, 13, 60, 540, '2026-02-06', 'Running'),
    208 (14, 14, 35, 260, '2026-02-06', 'Pilates'),
    209 (15, 15, 45, 390, '2026-02-07', 'Cycling'),
    210 (16, 16, 55, 460, '2026-02-07', 'HIIT'),
    211 (17, 17, 30, 240, '2026-02-08', 'Rowing'),
    212 (18, 18, 65, 520, '2026-02-08', 'Swimming'),
    213 (19, 19, 50, 440, '2026-02-09', 'Running'),
    214 (20, 20, 45, 370, '2026-02-09', 'Strength'),
    215 (21, 11, 35, 300, '2026-02-12', 'Cycling'),
    216 (22, 13, 30, 260, '2026-02-12', 'Core'),
    217 (23, 15, 70, 600, '2026-02-13', 'Long Run'),
    218 (24, 17, 40, 320, '2026-02-13', 'Strength');
     195(1, 1, 60, 500, '2026-02-01', 'running'),
     196(2, 2, 45, 400, '2026-02-01', 'cycling'),
     197(3, 3, 30, 300, '2026-02-01', 'swimming'),
     198(4, 4, 50, 420, '2026-02-02', 'hiit'),
     199(5, 5, 40, 350, '2026-02-02', 'strength'),
     200(6, 6, 35, 280, '2026-02-02', 'yoga'),
     201(7, 7, 55, 520, '2026-02-03', 'running'),
     202(8, 8, 45, 390, '2026-02-03', 'cycling'),
     203(9, 9, 30, 260, '2026-02-03', 'rowing'),
     204(10, 10, 60, 480, '2026-02-04', 'swimming'),
     205(11, 11, 50, 430, '2026-02-05', 'strength'),
     206(12, 12, 40, 310, '2026-02-05', 'yoga'),
     207(13, 13, 60, 540, '2026-02-06', 'running'),
     208(14, 14, 35, 260, '2026-02-06', 'pilates'),
     209(15, 15, 45, 390, '2026-02-07', 'cycling'),
     210(16, 16, 55, 460, '2026-02-07', 'hiit'),
     211(17, 17, 30, 240, '2026-02-08', 'rowing'),
     212(18, 18, 65, 520, '2026-02-08', 'swimming'),
     213(19, 19, 50, 440, '2026-02-09', 'running'),
     214(20, 20, 45, 370, '2026-02-09', 'strength'),
     215(21, 11, 35, 300, '2026-02-12', 'cycling'),
     216(22, 13, 30, 260, '2026-02-12', 'strength'),
     217(23, 15, 70, 600, '2026-02-13', 'running'),
     218(24, 17, 40, 320, '2026-02-13', 'strength');
    219219
    220220SELECT setval(
  • frontend/src/pages/Register/Register.jsx

    rc4c43f3 r37307aa  
    2121    setError("");
    2222    setIsSubmitting(true);
     23
     24    const normalizedEmail = email.trim().toLowerCase();
     25    const normalizedUsername = username.trim();
     26    const normalizedPassword = password;
     27
     28    if (normalizedUsername.length < 3 || normalizedUsername.length > 50) {
     29      setError("Username must be between 3 and 50 characters");
     30      setIsSubmitting(false);
     31      return;
     32    }
     33
     34    if (normalizedPassword.length < 6) {
     35      setError("Password must be at least 6 characters");
     36      setIsSubmitting(false);
     37      return;
     38    }
     39
    2340    try {
    2441      const res = await api.post("/auth/register", {
    25         email,
    26         username,
    27         password,
     42        email: normalizedEmail,
     43        username: normalizedUsername,
     44        password: normalizedPassword,
    2845      });
    2946      localStorage.setItem("authToken", res.data.token);
     
    3855      navigate("/dashboard");
    3956    } catch (err) {
     57      const fieldErrors = err?.response?.data?.errors ?? {};
     58      const firstFieldError = Object.values(fieldErrors)[0];
    4059      const message =
     60        firstFieldError ||
    4161        err?.response?.data?.message ||
    42         Object.values(err?.response?.data?.errors ?? {})[0] ||
    4362        "Registration failed";
    4463      setError(message);
     
    7594          onChange={(e) => setUsername(e.target.value)}
    7695          autoComplete="username"
     96          minLength={3}
     97          maxLength={50}
    7798          required
    7899        />
     
    86107          onChange={(e) => setPassword(e.target.value)}
    87108          autoComplete="new-password"
     109          minLength={6}
    88110          required
    89111        />
Note: See TracChangeset for help on using the changeset viewer.