2FA Setup Problem

Questions related to using nuBuilder Forte.

2FA Setup Problem

Unread postby stoicprogrammer » Wed Apr 07, 2021 7:54 pm

Hi,
I am experiencing difficulty during 2FA setup.

First of all my email setup works as expected. I have tested it before using 2FA.
2FA also works when this option is activated:
Code: Select all
"nuOutput2FATokenToConsole($token);     // For testing purposes, output the token to the developer console".
I can get a code and it works when I submit.


But when I activate this option:
Code: Select all
nuSendCodeByEmail($token);   // Send the token by email.
It says: "An email has been sent to the registered account. Subject = '".subject."' But I do not receive any code. I tested it on the globel admin account, and on user accounts,
I did not receive any code.


Am I missing something?

Note: when I looked in to system codes, both in nubilder4.sql file, and core system folder , I saw that there are several email sending methods such as built-in php mailing or using phpmailer. and as far as I remember general email set up uses different method than 2FA.
stoicprogrammer
 
Posts: 3
Joined: Thu Jan 21, 2021 4:27 am

Re: 2FA Setup Problem

Unread postby kev1n » Wed Apr 07, 2021 8:47 pm

Hi,

The function nuGetEmail() retrieves the email address from the database. For now you'd have to enter the email for the globeadmin directly in the zzzzsys_user table or
modify the two functions nuGetEmail() and nuSendCodeByEmail() as follows in the nuAuthentication2FA procedure:

Code: Select all
function nuGetEmail($adminEmail = '') {
    $u = nuUser();
    $email = $u->sus_email;
    if ($email == null) $email = $adminEmail;
    return $email;
}

function nuSendCodeByEmail($code) {
    $content = 'Your Code: '.$code;
    $subject = 'nuBuilder Authentication Code';
    $fromName = 'nubuilder';
    $sendTo = nuGetEmail('your_globeadmin_email@something.com'); // <-------------------- Replace with your "globeadmin" email address.
    nuEmailPHP($sendTo, $fromAddress, $fromName, $content, $subject);
    nuDisplayError("An email has been sent to the registered account. Subject = '".subject."'");
}
kev1n
nuBuilder Team
 
Posts: 1623
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5

Re: 2FA Setup Problem

Unread postby stoicprogrammer » Thu Apr 08, 2021 3:44 am

Kev1n,
I have finally figured it out.

I could not make this function work:
Code: Select all
nuEmailPHP()


Instead I used this function:
Code: Select all
nuSendEmail()


The final working code is:
Code: Select all
function nuGetEmail() {
    $u = nuUser();
    if ($u == "" ) return  "your_own_admin@email.com";       // your globe admin email here if you want 2FA for admin.
    return $u->sus_email;   // user email
}

function nuSendCodeByEmail($code) {
    $content = 'Your Code: '.$code;
    $subject = 'nuBuilder Authentication Code';
    $fromName = 'nubuilder';
    $sendTo = nuGetEmail();

    $fromAddress = "setup@email_settings.com";        // the mail used in general -- email settings here. (this variable is referred but missing in the original code, added here.)

    $cc = "some@email.com";               // this parameter is required by the function. if you dont want to use, you can replace it with globe admin email account.
    $bcc = "another@email.com";  // this parameter is required by the function. if you dont want to use, you can replace it with globe admin email account.

// this is the original function used in email setup testing:
//nuSendEmail($to, $fromAddress, $fromName, $body, $subject, array(), true, $cc, $bcc);
//it is adapted here like this:

nuSendEmail($sendTo, $fromAddress, $fromName, $content, $subject, array(), true, $cc, $bcc);


// nuEmailPHP($sendTo, $fromAddress, $fromName, $content, $subject);    ------ old code: it did not work.

    nuDisplayError("An email has been sent to the registered account. Subject = '".$subject."'");
}
//...the following of the code is the same.
stoicprogrammer
 
Posts: 3
Joined: Thu Jan 21, 2021 4:27 am

Re: 2FA Setup Problem

Unread postby kev1n » Thu Apr 08, 2021 3:47 am

Good job :D
kev1n
nuBuilder Team
 
Posts: 1623
Joined: Mon Oct 15, 2018 2:13 am
nuBuilder Version: 4.5


Return to General

Who is online

Users browsing this forum: absalom, GlenMcCabe and 21 guests

cron