00001 <?php
00002 session_start();
00003
00004 require_once("GenieGate/Controller.php");
00005 require_once("GenieGate/UserAccount.php");
00006 require_once("GenieGate/Groups.php");
00007 require_once("GenieGate/Properties.php");
00008 require_once("GenieGate/View/Mail.php");
00009 require_once("GenieGate/View/Location.php");
00010 require_once("GenieGate/Api/Login.php");
00011
00012
00024 class GenieGate_Controller_User extends GenieGate_Controller {
00025 var $UA;
00026 var $GM;
00027 var $PM;
00028
00029 var $APP_NAME = "User";
00030
00031 var $DISPATCH = array( DO_SHOW_SIGNUP_FORM => "do_show_signup_form",
00032 DO_CONFIRM_ACCOUNT => "do_confirm_account",
00033 DO_UPDATE_SETTINGS => "do_update_settings",
00034 DO_SHOW_PROPERTIES => "do_show_properties",
00035 DO_MAIN_PAGE => "do_main_page",
00036 DO_SHOW_FORGOT_PASSWORD => "do_show_forgot_password",
00037 DO_CHANGE_PASSWORD => "do_change_password",
00038 DO_LOGOUT => "do_logout",
00039 DO_SHOW_PASSWORD_CHANGE => "do_show_password_change",
00040 DO_SEND_PASSWORD => "do_send_password",
00041 DO_LOGIN => "do_login",
00042 DO_RESEND_CONFIRM => "do_resend_confirm",
00043 DO_SHOW_REMIND_FORM => "do_show_remind_form",
00044 DO_PROCESS_SIGNUP => "do_process_signup");
00045
00053 function GenieGate_Controller_User(&$conf){
00054 parent::GenieGate_Controller($conf);
00055 $this->GM = new GenieGate_Groups($this->DBH);
00056 $this->UA = new GenieGate_UserAccount($this->DBH,$this->GM);
00057 $this->PM = new GenieGate_Properties($this->DBH);
00058 $this->G = new GenieGate_Api_Login($this->DBH);
00059
00060
00061 if(! $conf[ALLOW_HTTP_AUTH]){
00062 $this->G->USE_HTTP_AUTH=FALSE;
00063 $this->G->setPromptView($this->getView("new-user"));
00064 }
00065 $this->addPlugins();
00066 }
00070 function addListener(&$listener){
00071 parent::addListener($listener);
00072 $this->UA->addListener(&$listener);
00073 $this->GM->addListener(&$listener);
00074 $this->PM->addListener(&$listener);
00075 }
00076
00082 function getUrl($id) {
00083 if($this->CFG[Url][$id]){
00084 return($this->CFG[Url][$id]);
00085 }
00086 $dir = dirname($_SERVER[PHP_SELF]);
00087 return("http://" . $_SERVER[SERVER_NAME] . $dir . "/" . $id . ".php");
00088 }
00097 function getMailView($to,$id){
00098 $dir = $this->CFG[Views][$this->APP_NAME];
00099 $file = $dir . $id . ".php";
00100 $mview = new GenieGate_View_Mail($to, $file);
00101 return($mview);
00102 }
00106 function getRedirectView($location){
00107 return( new GenieGate_View_Location($location) );
00108 }
00114 function do_show_signup_form(){
00115 return($this->getView("user-signup"));
00116 }
00117
00122 function do_show_password_change(){
00123 $user = $this->G->login();
00124 $view = $this->getView("change-password");
00125 $view->param("USER",$user);
00126 return($view);
00127 }
00131 function do_change_password(){
00132 $user = $this->G->login();
00133 $uid = $user->getUserId();
00134 $errors = array();
00135 $info = $this->UA->lookupUid($uid);
00136 if($info[password] != $_POST[PASSWORD]){
00137 array_push($errors,"Current password incorrect");
00138 }
00139 if($_POST[NEW_PASS] != $_POST[CONFIRM_PASS]){
00140 array_push($errors,"Passwords don't match");
00141 }
00142 if(count($errors)){
00143 $ev = $this->getView("error-general");
00144 $ev->param("ERRORS",$errors);
00145 return($ev);
00146 }
00147 $info[password] = $_POST[NEW_PASS];
00148 $errors = $this->UA->checkNewUserFields($info,FALSE);
00149 if(count($errors)){
00150 $ev = $this->getView("error-general");
00151 $ev->param("ERRORS",$errors);
00152 return($ev);
00153 }
00154 $this->UA->updateUserAccount($uid,$info);
00155 if($_POST[LOCATION]){
00156 $view = $this->getRedirectView($_POST[LOCATION]);
00157 }else{
00158 $view = $this->getView("password-changed");
00159 }
00160 return($view);
00161 }
00162
00163
00167 function do_show_remind_form(){
00168 return($this->getView("remind-confno"));
00169 }
00174 function do_resend_confirm(){
00175 $uid = $_REQUEST[UID];
00176 $email = $_REQUEST[EMAIL];
00177 $inf = $this->UA->lookupUid($uid);
00178 if(! $inf){
00179 $inf = $this->UA->lookupEmail($email);
00180 }
00181 if(! $inf){
00182 $view = $this->getView("error-general");
00183 $view->param("ERRORS",array("UserID or Email address not found"));
00184 return($view);
00185 }
00186
00187
00188 require_once("GenieGate/View/Ganged.php");
00189 $mview = $this->getMailView($inf[email],"mail-confirm-remind");
00190 $mview->param("CONF_NO",$inf[id]);
00191 $conf_url = $this->getUrl("confirm");
00192 $conf_url .= "?C=" . $inf[id] . "&U=" . $inf[uid];
00193 $mview->param("CONFIRM_URL",$conf_url);
00194 $mview->param("ACCOUNT",$inf);
00195
00196 $gview = new GenieGate_View_Ganged();
00197
00198 if($_REQUEST[LOCATION]){
00199 $view = $this->getRedirectView($_REQUEST[LOCATION]);
00200 $view->param("USERID",$inf[uid]);
00201
00202 $gview->addView($view);
00203 $gview->addView($mview);
00204 return($gview);
00205 }else{
00206 $gview->addView($this->getView("check-email-remind"));
00207 $gview->addView($mview);
00208 return($gview);
00209 }
00210 }
00218 function do_process_signup(){
00219
00220 $fields = array();
00221 $fields[uid] = $_POST[USERID];
00222 $fields[name] = $_POST[NAME];
00223 $fields[email] = $_POST[EMAIL];
00224 if($_POST[PASSWORD] != $_POST[PASSWORDC]){
00225 $errors = array("Passwords do not match");
00226 $view = $this->getView("error-signup");
00227 $view->param("ERRORS",$errors);
00228 return($view);
00229 }
00230 $fields[password] = $_POST[PASSWORD];
00231 $mview = $this->getMailView($fields[email],"mail-confirm");
00232 $errors = $this->UA->createUserAccount($fields,$mview);
00233 if(count($errors) > 0){
00234 $view = $this->getView("error-signup");
00235 $view->param("ERRORS",$errors);
00236 return($view);
00237 }
00238
00239 require_once("GenieGate/View/Ganged.php");
00240
00241
00242
00243
00244
00245
00246 $gview = new GenieGate_View_Ganged();
00247
00248
00249 $conf_no = $mview->param("CONF_NO");
00250 $conf_url = $this->getUrl("confirm");
00251 $conf_url .= "?C=" . $conf_no . "&U=" . $fields[uid];
00252 $mview->param("CONFIRM_URL",$conf_url);
00253
00254
00255 if($_POST[LOCATION]){
00256 $view = $this->getRedirectView($_POST[LOCATION]);
00257 $view->param("USERID",$fields[uid]);
00258 $gview->addView($view);
00259 $gview->addView($mview);
00260 return($gview);
00261 }else{
00262 $gview->addView($this->getView("check-email"));
00263 $gview->addView($mview);
00264 return($gview);
00265 }
00266 }
00272 function do_confirm_account(){
00273 $conf_no = $_REQUEST[C];
00274 $uid = $_REQUEST[U];
00275
00276 $errors = $this->UA->confirmUserAccount($uid,$conf_no);
00277 if(count($errors) > 0){
00278 $view = $this->getView("error-confirm");
00279 $view->param("ERRORS",$errors);
00280 return($view);
00281 }
00282 $view = $this->getView("account-confirmed");
00283 $fields = $this->UA->lookupUid($uid);
00284 $view->param("GROUPS",$this->GM->getAllGroups(FALSE));
00285 $view->param("PROPS",$this->PM->getSectionProperties("genie.form.Public"));
00286 $view->param("ACCOUNT",$fields);
00287 $view->param("START_PAGE",$this->getUrl("StartPage"));
00288 return($view);
00289 }
00293 function do_show_forgot_password(){
00294 return($this->getView("show-email-password"));
00295 }
00301 function do_send_password(){
00302 $uid = $_POST[UID];
00303 $email = $_POST[EMAIL];
00304 $inf = $this->UA->lookupUid($uid);
00305 if(! $inf){
00306 $inf = $this->UA->lookupEmail($email);
00307 }
00308 if(! $inf){
00309 $view = $this->getView("error-general");
00310 $view->param("ERRORS",array("UserID or Email address not found"));
00311 return($view);
00312 }
00313
00314
00315
00316 require_once("GenieGate/View/Ganged.php");
00317 $gview = new GenieGate_View_Ganged();
00318
00319
00320 $mv = $this->getMailView($inf[email],"mail-password");
00321 $mv->param("INFO",$inf);
00322
00323 if($_POST[LOCATION]){
00324 $gview->addView($this->getRedirectView($_POST[LOCATION]));
00325 $gview->addView($mv);
00326 return($gview);
00327 }else{
00328 $gview->addView($this->getView("sent-password"));
00329 $gview->addView($mv);
00330 return($gview);
00331 }
00332 }
00336 function do_show_properties(){
00337 $user = $this->G->login();
00338 $view = $this->getView("show-properties");
00339 $view->param("USER",$user);
00340 $view->param("PUBLIC",$this->PM->getSectionProperties("genie.form.Public"));
00341 return($view);
00342 }
00349 function do_main_page(){
00350 $user = $this->G->passiveLogin();
00351 if($user){
00352 $view = $this->getView("main");
00353 $view->param("USER",$user);
00354 $view->param("GROUPS",$this->GM->getAllGroups(FALSE));
00355 $view->param("PROPS",$this->PM->getSectionProperties("genie.form.Public"));
00356 return($view);
00357 }else{
00358 return($this->getView("new-user"));
00359 }
00360 }
00365 function do_logout(){
00366 $user = $this->G->logout();
00367 if($_REQUEST[LOCATION]){
00368 return($this->getRedirectView($_REQUEST[LOCATION]));
00369 }
00370 return($this->getView("logged-out"));
00371 }
00375 function do_login(){
00376 $user = $this->G->login();
00377 if($_REQUEST[LOCATION]){
00378 return($this->getRedirectView($_POST[LOCATION]));
00379 }
00380 return($this->do_main_page());
00381 }
00382
00383
00406 function do_update_settings(){
00407 $user = $this->G->login();
00408 $uid = $user->getUserId();
00409 $cp = $this->PM->getSection("genie.form.Public",$uid);
00410 foreach($_POST as $k => $v) {
00411 list($c,$n) = explode(":",$k,2);
00412 if($c == "PROP"){
00413 if(strlen($v)){
00414 if($cp->isProperty($n)){
00415 $cp->setProperty($n,$v);
00416 }
00417 }
00418 }
00419 }
00420 if($_POST[LOCATION]){
00421 return($this->getRedirectView($_POST[LOCATION]));
00422 }
00423 return($this->getView("set-properties"));
00424 }
00425
00426
00427 }
00428
00429 ?>