How to pre-populate and hide site URL entry page?

How to pre-populate and hide site URL entry page?

Yezi Yang發表於
Number of replies: 17

I do some customise on the Moodle mobile 2 and create an app for the higher education institution I work in. I meet a problem now. Since my institution has only one Moodle site, I want to set the Moodle site URL my institution use as a default URL and hide the page of typing in URL from users.



I also tried the way that mentioned on Moodle mobile customise guide written by Juan Leyva of changing the initial screen (add site) on page 20 (https://docs.google.com/presentation/d/1HX5h7zwtay4amaY3qyLuCLfI7kQCiD9IoWuDH-lSa_0/edit?pli=1#slide=id.gb58f8c5e5_0_101). However, it seems not work when I test the app with Google Chromium.


The following is the original code before I do any changes:



Here is the code after I change it, according to the guide:





I would be very grateful if someone can help me with it. I am sure this function is also very useful for developers in some other institutions.


評比平均分數: -
In reply to Yezi Yang

Re: How to pre-populate and hide site URL entry page?

Dani Palou發表於
Core developers的相片 Moodle HQ的相片 Peer reviewers的相片 Plugin developers的相片

Hello Yezi,

you shouldn't change the url properties of those states. Those url are internal URLs for the app to work, they aren't the URL of your Moodle site. The only thing you need to change to make it work is adding the onEnter property to the mm_login.site state, you don't need to change mm_login.sites state at all.

.state('mm_login.site', {
    url: '/site',
    templateUrl: 'core/components/login/templates/site.html',
    controller: 'mmLoginSiteCtrl',
    onEnter: function($state) {
        $state.go('mm_login.credentials', {siteurl: 'http://mymoodle.com'});
    }

})

That should be enough to make it work.

In any case, please notice that it's a basic example to make it work. The best solution would be to:

  1. Delete mm_login.site state.
  2. Change all the mm_login.site references to mm_login.credentials.
  3. In mmLoginCredentialsCtrl, hardcode your siteurl instead of getting it from $stateParams.

If you have any doubt or you still have problems with this please let us know.

Cheers,

Dani

評比平均分數:Useful (1)
In reply to Dani Palou

Re: How to pre-populate and hide site URL entry page?

Yezi Yang發表於

Dear Daniel,

Thank you very much for your help! Your solution works very well! 

I just add the following code to mm.login.sites and change the "siteurl" of the code to my Moodle site. It skip the url entry process and goes to username and password type in page immediately. 

"  onEnter: function($state) {
        $state.go('mm_login.credentials', {siteurl: 'http://mymoodle.com'});
    }
"


Again, it is a big problem for our institution. Your solution really helps a lot. Thank you very much!

In reply to Yezi Yang

Re: How to pre-populate and hide site URL entry page?

charles talathoti發表於
Hi Yezi,


Daniel suggested to edit site while leaving sites alone. But you said that you edited sites. Which one did you do? I am stuck in the same situation. It would help a lot.

In reply to Dani Palou

Re: How to pre-populate and hide site URL entry page?

Yezi Yang發表於

Dear Daniel, 

Thank you very much for your reply. It does help me skip the entrance URL typing. 

What I do is add the code you mentioned in the reply to the build/mm.bundle.js:


.state('mm_login.site', {
url: '/site',
templateUrl: 'core/components/login/templates/site.html',
controller: 'mmLoginSiteCtrl',
/**-------------------------------add code start----------------------------------------------*/
onEnter: function($state) {
$state.go('mm_login.credentials', {siteurl: 'http://xxx.xxx.edu.cn'});  // (here is my institution Moodle URL)

/**--------------------------add code end---------------------------------------------------*/
})


However, the code you provide seems cause another problem. After add the code, the "Grades" icons where a list of courses a user has is lost, as can be seen below.



Before I add the code, the page is shown as below. (I hide some other icons which are unnecessary to my institution.)




Since "Grades" is quite an important function for both our students and staff to check their personal and overall grades, I really do not want to loss the function. So I wondered whether you know how to both have re-populate and hide entry URL, as well as have the "grades" function. 


In addition, there is a Moodle mobile developer contact me personally about how to re-populating and hiding entry URL. So I am quite sure it is a problem that many developers are facing. It is a very useful function and can also help many people if it is solved. Thank you very much for your help!

In reply to Dani Palou

Re: How to pre-populate and hide site URL entry page?

Carlos Villalpando發表於

Hi. 

I'm having the same problem as Yezi. I want to "hide" the login page during the first load. I want the user to be directed directly to the page where you put your username and password. I had already add the property onEnter to the mm_login.site state, but when I open the application, It still request the site URL of my moodle.

I haven't tried the second option, which is hard coding the siteURL from $stateParams. I want to make it work using the first solution. 

This is my state:

.state('mm_login.site', { 

        url: '/site', 

        templateUrl: 'core/components/login/templates/site.html',

        controller: 'mmLoginSiteCtrl',

        onEnter: function($state) {

            $state.go('mm_login.credentials', {siteurl: 'http://xxxxx.xxxxxx.com'});

        }

    })

I hope someone could help me with this situation.

Greetings and thanks for the help.

In reply to Carlos Villalpando

Re: How to pre-populate and hide site URL entry page?

Juan Leyva發表於
Core developers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片

Hi,

we are working in adding a new setting in the config.json file (prepopulatedurl) so the app can detect that and omit the first screen.

Is something we have in the short-term roadmap.

Regards, Juan

In reply to Juan Leyva

Re: How to pre-populate and hide site URL entry page?

Aron Kondoro發表於

Hi,

I have a similar problem as indicated in this thread, but none of the solutions provided so far seem to work. Any help would be appreciated.

Thanks in advance.

In reply to Aron Kondoro

Re: How to pre-populate and hide site URL entry page?

Juan Leyva發表於
Core developers的相片 Moodle HQ的相片 Particularly helpful Moodlers的相片 Plugin developers的相片 Testers的相片

Hi,

if you fork using the latest master code (or synchronize your fork), now we support adding a fixed URL just adding a new setting in the config.json file:

siteurl: "https://yoursite.com"

The updated tutorial is linked from here:

https://docs.moodle.org/dev/Moodle_Mobile_custom_apps

Juan

In reply to Juan Leyva

Re: How to pre-populate and hide site URL entry page?

Yezi Yang發表於

Dear Juan,

Thank you very much for your reply. I add “siteurl:”https://mysite.com”” in config.json file as well as remove the URL of “demo_sites”. However, after I convert the code from Phonegap Build, it still asks users to type in Moodle site URL.

What I do for the code is following:

1. Download the MM2.7 code released in from github in “iOS” branch (https://github.com/moodlehq/moodlemobile-phonegapbuild)

2. Add “siteurl:”https://mysite.com”” in config.json file, and remove the URL of “demo_sites”. The following is a screen shot of the config.json file after I do the changes. Also I use the Moodle official demo site as the pre-populated URL.
3. Then I convert the code in Phonegap Build, as I always do for Moodle mobile app 2.3 and 2.5. I convert the app for iOS device. But the app in both of the devices ask users to type in Moodle site URL.


4. According to the PPT you post online, I also need to replace ‘http://mymoodle.com’ with my Moodle site URL in www/core/components/login/main.js. However, when I open the code I download from Github, there is no ‘http://mymoodle.com’.

After do the changes above, I also open the app on Google Chromium browser. It also asks me to type in Moodle URL.


In addition, when checking in Google Chroium developer tool, it has an error, as showing below.



I really appreciate this new function you developed and hope it can work in the Moodle app in my institution. I really looking forward for your reply. Thank you for your support again.


評比平均分數:Useful (1)
In reply to Dani Palou

Re: How to pre-populate and hide site URL entry page?

Sourabh Maheshwari發表於

Dear Daniel,

If we do this by deleting the mm_login.sitestate and use force login via browser, will the app automatically take a user to the browser without popping the confirmation box?

 

Also in a situation when you are login via browser in the app, shouldn't the browser window close after authentication is done?

 

Thanks and Regards,

Sourabh

In reply to Sourabh Maheshwari

Re: How to pre-populate and hide site URL entry page?

Dani Palou發表於
Core developers的相片 Moodle HQ的相片 Peer reviewers的相片 Plugin developers的相片

Hello Sourabh,

the older way to add a fixed site URL wasn't prepared to be used with login via browser (it required further development). Now in Moodle Mobile 2.7 we have a new way to add fixed site URLs that supports it. Basically, when the user opens the app for the first time he should see the confirmation box and be redirected to the browser.

About your second question, the browser redirects the user to the app but it's not closed. We'll take a look into this to see if it's easy to close it and it doesn't cause any problem.

Kind regards,

Dani

In reply to Dani Palou

Re: How to pre-populate and hide site URL entry page?

Sourabh Maheshwari發表於

Thanks Daniel for the clarification. 

This is our android app which we have customised and made available for testing.  We are facing problem on login via browser for SSO login and account creation for first time users.  

https://play.google.com/apps/testing/com.saam.arth

Thanks 

In reply to Sourabh Maheshwari

Re: How to pre-populate and hide site URL entry page?

Sourabh Maheshwari發表於

Please use following login details:

Edited to remove the login details, you should send them via private message next time.


(Editado por Daniel Palou - envío original jueves, 7 de enero de 2016, 15:38)

In reply to Sourabh Maheshwari

Re: How to pre-populate and hide site URL entry page?

Sourabh Maheshwari發表於

Thanks Daniel for your promt response and solution.

With the Access thing changed in the php file, the app is taking a user to a browser window; however, after inputing the user details, it is not going back to the app and when you again open the app, the same process happens.

 

Would be great if you can test with the guest account.

 

Thanks in advance,

Best Regards,

Sourabh

In reply to Sourabh Maheshwari

Re: How to pre-populate and hide site URL entry page?

Dani Palou發表於
Core developers的相片 Moodle HQ的相片 Peer reviewers的相片 Plugin developers的相片

Hi Sourabh,

I tested it and your Moodle opened MoodleMobile official app after authenticating. If you haven't done it already, you should change the URL scheme your app uses (see the plugin documentation).

You should also change the URL scheme used by your local mobile in Moodle. Inside local_mobile plugin there's a file named launch.php with this line:

$location = "Location: moodlemobile://token=$apptoken";

If you change "moodlemobile" with your URL scheme it should open your app, but then it won't work for the official Moodle Mobile app.

If you want it to work both for your custom app and for MoodleMobile then you'll have to create a new script. You can just duplicate launch.php (with another name) and use your custom URL scheme in that new script. You should call this new script in your custom app, that is done in www/core/components/login/services/helper.js:

var loginurl = siteurl + "/local/mobile/launch.php?service=" + mmCoreConfigConstants.wsextservice;

You should replace "local/mobile/launch.php" with the location of your new script.

I hope this helps!

Kind regards,

Dani

In reply to Yezi Yang

Re: How to pre-populate and hide site URL entry page?

Yezi Yang發表於

Dear Juan,

Thank you very much for your reply. I add “siteurl:”https://mysite.com”” in config.json file as well as remove the URL of “demo_sites”. However, after I convert the code from Phonegap Build, it still asks users to type in Moodle site URL.

What I do for the code is following:

1. Download the MM2.7 code released in from github in “iOS” branch (https://github.com/moodlehq/moodlemobile-phonegapbuild)

2. Add “siteurl:”https://mysite.com”” in config.json file, and remove the URL of “demo_sites”. The following is a screen shot of the config.json file after I do the changes. Also I use the Moodle official demo site as the pre-populated URL.

3. Then I convert the code in Phonegap Build, as I always do for Moodle mobile app 2.3 and 2.5. I convert the app for iOS device. But the app in both of the devices ask users to type in Moodle site URL.




4. According to the PPT you post online, I also need to replace ‘http://mymoodle.com’ with my Moodle site URL in www/core/components/login/main.js. However, when I open the code I download from Github, there is no ‘http://mymoodle.com’.

After do the changes above, I also open the app on Google Chromium browser. It also asks me to type in Moodle URL.


In addition, when checking in Google Chroium developer tool, it has an error, as showing below.



I really appreciate this new function you developed and hope it can work in the Moodle app in my institution. As you may know, there are some bugs when hard coding the Moodle site URL to pre-populating the site URL, such as chat and choice activities are not intergrated with the app until cleaning the cache. It becomes a big problems now, since a number of students are using choice activities in the app for optional course choosing for the second semester. I really hope that you can reply me about how to use the new feature to pre-populating the site URL in config.json file.

I am looking forward for your reply. Thank you for your support again.

In reply to Yezi Yang

Re: How to pre-populate and hide site URL entry page?

Dani Palou發表於
Core developers的相片 Moodle HQ的相片 Peer reviewers的相片 Plugin developers的相片

Hi Yezi,

seems Juan's changes to the PPT weren't saved, we just fixed it so it no longer talks about changing main.js.

About your problem, have you run gulp after adding that to the config file? In 2.7 we changed the way we read the config values to make it faster and simpler to retrieve them. Now the gulp process converts the JSON file into an Angular constant, and we read the values from that constant. This means that you need to run gulp everytime you change the config.json file.

If you don't have the development environment set, you can manually apply it to the build file (although it's not recommended since it can give you problems during rebase). If you go to the end of build/mm.bundle.js you'll see something like this:

.constant('mmCoreConfigConstants', {

    "app_id" : "com.moodle.moodlemobile",

    "versioncode" : "2007",

    "versionname" : "2.6",

    "cache_expiration_time" : 300000,

    "default_lang" : "en",

    "languages": {...},

    "wsservice" : "moodle_mobile_app",

    "wsextservice" : "local_mobile",

    "demo_sites": {...},

    "gcmpn": "694767596569"

}

You can add the siteurl in there too.

I hope this helps fixing the problem!

Kind regards,

Dani