Refactor to manager-centric model, add team calendar for all users
Key changes: - Removed office-centric model (deleted offices.py, office-rules) - Renamed to team-rules, managers are part of their own team - Team calendar visible to all (read-only for employees) - Admins can have a manager assigned
This commit is contained in:
@@ -26,21 +26,42 @@ const api = {
|
||||
},
|
||||
|
||||
/**
|
||||
* Check if user is authenticated
|
||||
* Check if user is authenticated (token or Authelia)
|
||||
*/
|
||||
isAuthenticated() {
|
||||
return !!this.getToken();
|
||||
return !!this.getToken() || this._autheliaAuth;
|
||||
},
|
||||
|
||||
/**
|
||||
* Check authentication - works with both JWT and Authelia
|
||||
* Call this on page load to verify auth status
|
||||
*/
|
||||
async checkAuth() {
|
||||
// Try to get current user - works with Authelia headers or JWT
|
||||
const response = await fetch('/api/auth/me', {
|
||||
headers: this.getToken() ? { 'Authorization': `Bearer ${this.getToken()}` } : {}
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
this._autheliaAuth = true;
|
||||
return await response.json();
|
||||
}
|
||||
|
||||
this._autheliaAuth = false;
|
||||
return null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Redirect to login if not authenticated
|
||||
* Returns user object if authenticated, null otherwise
|
||||
*/
|
||||
requireAuth() {
|
||||
if (!this.isAuthenticated()) {
|
||||
async requireAuth() {
|
||||
const user = await this.checkAuth();
|
||||
if (!user) {
|
||||
window.location.href = '/login';
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
return user;
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -143,11 +164,11 @@ const api = {
|
||||
/**
|
||||
* Register
|
||||
*/
|
||||
async register(email, password, name, officeId = null) {
|
||||
async register(email, password, name) {
|
||||
const response = await fetch('/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ email, password, name, office_id: officeId })
|
||||
body: JSON.stringify({ email, password, name })
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
|
||||
Reference in New Issue
Block a user