rabser / moodle-auth_googleoauth2

Oauth2 authentication plugin for Moodle (for Moodle 3.2 and earlier)
GNU General Public License v3.0
78 stars 78 forks source link

Facebook - profile photo #195

Closed PabloStep closed 8 years ago

PabloStep commented 8 years ago

Here is code which extends function in auth.php to get users profile photo from FB (hope it's helpful):

                      case 'facebook':
                            require_once($CFG->libdir . '/filelib.php');
                            require_once($CFG->libdir . '/gdlib.php');
                                $imagefilename = $CFG->tempdir . '/googleoauth2-portrait-' . $user->id;
                                $imagecontents = download_file_content('https://graph.facebook.com/' . $userdetails->uid . '/picture?type=large');
                                file_put_contents($imagefilename, $imagecontents);
                                if ($newrev = process_new_icon(context_user::instance($user->id),
                                'user', 'icon', 0, $imagefilename)) {
                                $DB->set_field('user', 'picture', $newrev, array('id' => $user->id));
                                }
                                unlink($imagefilename);
                            break;
                        default:
                            // TODO retrieve other provider profile pictures.
                            break;
                    }
                } 
mouneyrac commented 8 years ago

I added it last year https://github.com/mouneyrac/moodle-auth_googleoauth2/commit/cdee52353830e7e729c3bb5f86ac11f64f1bbd24 but thanks anyway Pablo :)