General developer forum

Moodle33 - login - how to hide classic form, only show OAuth2 button

 
Picture of Steve Ottevaere
Moodle33 - login - how to hide classic form, only show OAuth2 button
 

Hi everybody,

I plan to migrate my Moodle 3.1 to the 3.3.

After some tests, everything turns well but I want to fine tune the user experience smile

On Moodle 3.1, users accounts were linked to O365 account with oidc module.

In my 3.1, users had to login with the classic form (field username and password) in the login page.



moodle31 login page



In Moodle 3.3, i use the OAuth2 protocol included in the core.

The system works perfect but now users had to click on Microsoft button.


moodle33 login page


My problem :

I want to hide the classic form to prevent users to use it and have a login error.


My idea was to create a customize login page without the classic login form.

But the link to call for the OAuth2 authentification include de sesskey variable (exemple : https://moodle.mysite.be/auth/oauth2/login.php?id=1&wantsurl=%2F&sesskey=XXXXXXXXX).

How can I get this parameter in PHP?


Any ideas?

Thanks,


Steve.

 
Average of ratings: -
Picture of Steve Ottevaere
Re: Moodle33 - login - how to hide classic form, only show OAuth2 button
 

Hello,

I have found a solution.

Here's what I did :

1/
Create a customize login page /home/moodle/login/mycustomizeloginpage.php like this :


-------------------
<?php
require('../config.php');
require_once('lib.php');
?>

<h6 class="m-t-2">My OAuth2 button:</h6>
<a href="<?php print $CFG->wwwroot;?>/auth/oauth2/login.php?id=1&amp;wantsurl=%2F&amp;sesskey=<?php print sesskey();?>" title="Microsoft" class="btn btn-secondary btn-block">
     <img src="https://www.microsoft.com/favicon.ico" alt="" width="24" height="24"/>
           Microsoft
</a>
---------------------

In bold, important things.

2/
Modify your config.php file to use your customize login page.

Add this line to your config.php

$CFG->alternateloginurl='https://moodle.mysite.be/login/mycustomizeloginpage.php';

3/
After that you can, you can design your custom login page with css, small flowers or other things smile

4/
If for a reason or another, the link with your OAuth2 doesn't works, you can always comment de parameter $CFG->alternateloginurl in your config.php to find the default login page and you can connect with a administrator moodle account not linked to a o365 account to resolv your problem


Kind regards,


Steve.

 
Average of ratings: Useful (3)
Picture of Bert van der Hooft
Re: Moodle33 - login - how to hide classic form, only show OAuth2 button
 

I'm not a able tot design a nice login page, So I solved it in the css (see below).

CSS:

.forgetpass {display:none};

#loginbtn {display:none};

#username {display:none};

#password {display:none};

.rememberpass {display:none};

div.col-md-4:nth-child(1) {display:none};

.col-md-4 {

    float: center;

    width: 100%;

};

.btn-block {

    display: block;

    width: 50%;

}


 In order to get access in case of problems:

  1.  Allow theme change by URL. And login with another theme
  2. Or: use the inspector in your browser to remove the css code above

See also: https://moodle.org/mod/forum/discuss.php?d=344478 

Or


 
Average of ratings: Useful (1)