'userlogin_check_credintials', 'userlogin.createUser' => 'userlogin_create_user', 'userlogin.logUserOut' => 'userlogin_logout_user', 'userlogin.isUserLoggedIn' => 'userlogin_check_user', 'userlogin.logAnonIn' => 'userlogin_anon_login'); } /** * * Checks to see if the username exists, if not, present user with option to register * Checks to see if the username and password match the druapl database, if so, log the user in * */ function userlogin_check_credintials($username, $userpass) { if (xmlrpc_error()) { $error_num = xmlrpc_errno(); $error = xmlrpc_error(); drupal_set_message(t('Something went wrong such as: %error'), array('%error' => $error->message . '(' . $error_num . ')')); } global $user; if(!user_load(array('name' => $username))) { return array('errorUserName', $username); } if($account=user_load(array('name' => $username, 'pass' => $userpass))) { if(user_external_login($account)) { $user = $account; return 'loggedIn'; } else { return 'errorLoginFailed'; } } else { return array('errorUserPass', $userpass); } } /** * * Logs an anonymous user in * */ function userlogin_anon_login() { if (xmlrpc_error()) { $error_num = xmlrpc_errno(); $error = xmlrpc_error(); drupal_set_message(t('Something went wrong such as: %error'), array('%error' => $error->message . '(' . $error_num . ')')); } global $user; // Load the anonymous user $user = drupal_anonymous_user(); return 'anonLoggedIn'; } /** * * Checks to see if the username exists, if not, present user with option to register * Checks to see if the username and password match the druapl database, if so, log the user in * */ function userlogin_check_user() { if (xmlrpc_error()) { $error_num = xmlrpc_errno(); $error = xmlrpc_error(); drupal_set_message(t('Something went wrong such as: %error'), array('%error' => $error->message . '(' . $error_num . ')')); } global $user; if($user->uid > 0) { return array('userLoggedInOrNot', $user->name); } else { return 'errorUserNotLoggedIn'; } } /** * * Logs current user out * NOTE: Same as user_logout() without drupal_goto() call * */ function userlogin_logout_user($username) { if (xmlrpc_error()) { $error_num = xmlrpc_errno(); $error = xmlrpc_error(); drupal_set_message(t('Something went wrong such as: %error'), array('%error' => $error->message . '(' . $error_num . ')')); } global $user; watchdog('user', 'Session closed for %name.', array('%name' => $user->name)); // Destroy the current session: session_destroy(); module_invoke_all('user', 'logout', NULL, $user); // Load the anonymous user $user = drupal_anonymous_user(); return 'loggedOut'; } /** * * Creates a user in the drupal database * */ function userlogin_create_user($username, $userpass, $useremail) { if (xmlrpc_error()) { $error_num = xmlrpc_errno(); $error = xmlrpc_error(); drupal_set_message(t('Something went wrong such as: %error'), array('%error' => $error->message . '(' . $error_num . ')')); } global $user; // if user name exists in database, return error if(user_load(array('name' => $username))) { return array('errorUserName', $username); } $account = array('name' => $username, 'pass' => $userpass, 'mail' => $useremail, 'status' => 1); $user = user_save(null, $account); return array('userCreated', $username); }