text
stringlengths
0
234
pragma Unreferenced (Data);
Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;
Session : ASF.Sessions.Session := Ctx.Get_Session (Create => True);
begin
Session.Set_Principal (Principal.all'Access);
end Set_Session_Principal;
procedure Set_Authenticate_Cookie (Data : in out Authenticate_Bean;
Principal : in AWA.Users.Principals.Principal_Access) is
Id : constant ADO.Identifier := Principal.Get_Session_Identifier;
Cookie : constant String := Data.Manager.Get_Authenticate_Cookie (Id);
Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;
C : ASF.Cookies.Cookie := ASF.Cookies.Create (ASF.Security.Filters.AID_COOKIE, Cookie);
begin
ASF.Cookies.Set_Path (C, Ctx.Get_Request.Get_Context_Path);
ASF.Cookies.Set_Max_Age (C, 15 * 86400);
Ctx.Get_Response.Add_Cookie (Cookie => C);
end Set_Authenticate_Cookie;
-- ------------------------------
-- Action to authenticate a user (password authentication).
-- ------------------------------
procedure Authenticate_User (Data : in out Authenticate_Bean;
Outcome : in out Unbounded_String) is
Principal : AWA.Users.Principals.Principal_Access;
begin
Data.Manager.Authenticate (Email => To_String (Data.Email),
Password => To_String (Data.Password),
IpAddr => "",
Principal => Principal);
Outcome := To_Unbounded_String ("success");
Data.Set_Session_Principal (Principal);
Data.Set_Authenticate_Cookie (Principal);
exception
when Services.Not_Found =>
Outcome := To_Unbounded_String ("failure");
ASF.Applications.Messages.Factory.Add_Message ("users.login_signup_fail_message");
end Authenticate_User;
-- ------------------------------
-- Helper to send a remove cookie in the current response
-- ------------------------------
procedure Remove_Cookie (Name : in String) is
Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;
C : ASF.Cookies.Cookie := ASF.Cookies.Create (Name, "");
begin
ASF.Cookies.Set_Path (C, Ctx.Get_Request.Get_Context_Path);
ASF.Cookies.Set_Max_Age (C, 0);
Ctx.Get_Response.Add_Cookie (Cookie => C);
end Remove_Cookie;
-- ------------------------------
-- Logout the user and closes the session.
-- ------------------------------
procedure Logout_User (Data : in out Authenticate_Bean;
Outcome : in out Unbounded_String) is
use type ASF.Principals.Principal_Access;
Ctx : constant ASF.Contexts.Faces.Faces_Context_Access := ASF.Contexts.Faces.Current;
Session : ASF.Sessions.Session := Ctx.Get_Session (Create => False);
begin
Outcome := To_Unbounded_String ("success");
-- If there is no session, we are done.
if not Session.Is_Valid then
return;
end if;
declare
Principal : constant ASF.Principals.Principal_Access := Session.Get_Principal;
begin
if Principal /= null and then Principal.all in AWA.Users.Principals.Principal'Class then
declare
P : constant AWA.Users.Principals.Principal_Access :=
AWA.Users.Principals.Principal'Class (Principal.all)'Access;
begin
Data.Manager.Close_Session (Id => P.Get_Session_Identifier,
Logout => True);
exception
when others =>
Log.Error ("Exception when closing user session...");
Function Definition: procedure Dispatch (Manager : in Event_Manager;
Function Body: Queue : in AWA.Events.Queues.Queue_Ref;
Event : in Module_Event'Class) is
procedure Find_Queue (List : in Queue_Dispatcher);
Found : Boolean := False;
procedure Find_Queue (List : in Queue_Dispatcher) is
begin
if List.Queue = Queue then
List.Dispatcher.Dispatch (Event);
Found := True;
end if;