text stringlengths 0 234 |
|---|
-- ------------------------------ |
-- Initialize the service context. |
-- ------------------------------ |
procedure Initialize (Principal : in out Test_User) is |
begin |
-- Setup the service context. |
Principal.Context.Set_Context (AWA.Tests.Get_Application, null); |
if Principal.Manager = null then |
Principal.Manager := AWA.Users.Modules.Get_User_Manager; |
if Principal.Manager = null then |
Log.Error ("There is no User_Manager in the application."); |
end if; |
end if; |
end Initialize; |
-- ------------------------------ |
-- Create a test user associated with the given email address. |
-- Get an open session for that user. If the user already exists, no error is reported. |
-- ------------------------------ |
procedure Create_User (Principal : in out Test_User; |
Email : in String) is |
DB : ADO.Sessions.Session; |
Query : ADO.SQL.Query; |
Found : Boolean; |
Key : AWA.Users.Models.Access_Key_Ref; |
begin |
Initialize (Principal); |
DB := Principal.Manager.Get_Session; |
-- Find the user |
Query.Set_Join ("inner join awa_email e on e.user_id = o.id"); |
Query.Set_Filter ("e.email = ?"); |
Query.Bind_Param (1, Email); |
Principal.User.Find (DB, Query, Found); |
if not Found then |
Principal.User.Set_First_Name ("Joe"); |
Principal.User.Set_Last_Name ("Pot"); |
Principal.User.Set_Password ("admin"); |
Principal.Email.Set_Email (Email); |
Principal.Manager.Create_User (Principal.User, Principal.Email); |
Find_Access_Key (Principal, Email, Key); |
-- Run the verification and get the user and its session |
Principal.Manager.Verify_User (Key.Get_Access_Key, "192.168.1.1", |
Principal.Principal); |
else |
Principal.Manager.Authenticate (Email => Email, |
Password => "admin", |
IpAddr => "192.168.1.1", |
Principal => Principal.Principal); |
end if; |
Principal.User := Principal.Principal.Get_User; |
Principal.Session := Principal.Principal.Get_Session; |
end Create_User; |
-- ------------------------------ |
-- Create a test user for a new test and get an open session. |
-- ------------------------------ |
procedure Create_User (Principal : in out Test_User) is |
Key : AWA.Users.Models.Access_Key_Ref; |
Email : constant String := "Joe-" & Util.Tests.Get_Uuid & "@gmail.com"; |
begin |
Initialize (Principal); |
Principal.User.Set_First_Name ("Joe"); |
Principal.User.Set_Last_Name ("Pot"); |
Principal.User.Set_Password ("admin"); |
Principal.Email.Set_Email (Email); |
Principal.Manager.Create_User (Principal.User, Principal.Email); |
Find_Access_Key (Principal, Email, Key); |
-- Run the verification and get the user and its session |
Principal.Manager.Verify_User (Key.Get_Access_Key, "192.168.1.1", |
Principal.Principal); |
Principal.User := Principal.Principal.Get_User; |
Principal.Session := Principal.Principal.Get_Session; |
end Create_User; |
-- ------------------------------ |
-- Find the access key associated with a user (if any). |
-- ------------------------------ |
procedure Find_Access_Key (Principal : in out Test_User; |
Email : in String; |
Key : in out AWA.Users.Models.Access_Key_Ref) is |
DB : ADO.Sessions.Session; |
Query : ADO.SQL.Query; |
Found : Boolean; |
Signup_Kind : constant Integer |
:= AWA.Users.Models.Key_Type'Pos (AWA.Users.Models.SIGNUP_KEY); |
Password_Kind : constant Integer |
:= AWA.Users.Models.Key_Type'Pos (AWA.Users.Models.RESET_PASSWORD_KEY); |
begin |
Initialize (Principal); |
DB := Principal.Manager.Get_Session; |
-- Find the access key |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.