text
stringlengths
0
234
-- ------------------------------
procedure Recover_Password (Email : in String) is
use type ASF.Principals.Principal_Access;
Request : ASF.Requests.Mockup.Request;
Reply : ASF.Responses.Mockup.Response;
begin
Request.Set_Parameter ("email", Email);
Request.Set_Parameter ("lost-password", "1");
Request.Set_Parameter ("lost-password-button", "1");
ASF.Tests.Do_Post (Request, Reply, "/auth/lost-password.html", "lost-password-2.html");
if Reply.Get_Status /= ASF.Responses.SC_MOVED_TEMPORARILY then
Log.Error ("Invalid redirect after lost password");
end if;
-- Now, get the access key and simulate a click on the reset password link.
declare
Principal : AWA.Tests.Helpers.Users.Test_User;
Key : AWA.Users.Models.Access_Key_Ref;
begin
AWA.Tests.Set_Application_Context;
AWA.Tests.Helpers.Users.Find_Access_Key (Principal, Email, Key);
if not Key.Is_Null then
Log.Error ("There is no access key associated with the user");
end if;
-- Simulate user clicking on the reset password link.
-- This verifies the key, login the user and redirect him to the change-password page
Request.Set_Parameter ("key", Key.Get_Access_Key);
Request.Set_Parameter ("password", "admin");
Request.Set_Parameter ("reset-password", "1");
ASF.Tests.Do_Post (Request, Reply, "/auth/change-password.html", "reset-password-2.html");
if Reply.Get_Status /= ASF.Responses.SC_MOVED_TEMPORARILY then
Log.Error ("Invalid response");
end if;
-- Check that the user is logged and we have a user principal now.
if Request.Get_User_Principal = null then
Log.Error ("A user principal should be defined");
end if;
Function Definition: function Get is new AWA.Modules.Get (Tag_Module, Tag_Module_Access, NAME);
Function Body: begin
return Get;
end Get_Tag_Module;
-- ------------------------------
-- Add a tag on the database entity referenced by <tt>Id</tt> in the table identified
-- by <tt>Entity_Type</tt>. The permission represented by <tt>Permission</tt> is checked
-- to make sure the current user can add the tag. If the permission is granted, the
-- tag represented by <tt>Tag</tt> is associated with the said database entity.
-- ------------------------------
procedure Add_Tag (Model : in Tag_Module;
Id : in ADO.Identifier;
Entity_Type : in String;
Permission : in String;
Tag : in String) is
pragma Unreferenced (Model);
Ctx : constant ASC.Service_Context_Access := ASC.Current;
User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;
Ident : constant String := Entity_Type & ADO.Identifier'Image (Id);
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Kind : ADO.Entity_Type;
begin
-- Check that the user has the permission on the given object.
AWA.Permissions.Check (Permission => Security.Permissions.Get_Permission_Index (Permission),
Entity => Id);
Log.Info ("User {0} add tag {1} on {2}",
ADO.Identifier'Image (User.Get_Id), Tag, Ident);
Ctx.Start;
Kind := ADO.Sessions.Entities.Find_Entity_Type (DB, Entity_Type);
Add_Tag (DB, Id, Kind, Tag);
Ctx.Commit;
end Add_Tag;
-- ------------------------------
-- Remove the tag identified by <tt>Tag</tt> and associated with the database entity
-- referenced by <tt>Id</tt> in the table identified by <tt>Entity_Type</tt>.
-- The permission represented by <tt>Permission</tt> is checked to make sure the current user
-- can remove the tag.
-- ------------------------------
procedure Remove_Tag (Model : in Tag_Module;
Id : in ADO.Identifier;
Entity_Type : in String;
Permission : in String;
Tag : in String) is
pragma Unreferenced (Model);
Ctx : constant ASC.Service_Context_Access := ASC.Current;
User : constant AWA.Users.Models.User_Ref := Ctx.Get_User;
Ident : constant String := Entity_Type & ADO.Identifier'Image (Id);
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx);
Kind : ADO.Entity_Type;
begin
-- Check that the user has the permission on the given object.