function SignOut(fbID, teamName){
	userLogins.findOne( { $and: [ {FB_ID: fbID}, {SLACK_TEAM_NAME: teamName} ] }, function(err, doc){
		//stop if the user is not signed into the team
		if(doc === null){
			console.error(fbID + " is not signed into team " + teamName);
			sendTextMessage(fbID, "You are not signed into this team.");
			return;
		}
		//revoke the user's auth token
		request({
			uri: "https://slack.com/api/auth.revoke",
			qs: {
				token: doc.SLACK_TOKEN,
				exclude_members: "true"
			},
			method: "POST"
		}, (error, response, body) => {
			let JSONresponse = JSON.parse(body);
			if(!JSONresponse.ok){
				console.error("Error when logging user " + fbID + " out of team " + teamName + ".");
				console.error("Error: " + error);
				console.error("Response: " + response);
				console.error("Body: " + body);
				sendTextMessage(fbID, "Sorry, we encountered an error while processing this request.");
				return;
			}
			//remove the user's login document
			userLogins.remove( { $and: [ {FB_ID: fbID}, {SLACK_TEAM_NAME: teamName} ] }, {}, function (){} );
			//if that was the only team the user was logged into, delete the user's settings document
			userLogins.count({ FB_ID: fbID }, function (err, count) {
				if(count === 0){
					userSettings.remove( {FB_ID: fbID}, {}, function (){} );
				}
			});
			//remove the user's subscription from all channels of the team
			groups.update( {TEAM_NAME: teamName}, { $pull: {USERS: fbID} }, {}, function (){} );
			console.log("Successfully logged user " + fbID + " out of team " + teamName + ".");
			sendTextMessage(fbID, "You are now logged out of team " + teamName + ".");
		});
	});
}
//Postconditions: The user's auth token is revoked and the database document is removed
The user's auth token is revoked and the database document is removed
The user ' s auth token is revoked and the database document is removed
function SignOut(fbID, teamName){
	userLogins.findOne( { $and: [ {FB_ID: fbID}, {SLACK_TEAM_NAME: teamName} ] }, function(err, doc){
		if(doc === null){
			console.error(fbID + " is not signed into team " + teamName);
			sendTextMessage(fbID, "You are not signed into this team.");
			return;
		}
		request({
			uri: "https://slack.com/api/auth.revoke",
			qs: {
				token: doc.SLACK_TOKEN,
				exclude_members: "true"
			},
			method: "POST"
		}, (error, response, body) => {
			let JSONresponse = JSON.parse(body);
			if(!JSONresponse.ok){
				console.error("Error when logging user " + fbID + " out of team " + teamName + ".");
				console.error("Error: " + error);
				console.error("Response: " + response);
				console.error("Body: " + body);
				sendTextMessage(fbID, "Sorry, we encountered an error while processing this request.");
				return;
			}
			userLogins.remove( { $and: [ {FB_ID: fbID}, {SLACK_TEAM_NAME: teamName} ] }, {}, function (){} );
			userLogins.count({ FB_ID: fbID }, function (err, count) {
				if(count === 0){
					userSettings.remove( {FB_ID: fbID}, {}, function (){} );
				}
			});
			groups.update( {TEAM_NAME: teamName}, { $pull: {USERS: fbID} }, {}, function (){} );
			console.log("Successfully logged user " + fbID + " out of team " + teamName + ".");
			sendTextMessage(fbID, "You are now logged out of team " + teamName + ".");
		});
	});
}
function SignOut ( fbID , teamName ) { userLogins . findOne ( { $and : [ { FB_ID : fbID } , { SLACK_TEAM_NAME : teamName } ] } , function ( err , doc ) { if ( doc === null ) { console . error ( fbID + " is not signed into team " + teamName ) ; sendTextMessage ( fbID , "You are not signed into this team." ) ; return ; } request ( { uri : "https://slack.com/api/auth.revoke" , qs : { token : doc . SLACK_TOKEN , exclude_members : "true" } , method : "POST" } , ( error , response , body ) => { let JSONresponse = JSON . parse ( body ) ; if ( ! JSONresponse . ok ) { console . error ( "Error when logging user " + fbID + " out of team " + teamName + "." ) ; console . error ( "Error: " + error ) ; console . error ( "Response: " + response ) ; console . error ( "Body: " + body ) ; sendTextMessage ( fbID , "Sorry, we encountered an error while processing this request." ) ; return ; } userLogins . remove ( { $and : [ { FB_ID : fbID } , { SLACK_TEAM_NAME : teamName } ] } , { } , function ( ) { } ) ; userLogins . count ( { FB_ID : fbID } , function ( err , count ) { if ( count === 0 ) { userSettings . remove ( { FB_ID : fbID } , { } , function ( ) { } ) ; } } ) ; groups . update ( { TEAM_NAME : teamName } , { $pull : { USERS : fbID } } , { } , function ( ) { } ) ; console . log ( "Successfully logged user " + fbID + " out of team " + teamName + "." ) ; sendTextMessage ( fbID , "You are now logged out of team " + teamName + "." ) ; } ) ; } ) ; }
Postconditions: The user's auth token is revoked and the database document is removed
Postconditions : The user ' s auth token is revoked and the database document is removed
//stop if the user is not signed into the team //revoke the user's auth token //remove the user's login document //if that was the only team the user was logged into, delete the user's settings document //remove the user's subscription from all channels of the team