Modified the authentication api to store project registration id and registration number in the session.

Updated the project api's to use project id/number stored in the session
This commit is contained in:
jacob 2011-02-23 21:12:12 +00:00
parent 0320f662dd
commit 19676aa403
3 changed files with 46 additions and 28 deletions

63
api.php
View File

@ -370,7 +370,19 @@ switch($request[0]) {
$_SESSION['roles']=array();
if(!$cid) $cid=$_SESSION['conferences_id'];
$status=user_conference_load($accounts_id,$cid);
$u = user_load(null, $accounts_id);
if(is_array($u)){
$p = getProject($u['id']);
if(is_array($p)) {
$_SESSION['registrations_id'] = $p['registrations_id'];
$_SESSION['registration_number'] = $p['num'];
}else
$_SESSION['error'] = "project not found";
}
else
$_SESSION['error'] = "user not found";
$ret['conferences_id']=$cid;
$ret['status']="ok";
@ -391,6 +403,8 @@ switch($request[0]) {
unset($_SESSION['roles']);
unset($_SESSION['users_id']);
unset($_SESSION['name']);
unset($_SESSION['registrations_id']);
unset($_SESSION['registration_number']);
$ret['status']="ok";
}
else {
@ -860,8 +874,11 @@ switch($request[0]) {
$ret['error']=$chk['error'];
break;
}
// students status must be complete in order to add projects
/*
Originally, the student status was supposed to be complete before they could manage projects. Should
this still be true? If so, this code needs to be unremarked, and the subsets within /project checked
to see if it applies to all of them. If not, the remove this currently remarked block.
*/
/*
$sStatus = studentStatus();
if($sStatus != 'complete'){
@ -885,15 +902,15 @@ switch($request[0]) {
}
// we start by creating a registration
$regId = addRegistration($_SESSION['users_id']);
if(!is_numeric($regId)){
$regdat = addRegistration($_SESSION['users_id']);
if(!is_array($regdat)){
$ret['status'] = 'error';
$ret['error'] = $regId;
$ret['error'] = $regdat;
break;
}
// now we add a project to that registration
$project = addProject($regId);
$project = addProject($regdat['registrations_id']);
if(!is_array($project)){
$ret['status'] = 'error';
$ret['error'] = $project;
@ -901,6 +918,8 @@ switch($request[0]) {
}
// if we got this far, then all's good and we can return the project data
$_SESSION['registrations_id'] = $regdat['registrations_id'];
$_SESSION['registration_number'] = $regdat['registration_number'];
$ret['status'] = 'ok';
$ret['project'] = getProject($_SESSION['users_id']);
break;
@ -962,6 +981,8 @@ switch($request[0]) {
}
$result = joinProject($_POST['registration_number'], $_POST['email']);
if($result == "ok"){
$_SESSION['registrations_id'] = getRegistrationsId($_SESSION['users_id']);
$_SESSION['registration_number'] = $_POST['registration_number'];
$ret['status'] = "ok";
}else{
$ret['status'] = "error";
@ -970,40 +991,40 @@ switch($request[0]) {
break;
/* APIDOC: project/remove
post(registrations_id integer)
description(remove the current user from an existing project. If no other users are in the project, then it is deleted.)
*/
case 'remove':
if(!array_key_exists('registrations_id', $_POST)){
if(!array_key_exists('registrations_id', $_SESSION)){
$ret['status'] = 'error';
$ret['error'] = 'registrations_id (integer) is required';
$ret['error'] = 'current user not associated with a project';
break;
}
$result = removeProject($_POST['registrations_id']);
$result = removeProject($_SESSION['registrations_id']);
if($result != 'ok'){
$ret['status'] = "error";
$ret['error'] = $result;
break;
}
unset($_SESSION['registrations_id']);
unset($_SESSION['registration_number']);
$ret['status'] = 'ok';
break;
case 'mentor':
switch($request[2]){
/* APIDOC: project/mentor/add
post(registrations_id integer)
description(add a project mentor)
description(add a project mentor to the current project)
return(mentor array)
*/
case 'add':
if(!array_key_exists('registrations_id', $_POST)){
if(!array_key_exists('registrations_id', $_SESSION)){
$ret['status'] = "error";
$ret['error'] = 'registrations_id parameter required';
$ret['error'] = 'current user not associated with a project';
break;
}
$result = addMentor($_POST['registrations_id']);
$result = addMentor($_SESSION['registrations_id']);
if(is_array($result)){
$ret['status'] = 'ok';
$ret['mentor'] = $result;
@ -1052,16 +1073,16 @@ switch($request[0]) {
break;
/* APIDOC: project/mentor/view
post(registrations_id integer)
description(list project mentors)
return(mentors array)
*/
case 'view':
if(!array_key_exists('registrations_id', $_POST)){
if(!array_key_exists('registrations_id', $_SESSION)){
$ret['status'] = "error";
$ret['error'] = 'registrations_id parameter required';
$ret['error'] = 'current user not associated with a project';
break;
}
$result = getMentors($_POST['registrations_id']);
$result = getMentors($_SESSION['registrations_id']);
if(is_array($result)){
$ret['status'] = 'ok';
$ret['mentors'] = $result;

View File

@ -607,7 +607,7 @@ function getNewRegNum(){
return $regnum;
}
// add a registration record and return it's unique id
// add a registration record and return it's unique id and registration number in an array
// returns an error message if the user is alredy registered
function addRegistration($userId){
global $conference;
@ -657,7 +657,7 @@ function addRegistration($userId){
// ok, if the flow hits this point, then we've successfully added the registration and
// linked the user to it. Return the registration number
return $regid;
return array('registrations_id' => $regid, 'registration_number' => $regnum);
}
// get the registration id for a specific user.
@ -674,7 +674,7 @@ function getRegistrationsId($user){
// grab their registrations id
$result = mysql_fetch_assoc(mysql_query("SELECT registrations_id FROM users WHERE id = $uid"));
if(mysql_error()){
return "register_participants.inc.php::getRegistrationsId -> " . $mysql_error();
return "register_participants.inc.php::getRegistrationsId -> " . mysql_error();
}
return $result['registrations_id'];

View File

@ -3,7 +3,7 @@ include "common.inc.php";
?>
<html>
<head>
<script type="text/javascript" src="js/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$.get('api/role/list', {}, function(results){
@ -125,7 +125,6 @@ email address: <input type="text" name="email"></input><br/>
<h3>Leave a project</h3>
<form method ="post" action = "api/project/remove">
<label>registration id:<input type="text" name="registrations_id"></input></label><br/>
<input type="submit" value="Leave"></input>
</form>
@ -133,7 +132,6 @@ email address: <input type="text" name="email"></input><br/>
<div class="subset">
<h4>Add a mentor</h4>
<form method="post" action="api/project/mentor/add">
<label>registration id:<input type="text" name="registrations_id"></input></label><br/>
<input type="submit" value="Submit"></input>
</form>
<h4>Remove a mentor</h4>
@ -143,7 +141,6 @@ email address: <input type="text" name="email"></input><br/>
</form>
<h4>View mentors</h4>
<form method="post" action="api/project/mentor/view">
<label>registration id:<input type="text" name="registrations_id" id="viewform_registrations_id"></input></label><br/>
<input type="submit" value="Submit"></input>
</form>
</div>