Location: PHPKode > projects > OpenBizMap > openbizmap/mydata/script/run_newuser.txt
<?php
/*
OpenDataBag - Data Web Interface
Copyright (C) 2004 Nawara

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

$passwd_array=array();

$passwd_array=unserialize(base64_decode(file_get_contents(cfg_sso_path.'/data/.passwd.txt')));

if(file_exists(cfg_sso_path.'/temp/antibot/'.$sid))
  $antibot=file_get_contents(cfg_sso_path.'/temp/antibot/'.$sid);

$accept=get('accept');
if($accept)
{
  if(file_exists(cfg_sso_path.'/temp/newusers/'.$accept))
  {
    $new_passwd_array=unserialize(gzuncompress(base64_decode(file_get_contents(cfg_sso_path.'/temp/newusers/'.$accept))));

    $username=$new_passwd_array['user'];

    $passwd_array[md5(purename($username))]=$new_passwd_array['passwd'];
    $passwd_array[md5(purename($username.'email'))]=$new_passwd_array['email'];
    $passwd_array[md5(purename($username.'extra'))]=$new_passwd_array['extra'];

    $fp=fopen(cfg_sso_path.'/data/.passwd.txt','w');
    fwrite($fp,base64_encode(serialize($passwd_array)));
    fclose($fp);

    unlink(cfg_sso_path.'/temp/newusers/'.$accept);

    sendmail($new_passwd_array['email'],'newaccountready',array('USERNAME' => $new_passwd_array['user'], 'EMAIL' => $new_passwd_array['email'], 'LINK' => $selflink, 'EXTRA' => $new_passwd_array['extra']));
    $skin='newuser3';

    $new_passwd_array=array();
  }
  else
  {
    $message='No user to accept';
  }
}
elseif(!isset($passwd_array[md5(purename(get('username')))]) and strtolower($antibot)==strtolower(get('antibot')) and get('password1')==get('password'))
{
  //adding new user data to database
  if(defined('cfg_newuser_extra'))
  {
    $variable_array2=load_config(cfg_newuser_extra);

    $variable_array=array();
    reset($variable_array2);
    while(list($variable_name,$tmp)=each($variable_array2))
    {
      if(substr($variable_name,0,3)!='sys'
      and $variable_name!='Registration Date'
      and $variable_name!='Registration Time'
      and $variable_name!='User'
      and $variable_name!='Email'
      and $variable_name!='MyBag' and $variable_array[$variable_name]['tab']=='' and ($variable_array[$variable_name]['show_cond']==0 or $variable_array[$variable_name]['show_cond']==2))
      {
        $val=get(purename($variable_name));
        if(strlen($val))
          $variable_array[$variable_name]=$val;
      }
    }

    $variable_array['Registration Date']=date('Ymd');
    $variable_array['Registration Time']=date('H:i');
    $variable_array['User']=get('username');
    $variable_array['User Group']=cfg_newuser_group;
    $variable_array['Active']='1';
    $variable_array['Email']=strtolower(get('email'));

    $variable_array['sysId']='0';
    $variable_array['sysGroupBy']=cfg_newuser_extra;
    $variable_array['sysValidFrom']=date('Ymd');
    $variable_array['sysValidTo']=99991231;
    $variable_array['sysValid']=1;
    $variable_array['sysComment']='New user registration';

    $variable_array['MyBag']='access';
    $extra=save($variable_array);
  }

  $accept=md5(time().get('username')); //data waiting for acceptance

  $new_passwd_array=array();
  $new_passwd_array['user']=get('username');
  $new_passwd_array['passwd']=md5(purename(get('username')).get('password'));
  $new_passwd_array['email']=strtolower(get('email'));
  $new_passwd_array['extra']=get('extra');

  addpath(cfg_sso_path.'/temp/newusers');

  $fp=fopen(cfg_sso_path.'/temp/newusers/'.$accept,'w');
  fwrite($fp,base64_encode(gzcompress(serialize($new_passwd_array))));
  fclose($fp);

  $new_passwd_array=array();

  if(strlen(cfg_smtp_newuser_acceptance)>0)
    $sendto=cfg_smtp_newuser_acceptance;
  else
    $sendto=get('email');

  sendmail($sendto,'confirmnewuser',array('USERNAME' => get('username'), 'EMAIL' => get('email'), 'EXTRA' => $extra, 'LINK' => $selflink.'?odb_run=newuser&amp;odb_accept='.$accept));
  $skin='newuser2';
}
else
{
  if(strtolower($antibot)!=strtolower(get('antibot')))
    $message='Wrong antibot image recognision';

  if(get('password1')!=get('password'))
    $message='Passwords diffrent';

  if(isset($passwd_array[md5(purename(get('username')))]))
    $message='Username exists';

  $skin='newuser';
}

$passwd_array=array();

?>
Return current item: OpenBizMap