1<?php 2 3class auth_plugin_sfauth extends auth_plugin_authplain { 4 /** @var helper_plugin_sfauth */ 5 protected $hlp = null; 6 7 /** 8 * Get user data 9 * 10 * @param string $user 11 * @return array|bool|false 12 */ 13 function getUserData($user) { 14 $data = parent::getUserData($user); 15 if($data) return $data; 16 17 if(!$this->checkConfiguration()) return false; 18 19 /** @var helper_plugin_sfauth $sfuser */ 20 $sfuser = plugin_load('helper', 'sfauth'); 21 if($sfuser->init_by_user($user)) { 22 return $sfuser->getUserData(); 23 } 24 25 return false; 26 } 27 28 /** 29 * Check given user and password 30 * 31 * Also initiates the oauth process 32 * 33 * @param string $user 34 * @param string $pass 35 * @return bool 36 */ 37 function checkPass(&$user, $pass) { 38 global $INPUT; 39 40 if(!$INPUT->has('sf')) { 41 return parent::checkPass($user, $pass); 42 } 43 if(!$this->checkConfiguration()) return false; 44 45 /** @var helper_plugin_sfauth $sfuser */ 46 $sfuser = plugin_load('helper', 'sfauth'); 47 if($sfuser->init_by_oauth($INPUT->int('sf', 1))) { 48 $user = $sfuser->getUser(); 49 return true; 50 } 51 52 return false; 53 } 54 55 /** 56 * Check if the plugin is completely configured 57 * 58 * @return bool 59 */ 60 private function isSfConfigured() { 61 if(!$this->getConf('consumer key')) return false; 62 if(!$this->getConf('consumer secret')) return false; 63 if(!$this->getConf('auth url')) return false; 64 return true; 65 } 66 67 /** 68 * Wrap around the config check, emit a warning on first call 69 * 70 * @return bool 71 */ 72 public function checkConfiguration() { 73 if($this->isSfConfigured()) { 74 return true; 75 } 76 77 static $warningShown = false; 78 79 if(!$warningShown) { 80 msg('SalesForce login not configured. Just using plain auth.', 2); 81 $warningShown = true; 82 } 83 return false; 84 } 85 86 87 88} 89