library/src/network/httpd/BP-HTTPdSessions.cc
// Creates a session by looking at the user database and selecting
// a user.
Creates a session by looking at the user database and selecting
a user.
Creates a session by looking at the user database and selecting a user .
P_BP_HTTPD_USER_SESSION BP_HTTPdSessionAuthUserFromCreds
(
		P_BP_HTTPD_SESSION httpd,
		char             * user,
		char             * pass
)
{
	if(!httpd)
		return NULL;
	if(!user)
		return NULL;
	if(!pass)
		return NULL;
	P_BP_HTTPD_USER user_lookup = BP_HTTPdUserLookup
	(
			httpd,
			user,
			pass,
			NULL,
			NULL,
			NULL
	);
	if(!user_lookup)
		return NULL;
	if(user_lookup->session)
	{
		printf("\n WE WERE ABLE TO LOOKUP THE SESSION OK HERE?!");
		BP_HTTPdSessionDestroy(httpd, (P_BP_HTTPD_USER_SESSION) user_lookup->session);
		user_lookup->session = NULL;
	}
	P_BP_HTTPD_USER_SESSION session = (P_BP_HTTPD_USER_SESSION) NULL;
	size_t default_xsrf_token_count = 10;
	session = BP_HTTPdSessionAdd
	(
			httpd,
			BP_HTTPD_USER_SESSION_TYPE_AUTHENTICATED_USER,
			user_lookup,
			BP_HOUR,
			default_xsrf_token_count
	);
	user_lookup->session = session;
	printf("\n Looked up user ok?: %p - %s", user_lookup, user_lookup->username);
	return session;
}
P_BP_HTTPD_USER_SESSION BP_HTTPdSessionAuthUserFromCreds ( P_BP_HTTPD_SESSION httpd , char * user , char * pass ) { if ( ! httpd ) return NULL ; if ( ! user ) return NULL ; if ( ! pass ) return NULL ; P_BP_HTTPD_USER user_lookup = BP_HTTPdUserLookup ( httpd , user , pass , NULL , NULL , NULL ) ; if ( ! user_lookup ) return NULL ; if ( user_lookup -> session ) { printf ( " \n " ) ; BP_HTTPdSessionDestroy ( httpd , ( P_BP_HTTPD_USER_SESSION ) user_lookup -> session ) ; user_lookup -> session = NULL ; } P_BP_HTTPD_USER_SESSION session = ( P_BP_HTTPD_USER_SESSION ) NULL ; size_t default_xsrf_token_count = 10 ; session = BP_HTTPdSessionAdd ( httpd , BP_HTTPD_USER_SESSION_TYPE_AUTHENTICATED_USER , user_lookup , BP_HOUR , default_xsrf_token_count ) ; user_lookup -> session = session ; printf ( " \n " , user_lookup , user_lookup -> username ) ; return session ; }
Creates a session by looking at the user database and selecting
a user.
Creates a session by looking at the user database and selecting a user .
// ensure we have a daemon // ensure we have a user // ensure we have a password // Attempts to lookup a user within the table. // ensure we can lookup the user // check if we already have a session // note: always destroy session on successful login, this permits multiple user logins //       to exist without too much conflict. /*
		// check if the session is expired
		if(!BP_HTTPdSessionExpired((P_BP_HTTPD_USER_SESSION)user_lookup->session))
		{

			// if the session isn't expired, return it
			return (P_BP_HTTPD_USER_SESSION) user_lookup->session;

		}
		*/ // destroy the user session // set session ptr to null // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%% Add New Session %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // session // 10 tokens seems large enough for any and all tasks // add new session with 10 random xsrf tokens // set session // return the session