Add account/view api

This commit is contained in:
james 2010-10-01 21:04:05 +00:00
parent a92544bbea
commit f0b362eff7
2 changed files with 59 additions and 39 deletions

View File

@ -91,7 +91,18 @@ function account_set_password($accounts_id, $password = NULL)
function account_load($id) function account_load($id)
{ {
$id = intval($id); $id = intval($id);
$q = mysql_query("SELECT * FROM accounts WHERE id='$id'"); //we dont want password or the pending email code in here
$q = mysql_query("SELECT id,
username,
link_username_to_email,
passwordset,
email,
pendingemail,
superuser,
deleted,
deleted_datetime,
created
FROM accounts WHERE id='$id'");
if(mysql_num_rows($q) == 0) { if(mysql_num_rows($q) == 0) {
return false; return false;
} }

85
api.php
View File

@ -209,41 +209,58 @@ switch($request[0]) {
break; break;
case "account": case "account":
/* APIDOC: account/create switch($request[1]) {
description(creates an account) /* APIDOC: account/create
post(username varchar(64), password varchar(64), email varchar(64) optional) description(creates an account)
return(account array) post(username varchar(64), password varchar(64), email varchar(64) optional)
*/ return(account array)
if($request[1]=="create") { */
$user = trim($_POST['username']); case 'create':
$pass = trim($_POST['password']); $user = trim($_POST['username']);
$email = trim($_POST['email']); $pass = trim($_POST['password']);
if($user && $pass) { $email = trim($_POST['email']);
$a=account_create($user,$pass); if($user && $pass) {
if(is_array($a)) { $a=account_create($user,$pass);
if($email) if(is_array($a)) {
account_set_email($a['id'],$email); if($email)
$account=account_load($a['id']); account_set_email($a['id'],$email);
$ret['status']="ok"; $account=account_load($a['id']);
$ret['account']=$account; $ret['status']="ok";
$ret['account']=$account;
}
else {
$ret['status']="error";
switch($a) {
case -1: $ret['error']="invalid username"; break;
case -2: $ret['error']="username already exists"; break;
case -3: $ret['error']="invalid password"; break;
default: $ret['error']="unknown account creation error"; break;
}
}
} else {
$ret['status']="error";
$ret['error']="username (varchar 64) and password (varchar 64) are required ";
}
break;
/* APIDOC: account/view
description(view account information for currently logged in account)
return(account array)
*/
case 'view':
if(isset($_SESSION['accounts_id'])) {
$a = account_load($_SESSION['accounts_id']);
$ret['status']='ok';
$ret['account']=$a;
} }
else { else {
$ret['status']="error"; $ret['status']="error";
switch($a) { $ret['error']="You are not logged in";
case -1: $ret['error']="invalid username"; break;
case -2: $ret['error']="username already exists"; break;
case -3: $ret['error']="invalid password"; break;
default: $ret['error']="unknown account creation error"; break;
}
} }
} else { break;
default:
$ret['status']="error"; $ret['status']="error";
$ret['error']="username (varchar 64) and password (varchar 64) are required "; $ret['error']="invalid account command";
}
}
else {
$ret['status']="error";
$ret['error']="invalid account command";
} }
break; break;
@ -429,7 +446,6 @@ switch($request[0]) {
break; break;
} }
require_once("so_teams.inc.php");
switch($request[1]) { switch($request[1]) {
/* APIDOC: user/view /* APIDOC: user/view
description(view user information for current conference) description(view user information for current conference)
@ -499,13 +515,6 @@ echo json_encode($ret);
return(schools array) return(schools array)
*/ */
/* APIDOC: account/edit
notimplemented
description(edit account information)
post(account array)
return(account array)
*/
/* APIDOC: user/connect_teacher_to_school /* APIDOC: user/connect_teacher_to_school