<?php
include '../../conn/config.inc.php';
include './uc_client/client.php';
header('Content-Type:text/html;charset=GB2312');

if($_POST['key']!=MD5(UC_KEY)){echo 'API密锁不一致';exit();}

switch(@$_POST['action']){
  case 'reg':
	$uid = uc_user_register($_POST['user'], $_POST['pass'], $_POST['email'], $_POST['question'], $_POST['answer']);
	if($uid <= 0) {
		if($uid == -1) {
			echo '用户名不合法';
		} elseif($uid == -2) {
			echo '包含要允许注册的词语';
		} elseif($uid == -3) {
			echo '用户名已经存在';
		} elseif($uid == -4) {
			echo 'Email 格式有误';
		} elseif($uid == -5) {
			echo 'Email 不允许注册';
		} elseif($uid == -6) {
			echo '该 Email 已经被注册';
		} else {
			echo '未定义';
		}
    }
    break;

  case 'edit':
	$uid = uc_user_edit($_POST['user'],$_POST['oldpw'],$_POST['newpw'] ,$_POST['email'],1,$_POST['question'] ,$_POST['answer']);
	if($uid < 0) {
		if($uid == -1) {
			echo '旧密码不正确';
		} elseif($uid == -4) {
			echo 'Email 格式有误';
		} elseif($uid == -5) {
			echo 'Email 不允许注册';
		} elseif($uid == -6) {
			echo '该 Email 已经被注册';
		} elseif($uid == -7) {
			echo '没有做任何修改';
		} elseif($uid == -8) {
			echo '该用户受保护无权限更改';
		} else {
			echo '未定义';
		}
    }
    break;

  case 'checkname':
	$uid = uc_user_checkname($_POST['user']);
	if($uid < 0) {
		if($uid == -1) {
			echo '用户名不合法';
		} elseif($uid == -2) {
			echo '包含要允许注册的词语';
		} elseif($uid == -3) {
			echo '用户名已经存在';
		}
    }
    break;

  case 'checkemail':
	$uid = uc_user_checkemail($_POST['email']);
	if($uid < 0) {
		if($uid == -4) {
			echo 'Email 格式有误';
		} elseif($uid == -5) {
			echo 'Email 不允许注册';
		} elseif($uid == -6) {
			echo '该 Email 已经被注册';
		}
    }
    break;

  case 'login':
    list($uid, $username, $password, $email) = uc_user_login($_POST['user'],$_POST['pass'],0,0,"","");
	if($uid < 0) {
		if($uid == -1) {
			echo '用户不存在';
		} elseif($uid == -2) {
			echo '密码错误';
		}
    }else{
	  uc_user_synlogin($uid);
	}
    break;

  case 'getuser':
    if($data = uc_get_user($_POST['user'])) {
	    list($uid, $username, $email) = $data;
		echo $email;
    }
    break;

  case 'getuserid':
    if($data = uc_get_user($_POST['user'])) {
	    list($uid, $username, $email) = $data;
		echo $uid;
    }
    break;

  case 'logout':
    uc_user_synlogout();
    break;

  case 'delete':
	$uid = uc_user_delete($_POST['user']);
	if($uid == 0){
	  echo '操作失败';
    }
    break;

  case 'merge':
	$uid = $uid = uc_user_merge($_GET['user'], $_GET['newuser'], $user['id'], $_GET['pass'], $user['email']);
	if($uid < 0) {
		if($uid == -1) {
			echo '用户名不合法';
		} elseif($uid == -2) {
			echo '包含不允许注册的词语';
		} elseif($uid == -3) {
			echo '用户名已经存在';
		}
    }else{
	  uc_user_synlogin($uid);
	}
    break;
}
?>