Files
orion/static/shop/account/register.html

342 lines
11 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Account - {{ vendor.name }}</title>
<link rel="stylesheet" href="/static/css/shared/base.css">
<link rel="stylesheet" href="/static/css/shared/auth.css">
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
</head>
<body class="auth-page">
<div class="login-container"
x-data="customerRegistration()"
data-vendor-id="{{ vendor.id }}"
data-vendor-name="{{ vendor.name }}"
>
<!-- Header -->
<div class="login-header">
{% if vendor.logo_url %}
<img src="{{ vendor.logo_url }}" alt="{{ vendor.name }}" class="auth-logo">
{% else %}
<div class="auth-logo">🛒</div>
{% endif %}
<h1>Create Account</h1>
<p>Join {{ vendor.name }}</p>
</div>
<!-- Alert Box -->
<div x-show="alert.show"
x-transition
:class="'alert alert-' + alert.type"
x-text="alert.message"
></div>
<!-- Registration Form -->
<form @submit.prevent="handleRegister">
<!-- First Name -->
<div class="form-group">
<label for="firstName">First Name <span class="required">*</span></label>
<input
type="text"
id="firstName"
x-model="formData.first_name"
required
placeholder="Enter your first name"
:class="{ 'error': errors.first_name }"
@input="clearError('first_name')"
>
<div x-show="errors.first_name"
x-text="errors.first_name"
class="error-message show"
></div>
</div>
<!-- Last Name -->
<div class="form-group">
<label for="lastName">Last Name <span class="required">*</span></label>
<input
type="text"
id="lastName"
x-model="formData.last_name"
required
placeholder="Enter your last name"
:class="{ 'error': errors.last_name }"
@input="clearError('last_name')"
>
<div x-show="errors.last_name"
x-text="errors.last_name"
class="error-message show"
></div>
</div>
<!-- Email -->
<div class="form-group">
<label for="email">Email Address <span class="required">*</span></label>
<input
type="email"
id="email"
x-model="formData.email"
required
placeholder="your@email.com"
:class="{ 'error': errors.email }"
@input="clearError('email')"
>
<div x-show="errors.email"
x-text="errors.email"
class="error-message show"
></div>
</div>
<!-- Phone (Optional) -->
<div class="form-group">
<label for="phone">Phone Number</label>
<input
type="tel"
id="phone"
x-model="formData.phone"
placeholder="+352 123 456 789"
>
</div>
<!-- Password -->
<div class="form-group">
<label for="password">Password <span class="required">*</span></label>
<div class="password-group">
<input
:type="showPassword ? 'text' : 'password'"
id="password"
x-model="formData.password"
required
placeholder="At least 8 characters"
:class="{ 'error': errors.password }"
@input="clearError('password')"
>
<button
type="button"
class="password-toggle"
@click="showPassword = !showPassword"
>
<span x-text="showPassword ? '👁️' : '👁️‍🗨️'"></span>
</button>
</div>
<div class="form-help">
Must contain at least 8 characters, one letter, and one number
</div>
<div x-show="errors.password"
x-text="errors.password"
class="error-message show"
></div>
</div>
<!-- Confirm Password -->
<div class="form-group">
<label for="confirmPassword">Confirm Password <span class="required">*</span></label>
<input
:type="showPassword ? 'text' : 'password'"
id="confirmPassword"
x-model="confirmPassword"
required
placeholder="Re-enter your password"
:class="{ 'error': errors.confirmPassword }"
@input="clearError('confirmPassword')"
>
<div x-show="errors.confirmPassword"
x-text="errors.confirmPassword"
class="error-message show"
></div>
</div>
<!-- Marketing Consent -->
<div class="form-group">
<div class="remember-me">
<input
type="checkbox"
id="marketingConsent"
x-model="formData.marketing_consent"
>
<label for="marketingConsent" style="font-weight: normal;">
I'd like to receive news and special offers
</label>
</div>
</div>
<!-- Submit Button -->
<button
type="submit"
class="btn-login"
:disabled="loading"
>
<span x-show="loading" class="loading-spinner"></span>
<span x-text="loading ? 'Creating Account...' : 'Create Account'"></span>
</button>
</form>
<!-- Login Link -->
<div class="login-footer">
<div class="auth-footer-text">Already have an account?</div>
<a href="/shop/account/login">Sign in instead</a>
</div>
</div>
<script>
function customerRegistration() {
return {
// Data
formData: {
first_name: '',
last_name: '',
email: '',
phone: '',
password: '',
marketing_consent: false
},
confirmPassword: '',
showPassword: false,
loading: false,
errors: {},
alert: {
show: false,
type: 'error',
message: ''
},
// Get vendor data from element
get vendorId() {
return this.$el.dataset.vendorId;
},
get vendorName() {
return this.$el.dataset.vendorName;
},
// Clear specific error
clearError(field) {
delete this.errors[field];
},
// Clear all errors
clearAllErrors() {
this.errors = {};
this.alert.show = false;
},
// Show alert
showAlert(message, type = 'error') {
this.alert = {
show: true,
type: type,
message: message
};
// Auto-hide success messages
if (type === 'success') {
setTimeout(() => {
this.alert.show = false;
}, 3000);
}
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
},
// Validate form
validateForm() {
this.clearAllErrors();
let isValid = true;
// First name
if (!this.formData.first_name.trim()) {
this.errors.first_name = 'First name is required';
isValid = false;
}
// Last name
if (!this.formData.last_name.trim()) {
this.errors.last_name = 'Last name is required';
isValid = false;
}
// Email
if (!this.formData.email.trim()) {
this.errors.email = 'Email is required';
isValid = false;
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(this.formData.email)) {
this.errors.email = 'Please enter a valid email address';
isValid = false;
}
// Password
if (!this.formData.password) {
this.errors.password = 'Password is required';
isValid = false;
} else if (this.formData.password.length < 8) {
this.errors.password = 'Password must be at least 8 characters';
isValid = false;
} else if (!/[a-zA-Z]/.test(this.formData.password)) {
this.errors.password = 'Password must contain at least one letter';
isValid = false;
} else if (!/[0-9]/.test(this.formData.password)) {
this.errors.password = 'Password must contain at least one number';
isValid = false;
}
// Confirm password
if (this.formData.password !== this.confirmPassword) {
this.errors.confirmPassword = 'Passwords do not match';
isValid = false;
}
return isValid;
},
// Handle registration
async handleRegister() {
if (!this.validateForm()) {
return;
}
this.loading = true;
try {
const response = await fetch(
`/api/v1/public/vendors/${this.vendorId}/customers/register`,
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(this.formData)
}
);
const data = await response.json();
if (!response.ok) {
throw new Error(data.detail || 'Registration failed');
}
// Success!
this.showAlert(
'Account created successfully! Redirecting to login...',
'success'
);
// Redirect to login after 2 seconds
setTimeout(() => {
window.location.href = '/shop/account/login?registered=true';
}, 2000);
} catch (error) {
console.error('Registration error:', error);
this.showAlert(error.message || 'Registration failed. Please try again.');
} finally {
this.loading = false;
}
}
}
}
</script>
</body>
</html>