PageSourceSearch

https://portail.sonabhy.bf/chunk-QWVMUCHM.js

js sonabhy.bf collected 2026-10-06 16:53:38 UTC 5,238 bytes, 1 lines download raw bytes

1import{f as h}from"./chunk-GNQPTXC7.js";import{a as d}from"./chunk-BQAEME56.js";import{b as p}from"./chunk-2UWCXFRN.js";import{G as i,K as m,O as o,e as c,m as g}from"./chunk-V4GWFIWI.js";import{a as l,b as u}from"./chunk-55GY6K5S.js";var U=["ADMIN"],f=class n{constructor(e,r){this.http=e;this.router=r;this.loadUserFromStorage()}http;router;apiUrl=`${d.apiUrl}/auth`;currentUserSubject=new c(null);currentUser$=this.currentUserSubject.asObservable();tokenExpiryTimer=null;tokenInMemory=null;decodeJwtPayload(e){let r=e.split(".");if(r.length!==3)return null;try{return JSON.parse(atob(r[1]))}catch{return null}}login(e,r,t=!1){return this.http.post(`${this.apiUrl}/login`,{username:e,password:r,rememberMe:t},{withCredentials:!0}).pipe(i(s=>{s.success&&this.setSession(s.data.token,s.data.user)}))}getFormToken(){return this.http.get(`${this.apiUrl}/form-token`)}register(e){return this.http.post(`${this.apiUrl}/register`,e,{withCredentials:!0}).pipe(i(r=>{r.success&&this.setSession(r.data.token,r.data.user)}))}refreshUser(){return this.http.get(`${this.apiUrl}/profile`).pipe(i(e=>{if(e.success&&e.data?.permissions){let r=this.currentUserSubject.value;if(r){let t=u(l({},r),{permissions:e.data.permissions,roles:e.data.roles??r.roles,directions:e.data.directions??r.directions,lectureGlobaleModules:e.data.lectureGlobaleModules??r.lectureGlobaleModules,globalActionPermissions:e.data.globalActionPermissions??r.globalActionPermissions});localStorage.setItem("user",JSON.stringify(t)),this.currentUserSubject.next(t)}}}),g(()=>{}))}checkEmailForReset(e){return this.http.post(`${this.apiUrl}/forgot-password`,{email:e})}resetPassword(e,r){return this.http.post(`${this.apiUrl}/reset-password`,{token:e,newPassword:r})}logout(){this.http.post(`${this.apiUrl}/logout`,{},{withCredentials:!0}).subscribe({error:()=>{}}),this.clearSession(),this.router.navigate(["/accueil"])}logoutExpired(){this.clearSession(),this.router.url.startsWith("/auth")||this.router.navigate(["/auth/login"])}isLoggedIn(){let e=localStorage.getItem("tokenExpiry");return e?parseInt(e,10)*1e3<Date.now()?(this.clearSession(),!1):!!this.currentUserSubject.value:!1}getToken(){return this.tokenInMemory}getCurrentUser(){return this.currentUserSubject.value}updateCurrentUser(e){localStorage.setItem("user",JSON.stringify(e)),this.currentUserSubject.next(e)}getUserRoleAccronymes(e=this.getCurrentUser()){return e?Array.isArray(e.roles)&&e.roles.length?e.roles.map(r=>r.accronyme):e.role?[e.role]:[]:[]}isAdminUser(e=this.getCurrentUser()){return this.getUserRoleAccronymes(e).includes("ADMIN")}hasRole(e){return this.getUserRoleAccronymes().includes(e)}hasAnyRole(e){return this.getUserRoleAccronymes().some(t=>e.includes(t))}hasPermission(e,r){let t=this.getCurrentUser();return t?this.isAdminUser(t)?!0:t.permissions?t.permissions.some(s=>s.module===e&&s.action===r):!1:!1}hasModuleAccess(e){let r=this.getCurrentUser();return r?this.isAdminUser(r)?!0:r.permissions?r.permissions.some(t=>t.module===e):!1:!1}getAccessibleModules(){let e=this.getCurrentUser();return e?this.isAdminUser(e)?["CANDIDATURES","CANDIDATS","STAGE","SUIVI_STAGE","SUSPENSION_STAGE","OFFRE","AIDE","DEMANDE_AUDIENCE","AGENTS","SERVICES"]:e.permissions?Array.from(new Set(e.permissions.map(r=>r.module))):[]:[]}hasLectureGlobale(e){return!!this.getCurrentUser()?.lectureGlobaleModules?.includes(e)}hasGlobalPermission(e,r){return!!this.getCurrentUser()?.globalActionPermissions?.some(t=>t.module===e&&t.action===r)}getUserDirections(){return this.getCurrentUser()?.directions||[]}getUserDirectionAccronyme(){return this.getUserDirections()[0]?.accronyme||null}isSystemRole(){let e=this.getCurrentUser();if(!e)return!1;let r=this.getUserRoleAccronymes(e);return r.some(t=>U.includes(t))||r.includes("CANDIDAT")}getEffectiveDashboardRole(e=this.getCurrentUser()){if(!e)return"";let r=this.getUserRoleAccronymes(e);return r.includes("ADMIN")?"ADMIN":r.includes("CANDIDAT")?"CANDIDAT":e.role||r[0]||""}setSession(e,r){this.tokenInMemory=e,localStorage.setItem("user",JSON.stringify(r));let t=this.decodeJwtPayload(e);t?.exp&&localStorage.setItem("tokenExpiry",String(t.exp)),this.currentUserSubject.next(r),this.scheduleTokenExpiry(e)}loadUserFromStorage(){let e=localStorage.getItem("tokenExpiry"),r=localStorage.getItem("user");if(!e||!r)return;let t=parseInt(e,10);if(t*1e3<Date.now()){localStorage.removeItem("user"),localStorage.removeItem("tokenExpiry");return}try{let s=JSON.parse(r);this.currentUserSubject.next(s);let a=t*1e3-Date.now();a>0&&(this.tokenExpiryTimer=setTimeout(()=>this.logoutExpired(),a))}catch{localStorage.removeItem("user"),localStorage.removeItem("tokenExpiry")}
1}scheduleTokenExpiry(e){this.tokenExpiryTimer&&clearTimeout(this.tokenExpiryTimer);let r=this.decodeJwtPayload(e);if(!r)return;let t=r.exp*1e3-Date.now();t>0&&(this.tokenExpiryTimer=setTimeout(()=>this.logoutExpired(),t))}clearSession(){this.tokenExpiryTimer&&(clearTimeout(this.tokenExpiryTimer),this.tokenExpiryTimer=null),this.tokenInMemory=null,localStorage.removeItem("user"),localStorage.removeItem("tokenExpiry"),this.currentUserSubject.next(null)}static \u0275fac=function(r){return new(r||n)(o(p),o(h))};static \u0275prov=m({token:n,factory:n.\u0275fac,providedIn:"root"})};export{f as a};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.