Oracle apex中是否可以验证电子邮件以进行用户注册

时间:2019-01-29 18:10:21

标签: oracle oracle-apex

我正在使用apex 18.2设置Oracle Apex应用程序。

我想通过电子邮件验证实施用户注册过程,例如,如果从应用程序进行用户注册,系统将生成带有验证链接的电子邮件,如果用户单击该链接,则将注册用户以登录到应用程序。

2 个答案:

答案 0 :(得分:1)

不确定Oracle是否开箱即用,但是您始终可以为此创建自定义过程。

您可能需要自定义身份验证功能,自定义用户和未验证的用户表。像这样:

-- This table stores user information.
create table users_tbl ( 
  id number generated always as identity
, username varchar2(30)
, password varchar2(100)
, email_address varchar2(100)
-- etc
);

-- This table stores temporary/unverified user data.
create table unverified_users_tbl ( 
  id number generated always as identity
, username varchar2(30)
, password varchar2(100)
, email_address varchar2(100)
, verification_code varchar2(100) -- you can use sys_guid() function to generate code. also make this unique.
, expiration_date date -- you can set when the verification_code expires
, verified_flag varchar2(1) -- Y/N
-- etc
);

然后创建用于用户注册的公共页面表单,该表单会将数据插入到自定义的unverified_users_tbl中,并发送带有验证链接的电子邮件。可能最好使用一个过程来做这两个。像这样:

我们假设以下内容:

第1页->注册页(公开)  -具有用于用户注册的所有必填字段。

第2页->验证页(公开)  -具有字段P2_VERIFICATION_CODE  -具有“加载页面过程”以验证代码。

以下是有关操作步骤的一些想法:

create procedure register ( p_username in varchar2
                          , p_password in varchar2
                          , p_email_address in varchar2 )
is
  l_verification_code varchar2(100);
  l_subject varchar2(100);
  l_message varchar2(4000);
begin
  insert
    into unverified_users_tbl ( username
                              , password
                              , verification_code
                              , expiration_date )
  values ( p_username
         , encrypt(p_password) -- encrypt password here.
         , sys_guid()
         , sysdate + 1 -- expires after 24 hours )
  returning verification_code 
    into l_verification_code;

  l_subject := 'Verify your account';
  l_message := 'Verify your account by clicking this link. http://your-apex-url/' || apex_util.prepare_url( p_url => 'f?p=YOU_APP_ID:2:::NO::P2_VERIFICATION_CODE:' || l_verification_code );

  -- call your send mail procedure/function here.
  send_mail ( p_email_address, p_subject, p_message );
end;
/

然后在第2页(“验证”页面)上,在“加载”页面过程中执行PL / SQL。像这样:

begin
  if ( verify_code ( :P2_VERIFICATION_CODE ) = true ) then
    -- display verified message
  else
    -- display error message
  end if;
end;
/

-- returns true if verified otherwise returns false
create function verify_code ( p_verification_code ) return boolean
is
begin
  -- check if code exists and not expired.
  update unverified_users_tbl
     set verified_flag = 'Y'
   where verification_code = p_verification_code
     and expiration_date >= sysdate;

  -- sql%rowcount will return the number of records affected in the update statement above.
  -- should not return more than 1 otherwise something went wrong here.
  if ( sql%rowcount = 1 ) then
    -- we're here because we successfully verified the code
    -- copy the record to the users_tbl
    insert
      into users_tbl ( username
                     , password
                     , email_address
                     -- etc
                     )
    select username
         , password
         , email_address
         -- etc
      from unverified_users_tbl
     where verification_code = p_verification_code;

    commit;

    return true;

  else
    -- we're here because the verification_code is either invalid or expired.
    return false;
  end if;

end;
/

您的身份验证功能应针对您的自定义users_tbl进行验证。

您可以参考this进行自定义身份验证。

希望这会有所帮助。

答案 1 :(得分:-1)

步骤1)在让let设为P1_EMAIL的项目上创建验证。

第2步)选择符合条件部分的常规表达式。将此代码输入常规表达式:

/^[a-z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)?@[a-z][a-zA-Z-0-9]*\.[a-z]+(\.[a-z]+)?$/
相关问题