Show error login in my login page custom

Show error login in my login page custom

ដោយ Handerson Medeiros នៅ
ចំនួនតប៖ 11

Hi everybody,

I'm not wanting to use the default login page moodle, so I made a custom. The code is:


            <form class="loginform" name="login" method="post" action="/moodle/login/index.php">
               <p>Username :
                 <input size="10" name="username" />
               </p>
               <p>Password :
                 <input size="10" name="password" type="password" />
               </p>
               <p>
                 <input name="Submit" value="Login" type="submit" />
               </p>
            </form>  


My question is how i make for get e show a error the login os password for the user?

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Handerson Medeiros

Re: Show error login in my login page custom

ដោយ Franco Pantoja នៅ
រូបភាព Particularly helpful Moodlers

Hi


Moodle gives us this variable by GET in the url, 

?errorcode=n


        $errormsg = get_string("cookiesnotenabled");
        $errorcode = 1;
        $errormsg = get_string('username').': '.get_string("invalidusername");
        $errorcode = 2;
        $errormsg = get_string("invalidlogin");
        $errorcode = 3;
    $errormsg = get_string('sessionerroruser', 'error');
    $errorcode = 4;

Do not forget to activate the $CFG->alternateloginurl


Regards!!

មធ្យមភាគនៃរង្វាយតម្លៃ:Useful (1)
ឆ្លើយតបទៅកាន់ Franco Pantoja

Re: Show error login in my login page custom

ដោយ Davi DePaula នៅ

Thank you Paco, 


I used the following code to display a wrong username password message on my custom login page. 


<?php 

if ($_GET["errorcode"] == 3){

   echo '<div class="error_msg">The Username and/or Password entered is invalid, please try again.</div></br>';

}

?>

មធ្យមភាគនៃរង្វាយតម្លៃ:Useful (1)
ឆ្លើយតបទៅកាន់ Davi DePaula

Re: Show error login in my login page custom

ដោយ Tim Hunt នៅ
រូបភាព Core developers រូបភាព Documentation writers រូបភាព Particularly helpful Moodlers រូបភាព Peer reviewers រូបភាព Plugin developers

In Moodle code, you should never access $_GET or $_POST directly. Always use optional_param or required_param instead, with an appropriate PARAM_... type. It does not really matter here, but you should get into good habits. That way you won't start accidentally write in-secure code in future. So, this should be:

if (optional_param('errorcode', 0, PARAM_INT) == 3) {
   echo '<div class="error_msg">The Username and/or Password entered is invalid, please try again.</div></br>';
}

មធ្យមភាគនៃរង្វាយតម្លៃ:Useful (2)
ឆ្លើយតបទៅកាន់ Tim Hunt

Re: Show error login in my login page custom

ដោយ Davi DePaula នៅ

That is a good point, I was going that route, but I couldn't figure out the code to do it that way.  Thank you for the code Tim. 

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Davi DePaula

Re: Show error login in my login page custom

ដោយ Robin Leung នៅ

I tried to implement the code from Tim into my custom login page. But it didn't do anything. Am I missing something?

Thanks.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Robin Leung

Re: Show error login in my login page custom

ដោយ Robin Leung នៅ

Still looking for a solution..

Thanks.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Tim Hunt

Re: Show error login in my login page custom

ដោយ Brandon Jimenez នៅ

Hello, I tried both of your solutions on my login.php and index php (I just recently came to administer this Moodle site), and none of them work.

Ex 1:

if (optional_param('errorcode', 0, PARAM_INT) == 3) {
   echo '<div class="error_msg">The Username and/or Password entered is invalid, please try again.</div></br>';
}

Ex 2:

if ($_GET["errorcode"] == 3){
   echo '<div class="error_msg">The Username and/or Password entered is invalid, please try again.</div></br>';
}

Ex 3:

if ($errorcode == 3) {
   echo '<div class="error_msg">The Username and/or Password entered is invalid, please try again.</div></br>';
}

However, none of them works

I think I'm doing something wrong because I'm not using any customized auth php script, and it should reference the default login process. Even more, I found there and in the moodle.php the appropriate reference to the message it should display in the event of an error. So, what is that I'm missing?

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Davi DePaula

Re: Show error login in my login page custom

ដោយ Robin Leung នៅ

I used this code on my custom login page. But nothing happened.

Am I missing something? Thanks.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Robin Leung

Re: Show error login in my login page custom

ដោយ Sean Marx នៅ
រូបភាព Testers

Hi Robin

I had the same problem today on my Moodle 2.7 localhost dev site. A student could log in, but as admin I could not log in. I have a custom login page as well.

My fix was to go to mdl_user and reset the admin password. In my case I simply changed it to password (5f4dcc3b5aa765d61d8327deb882cf99) and it worked.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ Franco Pantoja

Re: Show error login in my login page custom

ដោយ evan skull នៅ

May I know how to activate the $CFG.

មធ្យមភាគនៃរង្វាយតម្លៃ: -
ឆ្លើយតបទៅកាន់ evan skull

Re: Show error login in my login page custom

ដោយ Yousuf Tafhim នៅ

Include Moodle's config.php file in the login page file. That will activate $CFG

មធ្យមភាគនៃរង្វាយតម្លៃ: -