Moodle

Repository API Login Frustrations

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Duplicate
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Repositories
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

I don't think the current api implementation or example plugins are particularly easy to undestand or write plugins for:

1/ The use of the GLOBAL variable $action is really not clear (and if it is a global, should it not be in caps?). Could we not do this work within the plugin isntance variables?

2/ print_login use is not clear

  • When does it get called? (It certainly isn't used if its defined).
  • Where will resultant of this be posted to - where do I do something with this login?
  • There is an ajax flag, and it apears to output needs to be in a specific format when this is set? What is this?
  • It looks like I need to set repo_id in here?

Activity

Hide
Dan Poltawski added a comment - - edited

3/ The logout button seems to only cause a change in the $action variable, which the plugin needs to inspect. Again could this not be done by a function of the plugin rather than the module creator needing to examine $action?

Show
Dan Poltawski added a comment - - edited 3/ The logout button seems to only cause a change in the $action variable, which the plugin needs to inspect. Again could this not be done by a function of the plugin rather than the module creator needing to examine $action?
Hide
Martin Dougiamas added a comment -

Dongsheng, can you address these? I guess there must be some cleaning up to do still.

Show
Martin Dougiamas added a comment - Dongsheng, can you address these? I guess there must be some cleaning up to do still.
Hide
Martin Dougiamas added a comment -

And thanks Dan!!

Show
Martin Dougiamas added a comment - And thanks Dan!!
Hide
Dongsheng Cai added a comment -

Hi, Dan,
1/
I agree, but currently, I couldn't find a graceful way to replace with it, when user click the repository name on file picker, repository module doesn't know whether the user is logged in (some plugins don't need to login, for example, local and upload plugin) until plugin class has been initialized (in __construct function), if the user is not logged in, we must change the action to tell repository api: print a login form for user, print_login will be called.

2/

  • when action == login
  • print_login will return some login information, which tell file picker what elements the login form should be contained, the most simple print_login should be like this:
    public function print_login($ajax = true)
    Unknown macro: { global $SESSION; if($ajax){ $ret = array(); $popup_btn = new stdclass; $popup_btn->type = 'popup'; $popup_btn->url = "http://moodlesite.com/login.php"; $ret['login'] = array($popup_btn); return $ret; } }

    This will create a link which can open a popup window, or you can tell file picker to create login form with username and password:
    public function print_login($ajax = true)
    Unknown macro: { global $SESSION; if($ajax){ $ret = array(); $username->label = get_string('username', 'repository_boxnet').': '; $username->id = 'box_username'; $username->type = 'text'; $username->name = 'boxusername'; $username->value = $ret->username; $password->label = get_string('password', 'repository_boxnet').': '; $password->id = 'box_password'; $password->type = 'password'; $password->name = 'boxpassword'; $ret['login'] = array($username, $password); return $ret; } }

label is the text before the username input element, type is the attribute of input element, name is the name of input element
it will create a form:
<label>username</label><br/>
<input type="text" name="boxusername' id="box_username" />
<label>Password</label><br/>
<input type="password" name="boxpassword' id="box_password" />

  • we will develop a non-javascript file picker later, so we use ajax flag here to tell plugin print a login form for ajax file picker instead of non-javascript file picker
  • Not anymore, I just found another way to store repository in javascript object.

3/ That's reasonable, we need to create a function called logout in base class.

Show
Dongsheng Cai added a comment - Hi, Dan, 1/ I agree, but currently, I couldn't find a graceful way to replace with it, when user click the repository name on file picker, repository module doesn't know whether the user is logged in (some plugins don't need to login, for example, local and upload plugin) until plugin class has been initialized (in __construct function), if the user is not logged in, we must change the action to tell repository api: print a login form for user, print_login will be called. 2/
  • when action == login
  • print_login will return some login information, which tell file picker what elements the login form should be contained, the most simple print_login should be like this: public function print_login($ajax = true)
    Unknown macro: { global $SESSION; if($ajax){ $ret = array(); $popup_btn = new stdclass; $popup_btn->type = 'popup'; $popup_btn->url = "http://moodlesite.com/login.php"; $ret['login'] = array($popup_btn); return $ret; } }
    This will create a link which can open a popup window, or you can tell file picker to create login form with username and password: public function print_login($ajax = true)
    Unknown macro: { global $SESSION; if($ajax){ $ret = array(); $username->label = get_string('username', 'repository_boxnet').': '; $username->id = 'box_username'; $username->type = 'text'; $username->name = 'boxusername'; $username->value = $ret->username; $password->label = get_string('password', 'repository_boxnet').': '; $password->id = 'box_password'; $password->type = 'password'; $password->name = 'boxpassword'; $ret['login'] = array($username, $password); return $ret; } }
label is the text before the username input element, type is the attribute of input element, name is the name of input element it will create a form: <label>username</label><br/> <input type="text" name="boxusername' id="box_username" /> <label>Password</label><br/> <input type="password" name="boxpassword' id="box_password" />
  • we will develop a non-javascript file picker later, so we use ajax flag here to tell plugin print a login form for ajax file picker instead of non-javascript file picker
  • Not anymore, I just found another way to store repository in javascript object.
3/ That's reasonable, we need to create a function called logout in base class.
Hide
Dongsheng Cai added a comment -

Any suggestions are welcomed, dan, please let me know if you know better way to implement the file picker. Thanks

Show
Dongsheng Cai added a comment - Any suggestions are welcomed, dan, please let me know if you know better way to implement the file picker. Thanks
Hide
Dan Poltawski added a comment -

Hi Dongsheng,

Thanks for your comments (I have not looked into the internals of how this works yet, just how I would write a plugin for it)

1) What possible actions can happen with this?

Could we not do this sort of thing in methods of the base class, e.g. check_login() function which defaults to true. So when we want to display a list of files we do:

$foo = new repo();

if( $foo->check_login() ){
$foo->display_files();
}else{
$foo->print_login();
}

Or something like that - the same for checking the result of the login, rather than putting it all in the constructor?

2) What is the format of the returned object - what interprets it? Why is it indexed by 'login'?

Show
Dan Poltawski added a comment - Hi Dongsheng, Thanks for your comments (I have not looked into the internals of how this works yet, just how I would write a plugin for it) 1) What possible actions can happen with this? Could we not do this sort of thing in methods of the base class, e.g. check_login() function which defaults to true. So when we want to display a list of files we do: $foo = new repo(); if( $foo->check_login() ){ $foo->display_files(); }else{ $foo->print_login(); } Or something like that - the same for checking the result of the login, rather than putting it all in the constructor? 2) What is the format of the returned object - what interprets it? Why is it indexed by 'login'?
Hide
Dongsheng Cai added a comment -

1) That's reasonable, the original Repository API specification don't have this function, we need to add it.

2) returned object will be encoded as JSON string, javascript interprets the JSON string (repository/lib.php line 1526)
> Why is it indexed by 'login'?
Because the Javascript Ajax request will be processed by a callback object (repository/lib.php line 1998)
the response json may be files list ($ret['list']) , login form ($ret['login']) or error report ($ret['e']).

Show
Dongsheng Cai added a comment - 1) That's reasonable, the original Repository API specification don't have this function, we need to add it. 2) returned object will be encoded as JSON string, javascript interprets the JSON string (repository/lib.php line 1526) > Why is it indexed by 'login'? Because the Javascript Ajax request will be processed by a callback object (repository/lib.php line 1998) the response json may be files list ($ret['list']) , login form ($ret['login']) or error report ($ret['e']).
Hide
Dongsheng Cai added a comment -

Dan, I added logout() and check_login() according your suggestion, we don't need $action anymore, let me know if you find more problem.

Show
Dongsheng Cai added a comment - Dan, I added logout() and check_login() according your suggestion, we don't need $action anymore, let me know if you find more problem.
Hide
Dongsheng Cai added a comment -

Dan, Repository API started to support popup now, you can have a look "Flickr plug-in".

Show
Dongsheng Cai added a comment - Dan, Repository API started to support popup now, you can have a look "Flickr plug-in".
Hide
Dongsheng Cai added a comment -
Show
Dongsheng Cai added a comment - See MDL-16545

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: