APEX如何通过数据库中用户信息验证登陆
小编给大家分享一下APEX如何通过数据库中用户信息验证登陆,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!
1. Custom Authentication in Oracle APEX1.1. IntroductionThis document isbased on:
· Oracle APEX 5.0
· Oracle APEX 5.1.4 测试可用
1.2. Default authentication of APEXAPEX默认登录页是101,默认验证方式APEX用户验证。本文主要测试通过数据库中用户信息进行验证登陆。
1.3. SQL Script1)创建用户信息表USER_ACCOUNT
create table USER_ACCOUNT
(
USER_NAME VARCHAR2(30) not null,
PASSWORD VARCHAR2(30) not null,
USER_TYPE VARCHAR2(10) not null,
ACTIVE VARCHAR2(1) not null,
EMAIL VARCHAR2(64) not null,
FULL_NAME VARCHAR2(64) not null
) ;
alter table USER_ACCOUNT
add constraint USER_ACCOUNT_PK primary key (USER_NAME) ;
alter table USER_ACCOUNT
add constraint USER_ACCOUNT_UK unique (EMAIL) ;
-----------------------------------
insert into user_account (USER_NAME, PASSWORD, USER_TYPE, ACTIVE, EMAIL, FULL_NAME)
values ('tom', 'tom123', 'admin', 'Y', 'tom@example.com', 'Tom');
insert into user_account (USER_NAME, PASSWORD, USER_TYPE,ACTIVE, EMAIL, FULL_NAME)
values ('jerry', 'jerry123', 'user', 'Y', 'jerry@example.com', 'Jerry');
insert into user_account (USER_NAME, PASSWORD, USER_TYPE,ACTIVE, EMAIL, FULL_NAME)
values ('donald', 'donald123', 'guest', 'N', 'donald@example.com', 'Donald');
Commit;
2)创建存储过程PKG_SECURITY
Create Or Replace Package Pkg_Security Is
Function Authenticate_User(p_User_Name Varchar2,p_Password Varchar2) Return Boolean;
-----
Procedure Process_Login(p_User_Name Varchar2
,p_Password Varchar2
,p_App_Id Number);
End Pkg_Security;
/
Create Or Replace Package Body Pkg_Security Is
Function Authenticate_User(p_User_Name Varchar2
,p_Password Varchar2) Return Boolean As
v_Password User_Account.Password%Type;
v_Active User_Account.Active%Type;
v_Email User_Account.Email%Type;
Begin
If p_User_Name Is Null Or p_Password Is Null Then
-- Write to Session, Notification must enter a username and password
Apex_Util.Set_Session_State('LOGIN_MESSAGE','Please enter Username and password.');
Return False;
End If;
----
Begin
Select u.Active
,u.Password
,u.Email
Into v_Active
,v_Password
,v_Email
From User_Account u
Where u.User_Name = p_User_Name;
Exception
When No_Data_Found Then
-- Write to Session, User not found.
Apex_Util.Set_Session_State('LOGIN_MESSAGE','User not found');
Return False;
End;
If v_Password <> p_Password Then
-- Write to Session, Password incorrect.
Apex_Util.Set_Session_State('LOGIN_MESSAGE','Password incorrect');
Return False;
End If;
If v_Active <> 'Y' Then
Apex_Util.Set_Session_State('LOGIN_MESSAGE','User locked, please contact admin');
Return False;
End If;
---
-- Write user information to Session.
--
Apex_Util.Set_Session_State('SESSION_USER_NAME',p_User_Name);
Apex_Util.Set_Session_State('SESSION_EMAIL',v_Email);
---
---
Return True;
End;
--------------------------------------
Procedure Process_Login(p_User_Name Varchar2
,p_Password Varchar2
,p_App_Id Number) As
v_Result Boolean := False;
Begin
v_Result := Authenticate_User(p_User_Name,p_Password);
If v_Result = True Then
-- Redirect to Page 1 (Home Page).
Wwv_Flow_Custom_Auth_Std.Post_Login(p_User_Name -- p_User_Name
,p_Password -- p_Password
,v('APP_SESSION') -- p_Session_Id
,p_App_Id || ':1' -- p_Flow_page
);
Else
-- Login Failure, redirect to page 101 (Login Page).
Owa_Util.Redirect_Url('f?p=&APP_ID.:101:&SESSION.');
End If;
End;
End Pkg_Security;
/
1.4. Declaring Application Items3)在应用程序中,点击“共享组件”》“应用程序项”;
应用程序项定义:
使用应用程序项可以维护会话状态。应用程序项可以通过使用计算, 处理或在 URL 中传递值来设置。使用 "新建实例时" 计算可以为会话设置一次项值。使用应用程序项可以维护未显示并且未指定给任何页的会话状态。
4)点击“创建”按钮:
输入对应属性值:
名称:LOGIN_MESSAGE
范围:Application
然后点击右上方“创建应用程序项”;
应用程序项可在后期被PL/SQL中调用,
如:Apex_Util.Set_Session_State('LOGIN_MESSAGE','Usernot found');
同样,再创建两个应用程序项:
· SESSION_USER_NAME
· SESSION_EMAIL
1.5. Custom Authentication5)在应用程序中编辑“登录页”,登录页页码为101;
6)右击“Content Body”创建新区域。
7)选中新区域,修改属性值:
标识》标题:LOGIN_MESSAGE
标识》类型:静态内容
源》文本:&LOGIN_MESSAGE. 注意结尾带”.”,如没有将不能返回变量值。
服务端条件》类型:项不为空值
服务端条件》项:选择应用程序项:LOGIN_MESSAGE
8)左侧导航栏切换到“处理“标签页,替换”处理“》”处理“》”Login”,修改其中“源”》“PL/SQL 代码”,
默认值:--apex_authentication.login(p_username =>:P101_USERNAME,p_password => :P101_PASSWORD );
替换值:Pkg_Security.Process_Login(:P101_USERNAME,:P101_PASSWORD,:APP_ID);
9)保存并运行测试;
附测试表中用户信息
用户名 用户密码 用户状态
tom tom123 Y
jerry jerry123 Y
donald donald123 N
看完了这篇文章,相信你对“APEX如何通过数据库中用户信息验证登陆”有了一定的了解,如果想了解更多相关知识,欢迎关注亿速云行业资讯频道,感谢各位的阅读!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。