function write_user($newUser) { //create salt here, because we want it to be the same on the web/server $hashpass = crypt($newUser["pass"], WebUsers::generateSALT()); $params = array('Login' => $newUser["name"], 'Password' => $hashpass, 'Email' => $newUser["mail"]); try { //make new webuser $user_id = WebUsers::createWebuser($params['Login'], $params['Password'], $params['Email']); //Create the user on the shard + in case shard is offline put copy of query in query db //returns: ok, shardoffline or liboffline $result = WebUsers::createUser($params, $user_id); Users::createPermissions(array($newUser["name"])); } catch (PDOException $e) { //go to error page or something, because can't access website db print_r($e); throw new SystemExit(); } return $result; }
/** * update the password. * update the password in the shard + update the password in the www/CMS version. * @param $user the username * @param $pass the new password. * @return ok if it worked, if the lib or shard is offline it will return liboffline or shardoffline. */ public static function setPassword($user, $pass) { $hashpass = crypt($pass, WebUsers::generateSALT()); $reply = WebUsers::setAmsPassword($user, $hashpass); $drupal_pass = user_hash_password($pass); $values = array('user' => $user, 'pass' => $drupal_pass); try { //make connection with and put into shard db db_query("UPDATE {users} SET pass = :pass WHERE name = :user", $values); } catch (PDOException $e) { //ERROR: the web DB is offline } return $reply; }
/** * update the password. * update the password in the shard + update the password in the www/CMS version. * @param $user the username * @param $pass the new password. * @return ok if it worked, if the lib or shard is offline it will return liboffline or shardoffline. */ public static function setPassword($user, $pass) { $hashpass = crypt($pass, WebUsers::generateSALT()); $reply = WebUsers::setAmsPassword($user, $hashpass); $values = array('Password' => $hashpass); try { //make connection with and put into shard db $dbw = new DBLayer("web"); $dbw->update("ams_user", $values, "Login = '******'"); } catch (PDOException $e) { //ERROR: the web DB is offline } return $reply; }