Change URL for 'Log in' button to external page

Change URL for 'Log in' button to external page

by James Pearce -
Number of replies: 10

Hi all,

I want to change the URL for the 'Log in' button on my page to an external page (for OAuth authentication). I need to keep the main moodle/login/ screen active so I don't want to change the Alternate login URL setting in the Site admin>Plugins>Authentication>Manage authentication (so admins can still access this method via the normal url).

In the header.php file, this bit of code seems to manage the url of the 'Log in' button:

<a class="btn btn-cta btn-cta-secondary" href="<?php echo $CFG->wwwroot ?>/login/" ><?php echo get_string('login') ?></a>

What should I alter so I can direct the 'Log in' button to an external site? 

Or could this be done with some Custom CSS code?

Thanks smart people

-----------------------

Moodle = v3.1.2

Theme = Herald v2.3

URL = paramediclearning.org

Average of ratings: -
In reply to James Pearce

Re: Change URL for 'Log in' button to external page

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

<a class="btn btn-cta btn-cta-secondary" href="  ADD YOUR URL HERE     " ><?php echo get_string('login') ?></a>

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Change URL for 'Log in' button to external page

by James Pearce -

Thanks for the quick reply again Mary,

Apparently I can't just forward the URL - the button must be this code:

<?php require_once($CFG->dirroot . '/auth/googleoauth2/lib.php'); auth_googleoauth2_display_buttons(); ?>

Is this able to be done in the below somewhere? 


<div class="info-container col-md-7 col-sm-12 col-xs-12">

                

                <div class="logininfo-container">

                    <?php echo $PAGE->headingmenu ?>

                    

                    <?php if (!isloggedin()) { ?>

                    <a class="btn btn-cta btn-cta-secondary" href=" BUTTON-HERE " ><?php echo get_string('login') ?></a>

                    <?php } ?>                    

                    

                    <?php if (isloggedin()) { ?>

                        <?php echo $OUTPUT->user_menu(); ?> 

                    <?php } ?>

                    

                </div><!--//logininfo-container-->

In reply to James Pearce

Re: Change URL for 'Log in' button to external page

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Well...not really sure.

I don't think this will work but here goes anyway:

Remove these lines:

<?php if (!isloggedin()) { ?>
 <a class="btn btn-cta btn-cta-secondary" href=" ..... " ><?php echo get_string('login') ?></a>
 <?php } ?>

And replace with these lines:

<?php if (!isloggedin()) {
    require_once($CFG->dirroot . '/auth/googleoauth2/lib.php'); 
    auth_googleoauth2_display_buttons();

} ?>

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Change URL for 'Log in' button to external page

by James Pearce -

Worked! Thanks so much Mary.

In reply to James Pearce

Re: Change URL for 'Log in' button to external page

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Now that's a bit of Moodle Magic!

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Change URL for 'Log in' button to external page

by James Pearce -

This might be pushing it but...

Is there any way that the text that code creates "Login with Wild Apricot" could be changed to just simply "Login"?

As you can see its a OAuth2 authentication from a database at Wild Apricot.

Thanks!

In reply to James Pearce

Re: Change URL for 'Log in' button to external page

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

You should be able to change this in your language settings.

Average of ratings: Useful (1)
In reply to James Pearce

Re: Change URL for 'Log in' button to external page

by Mary Evans -
Picture of Core developers Picture of Documentation writers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

Hi James,

Happy New Year!

Im not that familiar with this kind of alternative login, however Emma is on the right track suggesting you should be able to change that langusge string in Site Administration > Language > Language customisation 

I'll try and locate the string name for you.

Cheers

Mary

Average of ratings: Useful (1)
In reply to Mary Evans

Re: Change URL for 'Log in' button to external page

by James Pearce -

Thanks and Happy New Year to you both.

Unfortunately 'Wild Apricot' doesn't appear in the language pack in reference to login (only to do with client ID and key).

Any other ideas much appreciated smile 


In reply to James Pearce

Re: Change URL for 'Log in' button to external page

by James Pearce -

Problem solved! 

Thank you Emma and Mary (once again)!

The sting  was ['signinwithanaccount'] and customised to remove a placeholder

'Log in with {$a}';

Cheers!