|
| 1 | +<template> |
| 2 | + <div class="login-page"> |
| 3 | + <div class="login-card"> |
| 4 | + <h1 class="login-title">PredomicsApp</h1> |
| 5 | + <p class="login-subtitle">Microbiome-based classification</p> |
| 6 | + |
| 7 | + <div class="tab-switcher"> |
| 8 | + <button :class="{ active: mode === 'login' }" @click="mode = 'login'">Login</button> |
| 9 | + <button :class="{ active: mode === 'register' }" @click="mode = 'register'">Register</button> |
| 10 | + </div> |
| 11 | + |
| 12 | + <form @submit.prevent="submit"> |
| 13 | + <div v-if="mode === 'register'" class="field"> |
| 14 | + <label>Full Name</label> |
| 15 | + <input v-model="fullName" type="text" placeholder="Your name" /> |
| 16 | + </div> |
| 17 | + <div class="field"> |
| 18 | + <label>Email</label> |
| 19 | + <input v-model="email" type="email" placeholder="email@example.com" required /> |
| 20 | + </div> |
| 21 | + <div class="field"> |
| 22 | + <label>Password</label> |
| 23 | + <input v-model="password" type="password" placeholder="Password" required /> |
| 24 | + </div> |
| 25 | + <p v-if="error" class="error">{{ error }}</p> |
| 26 | + <button type="submit" class="btn-primary" :disabled="loading"> |
| 27 | + {{ loading ? 'Please wait...' : (mode === 'login' ? 'Login' : 'Create Account') }} |
| 28 | + </button> |
| 29 | + </form> |
| 30 | + </div> |
| 31 | + </div> |
| 32 | +</template> |
| 33 | + |
| 34 | +<script setup> |
| 35 | +import { ref } from 'vue' |
| 36 | +import { useRouter } from 'vue-router' |
| 37 | +import { useAuthStore } from '../stores/auth' |
| 38 | +
|
| 39 | +const auth = useAuthStore() |
| 40 | +const router = useRouter() |
| 41 | +
|
| 42 | +const mode = ref('login') |
| 43 | +const email = ref('') |
| 44 | +const password = ref('') |
| 45 | +const fullName = ref('') |
| 46 | +const error = ref('') |
| 47 | +const loading = ref(false) |
| 48 | +
|
| 49 | +async function submit() { |
| 50 | + error.value = '' |
| 51 | + loading.value = true |
| 52 | + try { |
| 53 | + if (mode.value === 'login') { |
| 54 | + await auth.login(email.value, password.value) |
| 55 | + } else { |
| 56 | + await auth.register(email.value, password.value, fullName.value) |
| 57 | + } |
| 58 | + router.push('/projects') |
| 59 | + } catch (e) { |
| 60 | + const detail = e.response?.data?.detail |
| 61 | + error.value = detail || 'Something went wrong. Please try again.' |
| 62 | + } finally { |
| 63 | + loading.value = false |
| 64 | + } |
| 65 | +} |
| 66 | +</script> |
| 67 | +
|
| 68 | +<style scoped> |
| 69 | +.login-page { |
| 70 | + display: flex; |
| 71 | + justify-content: center; |
| 72 | + align-items: center; |
| 73 | + min-height: 80vh; |
| 74 | +} |
| 75 | +
|
| 76 | +.login-card { |
| 77 | + background: white; |
| 78 | + border-radius: 12px; |
| 79 | + padding: 2.5rem; |
| 80 | + width: 100%; |
| 81 | + max-width: 400px; |
| 82 | + box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08); |
| 83 | +} |
| 84 | +
|
| 85 | +.login-title { |
| 86 | + text-align: center; |
| 87 | + color: #1a1a2e; |
| 88 | + font-size: 1.75rem; |
| 89 | + margin-bottom: 0.25rem; |
| 90 | +} |
| 91 | +
|
| 92 | +.login-subtitle { |
| 93 | + text-align: center; |
| 94 | + color: #78909c; |
| 95 | + font-size: 0.9rem; |
| 96 | + margin-bottom: 1.5rem; |
| 97 | +} |
| 98 | +
|
| 99 | +.tab-switcher { |
| 100 | + display: flex; |
| 101 | + gap: 0; |
| 102 | + margin-bottom: 1.5rem; |
| 103 | + border-radius: 8px; |
| 104 | + overflow: hidden; |
| 105 | + border: 1px solid #e0e0e0; |
| 106 | +} |
| 107 | +
|
| 108 | +.tab-switcher button { |
| 109 | + flex: 1; |
| 110 | + padding: 0.6rem; |
| 111 | + border: none; |
| 112 | + background: #f5f5f5; |
| 113 | + color: #78909c; |
| 114 | + font-size: 0.9rem; |
| 115 | + cursor: pointer; |
| 116 | + transition: all 0.2s; |
| 117 | +} |
| 118 | +
|
| 119 | +.tab-switcher button.active { |
| 120 | + background: #1a1a2e; |
| 121 | + color: white; |
| 122 | +} |
| 123 | +
|
| 124 | +.field { |
| 125 | + margin-bottom: 1rem; |
| 126 | +} |
| 127 | +
|
| 128 | +.field label { |
| 129 | + display: block; |
| 130 | + font-size: 0.85rem; |
| 131 | + font-weight: 500; |
| 132 | + color: #546e7a; |
| 133 | + margin-bottom: 0.3rem; |
| 134 | +} |
| 135 | +
|
| 136 | +.field input { |
| 137 | + width: 100%; |
| 138 | + padding: 0.6rem 0.75rem; |
| 139 | + border: 1px solid #e0e0e0; |
| 140 | + border-radius: 6px; |
| 141 | + font-size: 0.9rem; |
| 142 | + outline: none; |
| 143 | + transition: border-color 0.2s; |
| 144 | +} |
| 145 | +
|
| 146 | +.field input:focus { |
| 147 | + border-color: #4fc3f7; |
| 148 | +} |
| 149 | +
|
| 150 | +.error { |
| 151 | + color: #e53935; |
| 152 | + font-size: 0.85rem; |
| 153 | + margin-bottom: 0.75rem; |
| 154 | +} |
| 155 | +
|
| 156 | +.btn-primary { |
| 157 | + width: 100%; |
| 158 | + padding: 0.7rem; |
| 159 | + background: #1a1a2e; |
| 160 | + color: white; |
| 161 | + border: none; |
| 162 | + border-radius: 6px; |
| 163 | + font-size: 0.95rem; |
| 164 | + cursor: pointer; |
| 165 | + transition: background 0.2s; |
| 166 | + margin-top: 0.5rem; |
| 167 | +} |
| 168 | +
|
| 169 | +.btn-primary:hover { |
| 170 | + background: #2d2d4e; |
| 171 | +} |
| 172 | +
|
| 173 | +.btn-primary:disabled { |
| 174 | + opacity: 0.6; |
| 175 | + cursor: not-allowed; |
| 176 | +} |
| 177 | +</style> |
0 commit comments