source: petify-frontend/src/views/SignupView.vue

Last change on this file was 92e7c7a, checked in by veronika-ils <ilioskaveronika@…>, 8 hours ago

Petify fullstack project

  • Property mode set to 100644
File size: 15.5 KB
Line 
1<template>
2 <main class="auth-wrap">
3 <!-- animated blobs -->
4 <div class="blob blob-1" aria-hidden="true"></div>
5 <div class="blob blob-2" aria-hidden="true"></div>
6
7 <div class="auth-card card border-0 shadow-lg">
8 <div class="card-body p-4 p-md-5">
9 <!-- Header -->
10 <div class="d-flex align-items-center gap-3 mb-4">
11 <div class="brand-badge" aria-hidden="true">
12 <!-- paw -->
13 <svg width="22" height="22" viewBox="0 0 24 24" fill="none">
14 <path
15 d="M7.6 10.2c-1.1 0-2-.98-2-2.2s.9-2.2 2-2.2 2 .98 2 2.2-.9 2.2-2 2.2Zm8.8 0c-1.1 0-2-.98-2-2.2s.9-2.2 2-2.2 2 .98 2 2.2-.9 2.2-2 2.2ZM10 8.2c-1 0-1.8-.9-1.8-2s.8-2 1.8-2 1.8.9 1.8 2-.8 2-1.8 2Zm4 0c-1 0-1.8-.9-1.8-2s.8-2 1.8-2 1.8.9 1.8 2-.8 2-1.8 2ZM12 21c-2.6 0-5.6-1.6-5.6-4.5 0-2.2 1.9-3.7 3.9-3.7.8 0 1.4.2 1.7.5.3-.3.9-.5 1.7-.5 2 0 3.9 1.5 3.9 3.7C17.6 19.4 14.6 21 12 21Z"
16 fill="currentColor"
17 opacity=".92"
18 />
19 </svg>
20 </div>
21
22 <div class="flex-grow-1">
23 <h1 class="h4 mb-1 title">Create your account</h1>
24 <p class="text-muted mb-0">Create an account to start using Petify.</p>
25 </div>
26 </div>
27
28 <!-- Alerts -->
29 <div v-if="success" class="alert alert-success auth-alert" role="alert">
30 <strong class="me-1">Done.</strong>{{ success }}
31 </div>
32 <div v-if="error" class="alert alert-danger auth-alert" role="alert">
33 <strong class="me-1">Oops.</strong>{{ error }}
34 </div>
35
36 <form @submit.prevent="submit" class="mt-3">
37 <!-- Username -->
38 <div class="mb-3">
39 <label class="form-label" for="username">Username</label>
40 <div class="input-group auth-input">
41 <span class="input-group-text">
42 <!-- user -->
43 <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
44 <path
45 d="M12 12a4.5 4.5 0 1 0-4.5-4.5A4.5 4.5 0 0 0 12 12Zm0 2.25c-4.42 0-8 2.24-8 5v.75h16v-.75c0-2.76-3.58-5-8-5Z"
46 fill="currentColor"
47 opacity=".85"
48 />
49 </svg>
50 </span>
51 <input
52 id="username"
53 v-model.trim="username"
54 class="form-control"
55 type="text"
56 autocomplete="username"
57 required
58 placeholder="e.g. user_123"
59 />
60 </div>
61 </div>
62
63 <!-- Email -->
64 <div class="mb-3">
65 <label class="form-label" for="email">Email</label>
66 <div class="input-group auth-input">
67 <span class="input-group-text">
68 <!-- mail -->
69 <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
70 <path
71 d="M20 6H4a2 2 0 0 0-2 2v10a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2Zm-.6 3.2-6.9 4.5a1 1 0 0 1-1 0L4.6 9.2A1 1 0 1 1 5.7 7.6L12 11.7l6.3-4.1a1 1 0 1 1 1.1 1.6Z"
72 fill="currentColor"
73 opacity=".85"
74 />
75 </svg>
76 </span>
77 <input
78 id="email"
79 v-model.trim="email"
80 class="form-control"
81 type="email"
82 autocomplete="email"
83 required
84 placeholder="you@petify.com"
85 />
86 </div>
87 </div>
88
89 <!-- First/Last name -->
90 <div class="row g-2">
91 <div class="col-12 col-md-6">
92 <div class="mb-3">
93 <label class="form-label" for="firstName">First name</label>
94 <input
95 id="firstName"
96 v-model.trim="firstName"
97 class="form-control soft-input"
98 type="text"
99 autocomplete="given-name"
100 required
101 placeholder="Name"
102 />
103 </div>
104 </div>
105 <div class="col-12 col-md-6">
106 <div class="mb-3">
107 <label class="form-label" for="lastName">Last name</label>
108 <input
109 id="lastName"
110 v-model.trim="lastName"
111 class="form-control soft-input"
112 type="text"
113 autocomplete="family-name"
114 required
115 placeholder="Surname"
116 />
117 </div>
118 </div>
119 </div>
120
121 <!-- Password + show/hide -->
122 <div class="mb-3">
123 <label class="form-label" for="password">Password</label>
124 <div class="input-group auth-input">
125 <span class="input-group-text">
126 <!-- lock -->
127 <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
128 <path
129 d="M17 10h-1V8a4 4 0 0 0-8 0v2H7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2Zm-7-2a2 2 0 0 1 4 0v2h-4V8Z"
130 fill="currentColor"
131 opacity=".85"
132 />
133 </svg>
134 </span>
135 <input
136 id="password"
137 v-model="password"
138 class="form-control"
139 :type="showPassword ? 'text' : 'password'"
140 autocomplete="new-password"
141 required
142 minlength="6"
143 placeholder="At least 6 characters"
144 />
145 <button
146 class="btn btn-eye"
147 type="button"
148 :aria-label="showPassword ? 'Hide password' : 'Show password'"
149 :title="showPassword ? 'Hide password' : 'Show password'"
150 @click="togglePassword"
151 >
152 <svg v-if="!showPassword" width="18" height="18" viewBox="0 0 24 24" fill="none">
153 <path
154 d="M12 5c5.5 0 9.5 5.5 9.5 7s-4 7-9.5 7S2.5 14.5 2.5 12 6.5 5 12 5Zm0 2C8 7 4.9 10.8 4.9 12S8 17 12 17s7.1-3.8 7.1-5S16 7 12 7Zm0 2.5A2.5 2.5 0 1 1 9.5 12 2.5 2.5 0 0 1 12 9.5Z"
155 fill="currentColor"
156 opacity=".85"
157 />
158 </svg>
159 <svg v-else width="18" height="18" viewBox="0 0 24 24" fill="none">
160 <path
161 d="M3.3 4.7 4.7 3.3l16 16-1.4 1.4-2.3-2.3c-1.4.8-3 1.3-4.9 1.3-5.5 0-9.5-5.5-9.5-7 0-1.2 2.2-4.3 5.7-6.1L3.3 4.7ZM12 7c-.9 0-1.8.2-2.6.5l1.7 1.7c.3-.1.6-.2.9-.2A2.5 2.5 0 0 1 14.5 12c0 .3-.1.6-.2.9l1.7 1.7c.3-.8.5-1.7.5-2.6 0-3-2.4-5-4.5-5Zm0 10c.9 0 1.8-.2 2.6-.5l-1.7-1.7c-.3.1-.6.2-.9.2A2.5 2.5 0 0 1 9.5 12c0-.3.1-.6.2-.9L8 9.4c-.3.8-.5 1.7-.5 2.6 0 3 2.4 5 4.5 5Zm0-12c5.5 0 9.5 5.5 9.5 7 0 .8-1.3 2.8-3.4 4.5l-1.4-1.4c1.7-1.4 2.4-2.8 2.4-3.1 0-1.2-3.1-5-7.1-5-1.2 0-2.3.3-3.3.7L7.2 6.3C8.6 5.5 10.2 5 12 5Z"
162 fill="currentColor"
163 opacity=".85"
164 />
165 </svg>
166 </button>
167 </div>
168 <div class="form-text soft-text">At least 6 characters.</div>
169 </div>
170
171 <!-- Confirm + show/hide (same toggle) -->
172 <div class="mb-2">
173 <label class="form-label" for="confirm">Confirm password</label>
174 <div class="input-group auth-input">
175 <span class="input-group-text">
176 <!-- lock -->
177 <svg width="18" height="18" viewBox="0 0 24 24" fill="none">
178 <path
179 d="M17 10h-1V8a4 4 0 0 0-8 0v2H7a2 2 0 0 0-2 2v7a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-7a2 2 0 0 0-2-2Zm-7-2a2 2 0 0 1 4 0v2h-4V8Z"
180 fill="currentColor"
181 opacity=".85"
182 />
183 </svg>
184 </span>
185 <input
186 id="confirm"
187 v-model="confirm"
188 class="form-control"
189 :type="showPassword ? 'text' : 'password'"
190 autocomplete="new-password"
191 required
192 minlength="6"
193 placeholder="Repeat your password"
194 />
195 <button
196 class="btn btn-eye"
197 type="button"
198 :aria-label="showPassword ? 'Hide password' : 'Show password'"
199 :title="showPassword ? 'Hide password' : 'Show password'"
200 @click="togglePassword"
201 >
202 <svg v-if="!showPassword" width="18" height="18" viewBox="0 0 24 24" fill="none">
203 <path
204 d="M12 5c5.5 0 9.5 5.5 9.5 7s-4 7-9.5 7S2.5 14.5 2.5 12 6.5 5 12 5Zm0 2C8 7 4.9 10.8 4.9 12S8 17 12 17s7.1-3.8 7.1-5S16 7 12 7Zm0 2.5A2.5 2.5 0 1 1 9.5 12 2.5 2.5 0 0 1 12 9.5Z"
205 fill="currentColor"
206 opacity=".85"
207 />
208 </svg>
209 <svg v-else width="18" height="18" viewBox="0 0 24 24" fill="none">
210 <path
211 d="M3.3 4.7 4.7 3.3l16 16-1.4 1.4-2.3-2.3c-1.4.8-3 1.3-4.9 1.3-5.5 0-9.5-5.5-9.5-7 0-1.2 2.2-4.3 5.7-6.1L3.3 4.7ZM12 7c-.9 0-1.8.2-2.6.5l1.7 1.7c.3-.1.6-.2.9-.2A2.5 2.5 0 0 1 14.5 12c0 .3-.1.6-.2.9l1.7 1.7c.3-.8.5-1.7.5-2.6 0-3-2.4-5-4.5-5Zm0 10c.9 0 1.8-.2 2.6-.5l-1.7-1.7c-.3.1-.6.2-.9.2A2.5 2.5 0 0 1 9.5 12c0-.3.1-.6.2-.9L8 9.4c-.3.8-.5 1.7-.5 2.6 0 3 2.4 5 4.5 5Zm0-12c5.5 0 9.5 5.5 9.5 7 0 .8-1.3 2.8-3.4 4.5l-1.4-1.4c1.7-1.4 2.4-2.8 2.4-3.1 0-1.2-3.1-5-7.1-5-1.2 0-2.3.3-3.3.7L7.2 6.3C8.6 5.5 10.2 5 12 5Z"
212 fill="currentColor"
213 opacity=".85"
214 />
215 </svg>
216 </button>
217 </div>
218 </div>
219
220 <!-- Remember me -->
221 <div class="d-flex justify-content-between align-items-center mt-2 mb-3">
222 <span class="small text-muted">You can change details later.</span>
223 </div>
224
225 <!-- CTA -->
226 <button class="btn btn-primary w-100 btn-orange" type="submit" :disabled="loading">
227 <span v-if="loading" class="spinner-border spinner-border-sm me-2" aria-hidden="true"></span>
228 {{ loading ? 'Creating…' : 'Create account' }}
229 </button>
230 </form>
231
232 <div class="d-flex justify-content-between mt-4">
233 <RouterLink class="link subtle" to="/">Back to listings</RouterLink>
234 <RouterLink class="link accent" to="/login">Already have an account?</RouterLink>
235 </div>
236 </div>
237 </div>
238 </main>
239</template>
240
241<script setup lang="ts">
242import { ref } from 'vue'
243import { useRouter } from 'vue-router'
244import { useAuthStore } from '../stores/auth'
245
246const auth = useAuthStore()
247const router = useRouter()
248
249const username = ref('')
250const email = ref('')
251const firstName = ref('')
252const lastName = ref('')
253const password = ref('')
254const confirm = ref('')
255const loading = ref(false)
256const error = ref<string | null>(null)
257const success = ref<string | null>(null)
258
259const showPassword = ref(false)
260
261function togglePassword() {
262 showPassword.value = !showPassword.value
263}
264
265async function submit() {
266 error.value = null
267 success.value = null
268
269 if (password.value !== confirm.value) {
270 error.value = 'Passwords do not match'
271 return
272 }
273
274 loading.value = true
275 try {
276 const result = await auth.signup({
277 username: username.value,
278 email: email.value,
279 password: password.value,
280 firstName: firstName.value,
281 lastName: lastName.value,
282 })
283
284 // Optionally use rememberMe in your store to choose localStorage vs sessionStorage.
285 if (result.tokenReturned) {
286 await router.replace('/')
287 return
288 }
289
290 success.value = 'Account created. Redirecting to login…'
291 setTimeout(() => {
292 router.push('/login')
293 }, 600)
294 } catch (e) {
295 error.value = e instanceof Error ? e.message : String(e)
296 } finally {
297 loading.value = false
298 }
299}
300</script>
301
302<style scoped>
303/* Theme tokens (match login) */
304.auth-wrap {
305 --petify-orange: #ff7a18;
306 --petify-orange-2: #ff9a3d;
307 --petify-ink: #1f2937;
308
309 position: relative;
310 overflow: hidden;
311 min-height: 100vh;
312 display: grid;
313 place-items: center;
314 padding: 3rem 1rem;
315
316 background:
317 radial-gradient(1200px 600px at 15% 0%, rgba(255, 122, 24, 0.18), transparent 60%),
318 radial-gradient(900px 500px at 95% 15%, rgba(255, 154, 61, 0.14), transparent 55%),
319 linear-gradient(180deg, #fff7f0 0%, #ffffff 45%, #ffffff 100%);
320}
321
322/* Animated blobs */
323.blob {
324 position: absolute;
325 width: 520px;
326 height: 520px;
327 border-radius: 999px;
328 filter: blur(42px);
329 opacity: 0.55;
330 pointer-events: none;
331 mix-blend-mode: multiply;
332 animation: floaty 10s ease-in-out infinite;
333 background: radial-gradient(circle at 30% 30%, rgba(255, 122, 24, 0.55), rgba(255, 154, 61, 0.12));
334}
335
336.blob-1 {
337 top: -220px;
338 left: -220px;
339}
340
341.blob-2 {
342 bottom: -240px;
343 right: -240px;
344 animation-delay: -3.5s;
345}
346
347@keyframes floaty {
348 0% {
349 transform: translate3d(0, 0, 0) scale(1);
350 }
351 50% {
352 transform: translate3d(28px, 18px, 0) scale(1.06);
353 }
354 100% {
355 transform: translate3d(0, 0, 0) scale(1);
356 }
357}
358
359/* Card */
360.auth-card {
361 width: 100%;
362 max-width: 520px;
363 border-radius: 18px;
364 overflow: hidden;
365 position: relative;
366 z-index: 1;
367 backdrop-filter: blur(6px);
368}
369
370/* top accent strip */
371.auth-card::before {
372 content: "";
373 position: absolute;
374 inset: 0 0 auto 0;
375 height: 6px;
376 background: linear-gradient(90deg, var(--petify-orange), var(--petify-orange-2));
377}
378
379.title {
380 color: var(--petify-ink);
381 letter-spacing: -0.2px;
382}
383
384.brand-badge {
385 width: 46px;
386 height: 46px;
387 border-radius: 14px;
388 display: grid;
389 place-items: center;
390 color: #fff;
391 background: linear-gradient(135deg, var(--petify-orange), var(--petify-orange-2));
392 box-shadow: 0 10px 25px rgba(255, 122, 24, 0.28);
393}
394
395.auth-alert {
396 border-radius: 12px;
397}
398
399/* Input styling */
400.auth-input .input-group-text {
401 border-radius: 12px 0 0 12px;
402 background: #fff;
403 border-color: rgba(31, 41, 55, 0.12);
404 color: rgba(31, 41, 55, 0.7);
405 border-right: 0;
406}
407
408.auth-input .form-control {
409 border-radius: 0;
410 border-color: rgba(31, 41, 55, 0.12);
411 padding: 0.75rem 0.9rem;
412 border-left: 0;
413}
414
415.auth-input .form-control:focus {
416 box-shadow: 0 0 0 0.25rem rgba(255, 122, 24, 0.18);
417 border-color: rgba(255, 122, 24, 0.55);
418}
419
420/* Soft inputs (for non-group fields) */
421.soft-input {
422 border-radius: 12px;
423 border-color: rgba(31, 41, 55, 0.12);
424 padding: 0.75rem 0.9rem;
425}
426
427.soft-input:focus {
428 box-shadow: 0 0 0 0.25rem rgba(255, 122, 24, 0.18);
429 border-color: rgba(255, 122, 24, 0.55);
430}
431
432.soft-text {
433 color: rgba(31, 41, 55, 0.65);
434}
435
436/* Eye button */
437.btn-eye {
438 border-radius: 0 12px 12px 0;
439 border: 1px solid rgba(31, 41, 55, 0.12);
440 border-left: 0;
441 background: #fff;
442 color: rgba(31, 41, 55, 0.7);
443 padding: 0 0.85rem;
444}
445
446.btn-eye:hover {
447 color: rgba(31, 41, 55, 0.95);
448}
449
450.btn-eye:focus {
451 box-shadow: 0 0 0 0.25rem rgba(255, 122, 24, 0.18);
452}
453
454/* Orange CTA button */
455.btn-orange {
456 border: none;
457 border-radius: 12px;
458 padding: 0.8rem 1rem;
459 font-weight: 600;
460 background: linear-gradient(135deg, var(--petify-orange), var(--petify-orange-2));
461 box-shadow: 0 12px 24px rgba(255, 122, 24, 0.25);
462}
463
464.btn-orange:disabled {
465 opacity: 0.75;
466 box-shadow: none;
467}
468
469.btn-orange:hover {
470 filter: brightness(0.98);
471}
472
473/* Links */
474.link {
475 text-decoration: none;
476}
477
478.link.subtle {
479 color: rgba(31, 41, 55, 0.75);
480}
481
482.link.subtle:hover {
483 color: rgba(31, 41, 55, 0.95);
484}
485
486.link.accent {
487 color: #ff7a18;
488 font-weight: 600;
489}
490
491.link.accent:hover {
492 color: #e76610;
493}
494
495/* Respect reduced motion */
496@media (prefers-reduced-motion: reduce) {
497 .blob {
498 animation: none;
499 }
500}
501</style>
Note: See TracBrowser for help on using the repository browser.