| 57 | | public static function generateConnectionToken($mac, $network, $user) { |
| | 57 | /** |
| | 58 | * Generate a new access token for the connection |
| | 59 | * |
| | 60 | * @param string $mac The mac address of the computer connecting |
| | 61 | * |
| | 62 | * @param string $network The network the person is connecting to |
| | 63 | * |
| | 64 | * @param string $node The node from which the connection originates |
| | 65 | * |
| | 66 | * TODO: eventually, the user should not be necessary for userless authentication. But much |
| | 67 | * of the code would need to be changed in order to support this kind of authentication. |
| | 68 | * @param string $user The user authenticating |
| | 69 | * |
| | 70 | * @param string $node_ip=null The ip address from which the connection originates |
| | 71 | * |
| | 72 | * @return tokenid | false |
| | 73 | * |
| | 74 | */ |
| | 75 | public static function generateConnectionToken($mac, $network, $node, $user, $node_ip = null) { |
| 170 | | /** |
| 171 | | * Generate a new access token for the specified user |
| 172 | | * |
| 173 | | * @param string $validated_user The user to generate a token for |
| 174 | | * |
| 175 | | * @param string $creator The user generating the token |
| 176 | | * |
| 177 | | * @param string $token_template_id The token template that the token should be associated with. |
| 178 | | * If templates aren't used then this the auth process will create |
| 179 | | * tokens automatically and we don't need to create tokens elsewhere. |
| 180 | | * |
| 181 | | * @param string $token_lot=null Optional. The token lot the token is part of. |
| 182 | | * |
| 183 | | * @return tokenid |
| 184 | | * |
| 185 | | */ |
| 186 | | public static function generateTokenForUser($validated_user, $creator, $token_template_id, $token_lot = null) { |
| 187 | | $db = AbstractDb::getObject(); |
| 188 | | $token = self::generateToken(); |
| 189 | | |
| 190 | | $db->execSqlUpdate("INSERT INTO tokens (token_owner, token_issuer, token_id, token_template_id, token_status) VALUES ('" . $validated_user->getId() . "', '" . $creator->getId() . "', '$token', '" . $token_template_id . "', '" . TOKEN_UNUSED . "');"); |
| 191 | | |
| 192 | | return $token; |
| 193 | | } |
| 194 | | |
| | 190 | } |
| | 191 | |
| | 192 | /** |
| | 193 | * Instantiate the current user |
| | 194 | * |
| | 195 | * @return mixed A User object, or null if there was an error |
| | 196 | |
| | 197 | */ |
| | 198 | public static function getCurrentToken() { |
| | 199 | require_once ('classes/Session.php'); |
| | 200 | $session = Session::getObject(); |
| | 201 | $sessTokenId = $session->get('SESS_TOKEN_ID'); |
| | 202 | |
| | 203 | /* if(!empty($sessCurrentUserId)){ |
| | 204 | try { |
| | 205 | $user = self :: getObject($sessCurrentUserId); |
| | 206 | //$user = new User($session->get(SESS_USER_ID_VAR)); |
| | 207 | } catch (Exception $e) { |
| | 208 | $session->set(SESS_TOKEN_ID, null); |
| | 209 | } |
| | 210 | }*/ |
| | 211 | return $sessTokenId; |
| | 212 | } |
| | 213 | |
| | 214 | /** |
| | 215 | * Associates the user passed in parameter with the session |
| | 216 | * |
| | 217 | * This should NOT be called by anything except the Authenticators |
| | 218 | * |
| | 219 | * @param object $user User a user object, or null |
| | 220 | * |
| | 221 | * @return bool True if everything went well setting the session |
| | 222 | |
| | 223 | */ |
| | 224 | public static function setCurrentToken($tokenId) { |
| | 225 | |
| | 226 | try { |
| | 227 | $session = Session::getObject(); |
| | 228 | $session->set('SESS_TOKEN_ID', $tokenId); |
| | 229 | return true; |
| | 230 | } catch (Exception $e) { |
| | 231 | return false; |
| | 232 | } |
| | 233 | } |
| | 234 | |
| | 235 | /** Set Smarty template values. Standardization routine. |
| | 236 | * // TODO: implement this*/ |
| | 237 | public static function assignSmartyValues($smarty) { |
| | 238 | |
| | 239 | $tokenId = Token :: getCurrentToken(); |
| | 240 | |
| | 241 | /** |
| | 242 | * Define user security levels for the template |
| | 243 | * |
| | 244 | * These values are used in the default template of WiFoDog but could be |
| | 245 | * used in a customized template to restrict certain links to specific |
| | 246 | * user access levels. Note however that they will all be deprecateb by the |
| | 247 | * new roles system. |
| | 248 | */ |
| | 249 | $smarty->assign('hasConnection', !empty($tokenId) ? true : false); |
| | 250 | $smarty->assign('tokenId', $tokenId); |
| | 251 | /*$smarty->assign('userIsValid', $user && !$user->isSplashOnlyUser() ? true : false); |
| | 252 | $smarty->assign('userDEPRECATEDisSuperAdmin', $user && $user->DEPRECATEDisSuperAdmin()); |
| | 253 | |
| | 254 | if (isset ($_REQUEST['debug_request']) && ($user && $user->DEPRECATEDisSuperAdmin())) { |
| | 255 | // Tell Smarty everything it needs to know |
| | 256 | $smarty->assign('debugRequested', true); |
| | 257 | $smarty->assign('debugOutput', print_r($_REQUEST, true)); |
| | 258 | }*/ |